Add ansible files

This commit is contained in:
Evrard Van Espen
2025-11-23 11:22:45 +00:00
parent 8fc60f9d8b
commit bc439597cb
26 changed files with 1364 additions and 0 deletions

View File

@@ -0,0 +1,87 @@
- name: Setup ArgoCD
hosts:
- localhost
vars_files:
- config/config_vars.yaml
tasks:
- name: Check if argocd command is available
ansible.builtin.command:
cmd: "which argocd"
register: argocd_check
ignore_errors: true
changed_when: false
- name: Fail if argocd command is not available
when: argocd_check.rc != 0
ansible.builtin.fail:
msg: "argocd command not found. Please install argocd CLI."
- name: Create ArgoCD namespace
kubernetes.core.k8s:
name: argocd
api_version: v1
kind: Namespace
state: present
- name: Install ArgoCD
kubernetes.core.k8s:
src: https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
state: present
namespace: argocd
- name: Patch ArgoCD ConfigMap
kubernetes.core.k8s:
kind: ConfigMap
name: argocd-cmd-params-cm
namespace: argocd
merge_type: merge
definition:
data:
server.insecure: "true"
- name: Get ArgoCD server pod start time
kubernetes.core.k8s_info:
kind: Pod
namespace: argocd
label_selectors:
- app.kubernetes.io/name = argocd-server
register: argocd_pods
- name: Calculate time since ArgoCD server started
ansible.builtin.set_fact:
argocd_uptime: "{{ ((ansible_date_time.iso8601.replace('T', ' ').replace('Z', '') | to_datetime) - (argocd_pods.resources[0].status.startTime.replace('T', ' ').replace('Z', '') | to_datetime)).total_seconds() }}"
when: argocd_pods.resources | length > 0
- name: Display ArgoCD server uptime
ansible.builtin.debug:
msg: "ArgoCD server has been running for {{ argocd_uptime }}"
when: argocd_uptime is defined
- name: Restart ArgoCD server pods (only if running for less than 2 minutes)
when: argocd_uptime is defined and argocd_uptime < 120
kubernetes.core.k8s:
kind: Deployment
name: argocd-server
namespace: argocd
state: present
definition:
spec:
template:
metadata:
annotations:
kubectl.kubernetes.io/restartedAt: "{{ ansible_date_time.iso8601 }}"
- name: Configure ArgoCD Ingress
kubernetes.core.k8s:
template: files/argocd_svc.template.yaml
state: present
namespace: argocd
- name: Get K8s context
ansible.builtin.command:
cmd: "kubectl config get-contexts -o name"
register: k8s_context
- name: Configure ArgoCD context
ansible.builtin.command:
cmd: "argocd cluster add {{ k8s_context.stdout_lines[0] }}"