-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-playbook.yaml
157 lines (145 loc) · 4.96 KB
/
init-playbook.yaml
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
- name: Initialize gitops reconciliation loop
hosts: localhost
connection: local
gather_facts: false
tasks:
- name: Install OpenShift GitOps operator
kubernetes.core.k8s:
definition: "{{ lookup('kubernetes.core.kustomize', dir='.init/hub1/openshift-gitops-operator', enable_helm=True) }}"
wait: true
register: installOpenShiftGitopsOperatorResult
- name: Install OpenShift GitOps operator result output (enable -v to see)
ansible.builtin.debug:
var: installOpenShiftGitopsOperatorResult
verbosity: 1
- name: Wait for CRD established | ArgoCD
kubernetes.core.k8s_info:
kind: CustomResourceDefinition
api_version: apiextensions.k8s.io/v1
name: argocds.argoproj.io
wait: true
wait_timeout: 300
wait_condition:
type: Established
status: True
reason: InitialNamesAccepted
- name: Wait for CRD established | Application
kubernetes.core.k8s_info:
kind: CustomResourceDefinition
api_version: apiextensions.k8s.io/v1
name: applications.argoproj.io
wait: true
wait_timeout: 300
wait_condition:
type: Established
status: True
reason: InitialNamesAccepted
- name: Wait for Namespace | openshift-gitops
kubernetes.core.k8s_info:
kind: Namespace
api_version: v1
name: openshift-gitops
wait: true
wait_timeout: 300
- name: Configure cluster OpenShift GitOps (ArgoCD)
kubernetes.core.k8s:
definition: "{{ lookup('kubernetes.core.kustomize', dir='.init/hub1/openshift-gitops', enable_helm=True) }}"
wait: true
register: configureClusterOpenShiftGitops
- name: Configure cluster OpenShift GitOps (ArgoCD) result output (enable -v to see)
ansible.builtin.debug:
var: configureClusterOpenShiftGitops
verbosity: 1
- name: Wait for ArgoCD AppProjects
kubernetes.core.k8s_info:
kind: AppProject
api_version: argoproj.io/v1alpha1
name: "{{ appproject }}"
namespace: openshift-gitops
wait: true
wait_timeout: 300
loop:
- cluster-management
- tenant-management
loop_control:
loop_var: appproject
- name: Install Application to initialize gitops reconciliation loop
kubernetes.core.k8s:
definition: "{{ lookup('kubernetes.core.kustomize', dir='.init/hub1/hub-cluster-management-root-application', enable_helm=True) }}"
wait: true
register: installApplicationResult
- name: Install Application result output (enable -v to see)
ansible.builtin.debug:
var: installApplicationResult
verbosity: 1
- name: Wait for ArgoCD Applications in openshift-gitops to be healthy and synced (10 second delay between attempts, time out at 20 minutes)
kubernetes.core.k8s_info:
kind: Application
api_version: argoproj.io/v1alpha1
namespace: openshift-gitops
register: applications
retries: 120
delay: 10
until: >-
(
(
applications.resources |
rejectattr('status.health.status', 'defined') |
map(attribute='metadata') |
map(attribute='name') |
list
) +
(
applications.resources |
selectattr('status.health.status', 'defined') |
rejectattr('status.health.status', 'eq', 'Healthy') |
map(attribute='metadata') |
map(attribute='name') |
list
) +
(
applications.resources |
rejectattr('status.sync.status', 'defined') |
map(attribute='metadata') |
map(attribute='name') |
list
) +
(
applications.resources |
selectattr('status.sync.status', 'defined') |
rejectattr('status.sync.status', 'eq', 'Synced') |
map(attribute='metadata') |
map(attribute='name') |
list
)
) |
length == 0
failed_when: false
- name: Get list of ArgoCD Applications in openshift-gitops that are still not healthy and synced
ansible.builtin.set_fact:
unhealthy_applications: >-
{{
(
(
applications.resources |
rejectattr('status.health.status', 'eq', 'Healthy') |
map(attribute='metadata') |
map(attribute='name') |
list
) +
(
applications.resources |
rejectattr('status.sync.status', 'eq', 'Synced') |
map(attribute='metadata') |
map(attribute='name') |
list
)
)
}}
- name: Verify after waiting all ArgoCD Applications in openshift-gitops are healthy and synced
ansible.builtin.assert:
that:
unhealthy_applications | length == 0
quiet: false
fail_msg: "Failed due to ArgoCD Applications in openshift-gitops still not being healthy and synced: {{ unhealthy_applications }}"
success_msg: "All ArgoCD Applications in openshift-gitops are healthy and synced"