-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsite.yml
346 lines (311 loc) · 10.5 KB
/
site.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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
---
- hosts: demo_machine
vars_prompt:
- name: "mode"
prompt: 'Do you want to stand up a new environment or delete an existing environment? ("new" or "delete")'
default: "new"
private: no
pre_tasks:
- name: Verify Ansible is greater than 2.8
assert:
that: "ansible_version.full is version_compare('2.8', '>=')"
msg: >
" You must update Ansible to at least 2.8."
- name: Check for websites
uri:
url: "{{ item.url }}"
body_format: json
status_code: 200
return_content: yes
validate_certs: NO
method: GET
register: result
until: result.status == 200
retries: 5
delay: 2
loop:
- { url: 'https://hub.docker.com' }
- { url: 'https://github.com' }
- { url: 'https://plugins.jenkins.io'}
- name: Check if Kubectl is installed in current shell
command: |
which kubectl
register: kubectl_is_installed
ignore_errors: yes
- name: Fail if kubectl not installed
assert:
that: "kubectl_is_installed.stdout != ''"
fail_msg: "kubectl is not found in the current shell. Please install kubectl and connect it to your target cluster."
success_msg: "kubectl found. Located at {{ kubectl_is_installed.stdout }}"
- name: Check that kubectl is connected to a cluster.
command: |
kubectl get nodes -o wide
register: kubectl_is_configured
ignore_errors: yes
- name: Fail if kubectl not connected to a cluster
assert:
that: "kubectl_is_configured.rc == 0"
fail_msg: "kubectl is not configured with a cluster connection. Please connect to a cluster and re-run."
success_msg: "kubectl is configured with a cluster connection."
- name: Set fact that we are dealing with a docker-desktop k8s implementation
set_fact:
docker_desktop: "configured"
when: kubectl_is_configured.stdout is search("docker-desktop")
- name: Configure k8s worker node Ip address
block:
- name: Find IP address of k8s node if not using docker-desktop
command: |
kubectl get nodes -l node-role.kubernetes.io/worker!=true,node-role.kubernetes.io/controlplane!=true -o wide | awk 'NR==2 {print $6}'
register: workerNodeAddressResult
- name: Set ip address of worker node
set_fact:
workerNodeAddress: "{{ workerNodeAddressResult.stdout }}"
when: docker_desktop is undefined
tasks:
- name: install PIP modules
pip:
name:
- pyYAML
- kubernetes
- openshift
extra_args: --user
- name: Load cluster tools and set demostage status
block:
- name: Find all manifests in manifests/tools directory
find:
paths: "{{ playbook_dir }}/files/manifests/tools/"
file_type: file
use_regex: yes
patterns:
- '.*.yml$'
- '.*.yaml$'
register: toolManifests
- name: Load Cluster tools manifests
k8s:
state: present
src: "{{ toolsLoad }}"
wait: yes
wait_condition:
reason: completed
status: "True"
wait_timeout: 360
register: demoStage
loop: "{{ toolManifests.files | map(attribute='path') | list }}"
loop_control:
loop_var: toolsLoad
- name: Set demo status
set_fact:
demoStage: "toolsLoaded"
when: mode == 'new'
- name: Set up ingress if running on local docker for mac instance of k8s
include_tasks: localIngress.yml
when: docker_desktop == "configured" and mode == "new" and demoStage == "toolsLoaded"
- name: Configure DAP source and access. Set demo status
block:
- name: Set DAP ingress route when using local docker-desktop
set_fact:
dapIngressRoute: "dap.{{ clusterFQDN }}"
when: docker_desktop == "configured"
- name: Set DAP ingress to node and port when using a cluster
set_fact:
dapIngressRoute: "{{ workerNodeAddress }}:{{ dapPort }}"
when: docker_desktop != "configured"
- name: Configure DAP
include_tasks: "{{ dapStage }}.yml"
loop:
- source
- access
loop_control:
loop_var: dapStage
- name: Set demo stage status
set_fact:
demoStage: "dapConfigured"
when: demoStage == "toolsLoaded" and mode == "new"
- name: Configure demo tools and set status
block:
- name: Configure demo tools
include_tasks: "{{ tasks }}.yml"
loop:
- apps
loop_control:
loop_var: tasks
- name: Set demo stage status
set_fact:
demoStage: "demoToolsConfigured"
when: demoStage == "dapConfigured" and mode == "new"
- name: Clean environment
block:
- name: Ask user for password for removal of hosts
pause:
prompt: "Enter SUDO password"
echo: no
register: sudo
when: hostsChecks.changed != true
no_log: yes
- name: Set ansible become password for removal of hosts
set_fact:
ansible_become_pass: "{{ sudo.user_input }}"
no_log: yes
when: hostsChecks.changed != true
- name: Remove host entries for webpages
lineinfile:
path: /etc/hosts
line: 127.0.0.1 {{ item }}
state: absent
with_items:
- "{{ ingressRoutes }}"
become: yes
when: hostsChecks.changed != true
- name: Find all manifests in manifests/sidecarInjector directory
find:
paths: "{{ playbook_dir }}/files/manifests/sidecarInjector/deployment"
file_type: file
use_regex: yes
patterns:
- '.*.yml$'
- '.*.yaml$'
register: sidecarManifests
- name: Remove Injector manifests
k8s:
state: absent
src: "{{ sidecarInjectorLoad }}"
namespace: injectors
wait: yes
wait_condition:
reason: completed
status: "True"
wait_timeout: 360
loop: "{{ sidecarManifests.files | map(attribute='path') | list }}"
loop_control:
loop_var: sidecarInjectorLoad
- name: Remove Injector Namespace
k8s:
state: absent
api_version: v1
kind: Namespace
name: injectors
wait: yes
wait_condition:
reason: completed
status: "True"
wait_timeout: 360
- name: remove sidecar download
file:
state: absent
path: "{{ playbook_dir }}/files/manifests/sidecarInjector/"
- name: Find all manifests in metrics directory
find:
paths: "{{ playbook_dir }}/files/manifests/tools/metrics/deploy/1.8+/"
file_type: file
register: metrics
- name: remove metrics server
k8s:
state: absent
src: "{{ item }}"
wait: yes
wait_condition:
reason: completed
status: "True"
loop: "{{ metrics.files | map(attribute='path') | list }}"
- name: Remove dap and demoapps namespacenamespace
k8s:
name: "{{ item }}"
api_version: v1
kind: Namespace
state: absent
wait: yes
wait_condition:
reason: completed
status: "True"
wait_timeout: 360
with_items:
- dap
- demoapps
- name: Find all manifests in ingress directory
find:
paths: "{{ playbook_dir }}/files/manifests/ingress/"
file_type: file
register: ingress
- name: Remove tool ingress
k8s:
state: absent
src: "{{ item }}"
wait: yes
wait_condition:
reason: completed
status: "True"
wait_timeout: 360
loop: "{{ ingress.files | map(attribute='path') | list }}"
- name: Find all manifests in tools directory
find:
paths: "{{ playbook_dir }}/files/manifests/tools/"
file_type: file
register: tools
- name: Remove Cluster tools
k8s:
state: absent
src: "{{ item }}"
wait: yes
wait_condition:
reason: completed
status: "True"
wait_timeout: 360
loop: "{{ tools.files | map(attribute='path') | list }}"
- name: remove metrics download
file:
state: absent
path: "{{ playbook_dir }}/files/manifests/tools/metrics/"
when: mode == "delete"
vars:
adminPass: 'CYberark11@@'
account: 'cyberark'
dapAdmin: 'admin'
dapAdminPass: "{{adminPass}}"
dapAccount: "{{ account }}"
dapSourceService: 'source.dap.svc.cluster.local'
dapAccessService: 'access.dap.svc.cluster.local'
dapFollowerReplicaCount: 1
dapMasterContainerName: 'node'
clusterFQDN: "k8scluster.local"
ingressEnable: 'yes'
dapIngressRoute: "dap.{{clusterFQDN}}"
dapPort: 30443
jenkinsIngressRoute: "jenkins.{{clusterFQDN}}"
dashboardIngressRoute: "dashboard.{{clusterFQDN}}"
weaveIngressRoute: "weave.{{clusterFQDN}}"
gogsIngressRoute: "gogs.{{clusterFQDN}}"
demoMachineAddress: "{{ ansible_default_ipv4.address }}"
ingressRoutes:
- "{{dapIngressRoute}}"
- "{{jenkinsIngressRoute}}"
- "{{dashboardIngressRoute}}"
- "{{weaveIngressRoute}}"
- "{{gogsIngressRoute}}"
gogsAdmin: 'eva'
gogsAdminPass: "{{adminPass}}"
gogsOrg: "{{ account }}"
gogsApiAccessPass: "{{ gogsAdminPass }}"
jenkinsPlugins:
- cloudbees-folder
- antisamy-markup-formatter
- build-timeout
- credentials-binding
- timestamper
- ws-cleanup
- ant
- gradle
- workflow-aggregator
- github-organization-folder
- pipeline-stage-view
- build-pipeline-plugin
- conditional-buildstep
- jenkins-multijob-plugin
- git
- subversion
- tfs
- gitlab-plugin
- ssh-slaves
- matrix-auth
- pam-auth
- email-ext
- mailer