From eb2ada2164b3f4276bff95f0e7867e677f93bdb6 Mon Sep 17 00:00:00 2001 From: Danny Bessems Date: Wed, 23 Aug 2023 14:31:09 +0200 Subject: [PATCH] chore: Refactor git commands to git_acp module --- .../bootstrap/roles/metacluster/tasks/git.yml | 4 +- .../roles/workloadcluster/tasks/gitops.yml | 44 ++++++++++++++----- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/git.yml b/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/git.yml index fb8d031..fd59f48 100644 --- a/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/git.yml +++ b/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/git.yml @@ -122,8 +122,8 @@ - organization: wl body: name: GitOps.Config - # auto_init: true - # default_branch: main + auto_init: true + default_branch: main description: GitOps manifests loop_control: label: "{{ item.organization ~ '/' ~ item.body.name }}" diff --git a/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/workloadcluster/tasks/gitops.yml b/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/workloadcluster/tasks/gitops.yml index 56eca1b..d66e17b 100644 --- a/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/workloadcluster/tasks/gitops.yml +++ b/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/workloadcluster/tasks/gitops.yml @@ -5,6 +5,12 @@ recurse: false register: helm_charts +- name: Pull existing repository + ansible.builtin.git: + repo: https://git.{{ vapp['metacluster.fqdn'] }}/wl/GitOps.Config.git + dest: /opt/workloadcluster/git-repositories/gitops + version: main + - name: Create hard-links to populate new git-repository ansible.builtin.shell: cmd: >- @@ -41,18 +47,32 @@ loop_control: label: "{{ item.key }}" -- name: Initialize/Push git repository - ansible.builtin.shell: - cmd: | - git init - git config --global user.email "administrator@{{ vapp['metacluster.fqdn'] }}" - git config --global user.name "administrator" - git checkout -b main - git add . - git commit -m "Upload charts" - git remote add origin https://git.{{ vapp['metacluster.fqdn'] }}/wl/GitOps.Config.git - git push https://administrator:{{ vapp['metacluster.password'] | urlencode }}@git.{{ vapp['metacluster.fqdn'] }}/wl/GitOps.Config.git --all - chdir: /opt/workloadcluster/git-repositories/gitops +- name: Push git repository + lvrfrc87.git_acp.git_acp: + path: /opt/workloadcluster/git-repositories/gitops + branch: main + comment: "Upload charts" + add: + - . + url: https://administrator:{{ vapp['metacluster.password'] | urlencode }}@git.{{ vapp['metacluster.fqdn'] }}/wl/GitOps.Config.git + environment: + GIT_AUTHOR_NAME: administrator + GIT_AUTHOR_EMAIL: administrator@{{ vapp['metacluster.fqdn'] }} + GIT_COMMITTER_NAME: administrator + GIT_COMMITTER_EMAIL: administrator@{{ vapp['metacluster.fqdn'] }} + +# - name: Initialize/Push git repository +# ansible.builtin.shell: +# cmd: | +# git init +# git config --global user.email "administrator@{{ vapp['metacluster.fqdn'] }}" +# git config --global user.name "administrator" +# git checkout -b main +# git add . +# git commit -m "Upload charts" +# git remote add origin https://git.{{ vapp['metacluster.fqdn'] }}/wl/GitOps.Config.git +# git push https://administrator:{{ vapp['metacluster.password'] | urlencode }}@git.{{ vapp['metacluster.fqdn'] }}/wl/GitOps.Config.git --all +# chdir: /opt/workloadcluster/git-repositories/gitops - name: Retrieve workload-cluster kubeconfig kubernetes.core.k8s_info: