chore: Refactor playbook for idempotency

This commit is contained in:
Danny Bessems 2023-08-23 14:03:25 +02:00
parent 0310bb9d1a
commit 436995accc
4 changed files with 55 additions and 24 deletions

View File

@ -110,8 +110,8 @@
- organization: mc - organization: mc
body: body:
name: GitOps.ClusterAPI name: GitOps.ClusterAPI
# auto_init: true auto_init: true
# default_branch: main default_branch: main
description: ClusterAPI manifests description: ClusterAPI manifests
- organization: mc - organization: mc
body: body:
@ -125,12 +125,6 @@
# auto_init: true # auto_init: true
# default_branch: main # default_branch: main
description: GitOps manifests description: GitOps manifests
- organization: wl
body:
name: GitOps.HelmCharts
# auto_init: true
# default_branch: main
description: Helm charts
loop_control: loop_control:
label: "{{ item.organization ~ '/' ~ item.body.name }}" label: "{{ item.organization ~ '/' ~ item.body.name }}"

View File

@ -63,6 +63,14 @@
ansible.builtin.command: ansible.builtin.command:
cmd: update-ca-certificates cmd: update-ca-certificates
- name: Extract container images (for idempotency purposes)
ansible.builtin.unarchive:
src: /opt/metacluster/container-images/image-tarballs.tgz
dest: /opt/metacluster/container-images
remote_src: no
when:
- lookup('ansible.builtin.fileglob', 'opt/metacluster/container-images/*.tgz') is match('.*image-tarballs.tgz')
- name: Get all stored fully qualified container image names - name: Get all stored fully qualified container image names
ansible.builtin.shell: ansible.builtin.shell:
cmd: >- cmd: >-

View File

@ -129,6 +129,12 @@
state: directory state: directory
register: capi_clustermanifest register: capi_clustermanifest
- name: Pull existing repository
ansible.builtin.git:
repo: https://git.{{ vapp['metacluster.fqdn'] }}/mc/GitOps.ClusterAPI.git
dest: "{{ capi_clustermanifest.path }}"
version: main
- name: Save workload cluster manifest - name: Save workload cluster manifest
ansible.builtin.copy: ansible.builtin.copy:
dest: "{{ capi_clustermanifest.path }}/new-cluster.yaml" dest: "{{ capi_clustermanifest.path }}/new-cluster.yaml"
@ -173,24 +179,46 @@
prefix: "{{ vapp['guestinfo.prefixlength'] }}" prefix: "{{ vapp['guestinfo.prefixlength'] }}"
gateway: "{{ vapp['guestinfo.gateway'] }}" gateway: "{{ vapp['guestinfo.gateway'] }}"
- name: Initialize/Push git repository - name: Remove working files
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 ./manifests
git commit -m "Upload manifests"
git remote add origin https://git.{{ vapp['metacluster.fqdn'] }}/mc/GitOps.ClusterAPI.git
git push https://administrator:{{ vapp['metacluster.password'] | urlencode }}@git.{{ vapp['metacluster.fqdn'] }}/mc/GitOps.ClusterAPI.git --all
chdir: "{{ capi_clustermanifest.path }}"
- name: Cleanup tempfolder
ansible.builtin.file: ansible.builtin.file:
path: "{{ capi_clustermanifest.path }}" path: "{{ item }}"
state: absent state: absent
when: capi_clustermanifest.path is defined loop: "{{ query('ansible.builtin.fileglob', capi_clustermanifest.path ~ '/*.yaml') }}"
loop_control:
label: "{{ item | basename }}"
- name: Push git repository
lvrfrc87.git_acp.git_acp:
path: "{{ capi_clustermanifest.path }}"
branch: main
comment: "Upload manifests"
add:
- ./manifests
url: https://administrator:{{ vapp['metacluster.password'] | urlencode }}@git.{{ vapp['metacluster.fqdn'] }}/mc/GitOps.ClusterAPI.git
environment:
GIT_AUTHOR_NAME: administrator
GIT_AUTHOR_NAME: administrator@{{ vapp['metacluster.fqdn'] }}
GIT_COMMITTER_NAME: administrator
GIT_COMMITTER_NAME: 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 ./manifests
# git commit -m "Upload manifests"
# git remote add origin https://git.{{ vapp['metacluster.fqdn'] }}/mc/GitOps.ClusterAPI.git
# git push https://administrator:{{ vapp['metacluster.password'] | urlencode }}@git.{{ vapp['metacluster.fqdn'] }}/mc/GitOps.ClusterAPI.git --all
# chdir: "{{ capi_clustermanifest.path }}"
# - name: Cleanup tempfolder
# ansible.builtin.file:
# path: "{{ capi_clustermanifest.path }}"
# state: absent
# when: capi_clustermanifest.path is defined
- name: Configure Cluster API repository - name: Configure Cluster API repository
ansible.builtin.template: ansible.builtin.template:

View File

@ -274,6 +274,7 @@ dependencies:
- community.general - community.general
- community.vmware - community.vmware
- kubernetes.core - kubernetes.core
- lvrfrc87.git_acp
container_images: container_images:
# This should match the image tag referenced at `platform.packaged_components[.name==traefik].config` # This should match the image tag referenced at `platform.packaged_components[.name==traefik].config`