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 2b2dfe6..85decc5 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 @@ -119,18 +119,18 @@ # auto_init: true # default_branch: main description: GitOps manifests - - organization: mc - body: - name: GitOps.HelmCharts - # auto_init: true - # default_branch: main - description: Helm charts - organization: wl body: name: GitOps.Config # auto_init: true # default_branch: main description: GitOps manifests + - organization: wl + body: + name: GitOps.HelmCharts + # auto_init: true + # default_branch: main + description: Helm charts loop_control: label: "{{ item.organization ~ '/' ~ item.body.name }}" diff --git a/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/gitops.yml b/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/gitops.yml index 61944ef..915950d 100644 --- a/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/gitops.yml +++ b/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/metacluster/tasks/gitops.yml @@ -39,7 +39,7 @@ mode: 0600 vars: _template: - name: argocd-gitrepo-metacluster + name: argocd-gitrepo-mc-gitopsconfig namespace: argo-cd url: https://git.{{ vapp['metacluster.fqdn'] }}/mc/GitOps.Config.git notify: diff --git a/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/workloadcluster/tasks/clusterapi.yml b/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/workloadcluster/tasks/clusterapi.yml index 1196177..68f92cb 100644 --- a/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/workloadcluster/tasks/clusterapi.yml +++ b/ansible/roles/firstboot/files/ansible_payload/bootstrap/roles/workloadcluster/tasks/clusterapi.yml @@ -167,6 +167,21 @@ git push https://administrator:{{ vapp['metacluster.password'] | urlencode }}@git.{{ vapp['metacluster.fqdn'] }}/mc/GitOps.ClusterAPI.git --all chdir: "{{ capi_clustermanifest.path }}" +- name: Configure Cluster API repository + ansible.builtin.template: + src: gitrepo.j2 + dest: /var/lib/rancher/k3s/server/manifests/{{ _template.name }}-manifest.yaml + owner: root + group: root + mode: 0600 + vars: + _template: + name: argocd-gitrepo-mc-gitopsclusterapi + namespace: argo-cd + url: https://git.{{ vapp['metacluster.fqdn'] }}/mc/GitOps.ClusterAPI.git + notify: + - Apply manifests + # Temporarily disabled until manifests are properly managed by gitops # - name: Cleanup tempfolder # ansible.builtin.file: @@ -174,6 +189,7 @@ # state: absent # when: capi_clustermanifest.path is defined +# TODO: Move to gitops - name: Create in-cluster IpPool kubernetes.core.k8s: template: ippool.j2 @@ -201,13 +217,37 @@ retries: "{{ playbook.retries }}" delay: "{{ (storage_benchmark | int) * (playbook.delay.medium | int) }}" -- name: Apply workload cluster manifest - kubernetes.core.k8s: - definition: >- - {{ clusterctl_newcluster.stdout }} - wait: true - kubeconfig: "{{ kubeconfig.path }}" -# TODO: move to git repo +- name: Create application + ansible.builtin.template: + src: application.j2 + dest: /var/lib/rancher/k3s/server/manifests/{{ _template.application.name }}-manifest.yaml + owner: root + group: root + mode: 0600 + vars: + _template: + application: + name: argocd-application-clusterapi + namespace: argo-cd + cluster: + name: https://kubernetes.default.svc + namespace: default + repository: + url: https://git.{{ vapp['metacluster.fqdn'] }}/mc/GitOps.ClusterAPI.git + path: manifests + revision: main + notify: + - Apply manifests + +- name: Trigger handlers + ansible.builtin.meta: flush_handlers + +# - name: Apply workload cluster manifest +# kubernetes.core.k8s: +# definition: >- +# {{ clusterctl_newcluster.stdout }} +# wait: true +# kubeconfig: "{{ kubeconfig.path }}" - name: Wait for cluster to be available ansible.builtin.shell: 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 5adcd07..9cf5f65 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 @@ -62,7 +62,7 @@ mode: 0600 vars: _template: - name: argocd-gitrepo-workloadcluster + name: argocd-gitrepo-wl-gitopsconfig namespace: argo-cd url: https://git.{{ vapp['metacluster.fqdn'] }}/wl/GitOps.Config.git notify: diff --git a/ansible/roles/firstboot/files/ansible_payload/bootstrap/templates/application.j2 b/ansible/roles/firstboot/files/ansible_payload/bootstrap/templates/application.j2 new file mode 100644 index 0000000..828b56a --- /dev/null +++ b/ansible/roles/firstboot/files/ansible_payload/bootstrap/templates/application.j2 @@ -0,0 +1,16 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + name: {{ _template.application.name }} + namespace: {{ _template.application.namespace }} +spec: + destination: + namespace: {{ _template.cluster.namespace }} + server: {{ _template.cluster.name }} + project: default + source: + repoURL: {{ _template.repository.url }} + path: {{ _template.repository.path }} + targetRevision: {{ _template.repository.revision }} + syncPolicy: + automated: {}