-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgitops.yml
96 lines (87 loc) · 3.06 KB
/
gitops.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
- name: "Deploy Argocd Applications"
hosts: all
vars_files:
- vars.local.yml
vars:
#owner/repo format
gitea_repo_name: "gitea/{{ github_template_repo | basename }}"
# uncomment this to point to GitHub or other url,
# if this is not set it will use local gitea
# gitops_repo_url: 'https://gitea.kameshs.dev/'
# the cluster where the target applications will be deployed
target_cluster_context: cluster1
# the kubernetes context where we can find Argocd deployment
git_k8s_context: mgmt
argocd_k8s_context: mgmt
tasks:
- name: "Get Argocd Server Service"
kubernetes.core.k8s_info:
kind: Service
name: argocd-server
namespace: argocd
context: "{{ argocd_k8s_context }}"
register: argcod_server_svc_result
- name: "Set Argocd Service fact"
set_fact:
argocd_server_address: "{{ argcod_server_svc_result.resources[0].status.loadBalancer.ingress[0].ip }}"
- name: "Query Git url"
kubernetes.core.k8s_info:
kind: Service
name: gateway-proxy
namespace: gitea
context: "{{ git_k8s_context }}"
register: git_service_result
when: gitops_repo_url is not defined
- name: "Set Git Repo Facts"
set_fact:
git_url: "https://gitea.kameshs.dev"
git_repo_fqn: "https://gitea.kameshs.dev/{{ gitea_repo_name }}"
vars:
q: "status.loadBalancer.ingress[*].ip"
when: gitops_repo_url is not defined
- name: "Retrieve Gitea password"
ansible.builtin.slurp:
path: "{{ work_dir }}/gitea.password"
register: gitea_password
- name: "Register demo git Repo"
ansible.builtin.command:
argv:
- argocd
- repo
- add
- "{{ git_repo_fqn }}"
- --username="gitea"
- --password="{{ gitea_password['contents'] | b64decode }}"
- --server={{ argocd_server_address }}
- "{{ argocd_k8s_context }}"
loop_control:
label: "{{ item.key }}"
- name: "Register GitOps Facts"
set_fact:
kube_cluster_url: "{{ api.connection.host }}"
git_repository_url: "{{ git_repo_fqn }}"
- name: "Deploy Argocd Applications"
kubernetes.core.helm:
release_namespace: argocd
release_name: gloo-edge-gitops-quickstart
create_namespace: yes
chart_ref: "{{ playbook_dir }}/charts/argocd-apps"
values_files:
- "{{ work_dir }}/argo-apps-values.yaml"
context: "{{ argocd_k8s_context }}"
when: argocd_app_cleanup is not defined or not argocd_app_cleanup
- name: "Cleanup Argocd Applications"
kubernetes.core.helm:
release_namespace: argocd
release_name: gloo-edge-gitops-quickstart
create_namespace: yes
chart_ref: "{{ playbook_dir }}/charts/argocd-apps"
state: absent
context: "{{ argocd_k8s_context }}"
when: argocd_app_cleanup | default(false)
- name: "direnv allow"
ansible.builtin.command:
argv:
- direnv
- allow
- "{{ playbook_dir }}"