argocd: simplify manifests apply

ArgoCD upstream manifests do not include namespace for the objects, so
there is no need to override it, and simply using kubectl flags allow to
set it.

Use the upstream file directly , considerably simplifying the argocd
install.

ansible-lint: the refactor apparently newly exposes the password hash
filter to ansible and this needs passlib, so add it to the pre-commit
dependencies.
This commit is contained in:
Max Gautier
2026-09-25 19:45:58 +02:00
parent 7462b8b93b
commit 88b827e58d
9 changed files with 27 additions and 104 deletions
+1
View File
@@ -43,6 +43,7 @@ repos:
- jmespath==1.0.1 - jmespath==1.0.1
- netaddr==1.3.0 - netaddr==1.3.0
- distlib - distlib
- passlib==1.7.4
- repo: https://github.com/golangci/misspell - repo: https://github.com/golangci/misspell
rev: v0.7.0 rev: v0.7.0
+1 -1
View File
@@ -128,7 +128,7 @@ Note:
- Application - Application
- [cert-manager](https://github.com/jetstack/cert-manager) 1.15.3 - [cert-manager](https://github.com/jetstack/cert-manager) 1.15.3
- [coredns](https://github.com/coredns/coredns) 1.14.6 - [coredns](https://github.com/coredns/coredns) 1.14.6
- [argocd](https://argoproj.github.io/) 2.14.5 - [argocd](https://argoproj.github.io/) 2.14.21
- [helm](https://helm.sh/) 3.22.0 - [helm](https://helm.sh/) 3.22.0
- [metallb](https://metallb.universe.tf/) 0.13.9 - [metallb](https://metallb.universe.tf/) 0.13.9
- [registry](https://github.com/distribution/distribution) 2.8.1 - [registry](https://github.com/distribution/distribution) 2.8.1
@@ -1,5 +0,0 @@
---
argocd_enabled: false
argocd_version: 2.14.5
argocd_namespace: argocd
# argocd_admin_password:
+22 -88
View File
@@ -1,95 +1,29 @@
--- ---
- name: Kubernetes Apps | Download yq
include_tasks: "../../../download/tasks/download_file.yml"
vars:
download: "{{ download_defaults | combine(downloads.yq) }}"
- name: Kubernetes Apps | Copy yq binary from download dir
copy:
src: "{{ downloads.yq.dest }}"
dest: "{{ bin_dir }}/yq"
mode: "0755"
remote_src: true
- name: Kubernetes Apps | Set ArgoCD template list
set_fact:
argocd_templates:
- name: namespace
file: argocd-namespace.yml
- name: install
file: "{{ downloads.argocd_install.dest | basename }}"
namespace: "{{ argocd_namespace }}"
download: "{{ downloads.argocd_install }}"
when:
- "inventory_hostname == groups['kube_control_plane'][0]"
- name: Kubernetes Apps | Download ArgoCD remote manifests
include_tasks: "../../../download/tasks/download_file.yml"
vars:
download: "{{ download_defaults | combine(item.download) }}"
with_items: "{{ argocd_templates | selectattr('download', 'defined') | list }}"
loop_control:
label: "{{ item.file }}"
when:
- "inventory_hostname == groups['kube_control_plane'][0]"
- name: Kubernetes Apps | Copy ArgoCD remote manifests from download dir
ansible.posix.synchronize:
src: "{{ local_release_dir }}/{{ item.file }}"
dest: "{{ kube_config_dir }}/{{ item.file }}"
compress: false
perms: true
owner: false
group: false
delegate_to: "{{ inventory_hostname }}"
with_items: "{{ argocd_templates | selectattr('download', 'defined') | list }}"
when:
- "inventory_hostname == groups['kube_control_plane'][0]"
- name: Kubernetes Apps | Set ArgoCD namespace for remote manifests
become: true
command: |
{{ bin_dir }}/yq eval-all -i '.metadata.namespace="{{ argocd_namespace }}"' {{ kube_config_dir }}/{{ item.file }}
with_items: "{{ argocd_templates | selectattr('download', 'defined') | list }}"
loop_control:
label: "{{ item.file }}"
when:
- "inventory_hostname == groups['kube_control_plane'][0]"
- name: Kubernetes Apps | Create ArgoCD manifests from templates
become: true
template:
src: "{{ item.file }}.j2"
dest: "{{ kube_config_dir }}/{{ item.file }}"
mode: "0644"
with_items: "{{ argocd_templates | selectattr('download', 'undefined') | list }}"
loop_control:
label: "{{ item.file }}"
when:
- "inventory_hostname == groups['kube_control_plane'][0]"
- name: Kubernetes Apps | Install ArgoCD - name: Kubernetes Apps | Install ArgoCD
become: true vars:
kube: ns_object:
name: ArgoCD apiVersion: v1
kubectl: "{{ bin_dir }}/kubectl" kind: Namespace
filename: "{{ kube_config_dir }}/{{ item.file }}" metadata:
state: latest name: "{{ argocd_namespace }}"
with_items: "{{ argocd_templates }}" labels:
when: app: argocd
- "inventory_hostname == groups['kube_control_plane'][0]" command:
cmd: >
{{ kubectl }} apply -n {{ argocd_namespace }}
--server-side=true --force-conflicts --field-manager=kubespray
-f - -f {{ downloads.argocd_install.dest }}
stdin: "{{ ns_object | to_json }}"
# https://github.com/argoproj/argo-cd/blob/master/docs/faq.md#i-forgot-the-admin-password-how-do-i-reset-it # https://github.com/argoproj/argo-cd/blob/master/docs/faq.md#i-forgot-the-admin-password-how-do-i-reset-it
- name: Kubernetes Apps | Set ArgoCD custom admin password - name: Kubernetes Apps | Set ArgoCD custom admin password
become: true vars:
shell: | password_patch:
{{ bin_dir }}/kubectl --kubeconfig /etc/kubernetes/admin.conf -n {{ argocd_namespace }} patch secret argocd-secret -p \ stringData:
'{ 'admin.password': "{{ argocd_admin_password | password_hash('bcrypt') }}"
"stringData": { 'admin.passwordMtime': "{{ now(utc=true, fmt='%Y-%m-%dT%H:%M:%SZ') }}"
"admin.password": "{{ argocd_admin_password | password_hash('bcrypt') }}", command:
"admin.passwordMtime": "'$(date +%FT%T%Z)'" cmd: "{{ kubectl }} -n {{ argocd_namespace }} patch secret argocd-secret --patch-file=/dev/stdin"
} stdin: "{{ password_patch | to_json }}"
}'
when: when:
- argocd_admin_password is defined - argocd_admin_password is defined
- "inventory_hostname == groups['kube_control_plane'][0]"
@@ -1,7 +0,0 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: {{ argocd_namespace }}
labels:
app: argocd
+1
View File
@@ -114,6 +114,7 @@ dependencies:
- metallb - metallb
- role: kubernetes-apps/argocd - role: kubernetes-apps/argocd
become: true
when: when:
- argocd_enabled - argocd_enabled
- inventory_hostname == groups['kube_control_plane'][0] - inventory_hostname == groups['kube_control_plane'][0]
@@ -925,8 +925,7 @@ downloads:
argocd_install: argocd_install:
enabled: "{{ argocd_enabled }}" enabled: "{{ argocd_enabled }}"
file: true file: true
version: "{{ argocd_version }}" dest: "{{ local_release_dir }}/argocd-install-{{ argocd_version }}.yml"
dest: "{{ local_release_dir }}/argocd-install.yml"
checksum: "{{ argocd_install_checksum }}" checksum: "{{ argocd_install_checksum }}"
url: "{{ argocd_install_url }}" url: "{{ argocd_install_url }}"
unarchive: false unarchive: false
@@ -475,6 +475,7 @@ expand_persistent_volumes: false
metallb_enabled: false metallb_enabled: false
metallb_speaker_enabled: "{{ metallb_enabled }}" metallb_speaker_enabled: "{{ metallb_enabled }}"
argocd_enabled: false argocd_enabled: false
argocd_namespace: argocd
gateway_api_enabled: false gateway_api_enabled: false
prometheus_operator_crds_enabled: false prometheus_operator_crds_enabled: false
-1
View File
@@ -14,7 +14,6 @@
loop: loop:
- ../roles/container-engine/docker/defaults/main.yml - ../roles/container-engine/docker/defaults/main.yml
- ../roles/kubernetes/node/defaults/main.yml - ../roles/kubernetes/node/defaults/main.yml
- ../roles/kubernetes-apps/argocd/defaults/main.yml
- name: Render versions in README.md - name: Render versions in README.md
blockinfile: blockinfile:
marker: '<!-- {mark} ANSIBLE MANAGED BLOCK -->' marker: '<!-- {mark} ANSIBLE MANAGED BLOCK -->'