blob: df7e2d88e3c1f215555bc3d277ab50a1b45df998 (
plain)
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
|
---
- name: Generate a random string for test
set_fact:
test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
when: test_id is not defined
- name: generate random string for schedule
set_fact:
org_name: "AWX-Collection-tests-organization-org-{{ test_id }}"
sched1: "AWX-Collection-tests-schedule-sched1-{{ test_id }}"
sched2: "AWX-Collection-tests-schedule-sched2-{{ test_id }}"
cred1: "AWX-Collection-tests-schedule-cred1-{{ test_id }}"
proj1: "AWX-Collection-tests-schedule-proj1-{{ test_id }}"
proj2: "AWX-Collection-tests-schedule-proj2-{{ test_id }}"
jt1: "AWX-Collection-tests-schedule-jt1-{{ test_id }}"
jt2: "AWX-Collection-tests-schedule-jt1-{{ test_id }}"
ee1: "AWX-Collection-tests-schedule-ee1-{{ test_id }}"
label1: "AWX-Collection-tests-schedule-l1-{{ test_id }}"
label2: "AWX-Collection-tests-schedule-l2-{{ test_id }}"
ig1: "AWX-Collection-tests-schedule-ig1-{{ test_id }}"
ig2: "AWX-Collection-tests-schedule-ig2-{{ test_id }}"
slice_inventory: "AWX-Collection-tests-schedule-slice-inv-{{ test_id }}"
host_name: "AWX-Collection-tests-schedule-host-{{ test_id }}"
slice_num: 10
- block:
- name: Try to create without an rrule
schedule:
name: "{{ sched1 }}"
state: present
unified_job_template: "Demo Job Template"
enabled: true
register: result
ignore_errors: true
- assert:
that:
- result is failed
- "'Unable to create schedule {{ sched1 }}' in result.msg"
- name: Create with options that the JT does not support
schedule:
name: "{{ sched1 }}"
state: present
unified_job_template: "Demo Job Template"
rrule: "DTSTART:20191219T130551Z RRULE:FREQ=WEEKLY;INTERVAL=1;COUNT=1"
description: "This hopefully will not work"
extra_data:
some: var
inventory: Demo Inventory
scm_branch: asdf1234
job_type: run
job_tags: other_tags
skip_tags: some_tags
limit: node1
diff_mode: true
verbosity: 4
enabled: true
register: result
ignore_errors: true
- assert:
that:
- result is failed
- "'Unable to create schedule {{ sched1 }}' in result.msg"
- name: Build a real schedule
schedule:
name: "{{ sched1 }}"
state: present
unified_job_template: "Demo Job Template"
rrule: "DTSTART:20191219T130551Z RRULE:FREQ=WEEKLY;INTERVAL=1;COUNT=1"
register: result
- assert:
that:
- result is changed
- name: Build a real schedule with exists
schedule:
name: "{{ sched1 }}"
state: exists
unified_job_template: "Demo Job Template"
rrule: "DTSTART:20191219T130551Z RRULE:FREQ=WEEKLY;INTERVAL=1;COUNT=1"
register: result
- assert:
that:
- result is not changed
- name: Delete a real schedule
schedule:
name: "{{ sched1 }}"
state: absent
unified_job_template: "Demo Job Template"
rrule: "DTSTART:20191219T130551Z RRULE:FREQ=WEEKLY;INTERVAL=1;COUNT=1"
register: result
- assert:
that:
- result is changed
- name: Build a real schedule with exists
schedule:
name: "{{ sched1 }}"
state: exists
unified_job_template: "Demo Job Template"
rrule: "DTSTART:20191219T130551Z RRULE:FREQ=WEEKLY;INTERVAL=1;COUNT=1"
register: result
- assert:
that:
- result is changed
- name: Rebuild the same schedule
schedule:
name: "{{ sched1 }}"
state: present
unified_job_template: "Demo Job Template"
rrule: "DTSTART:20191219T130551Z RRULE:FREQ=WEEKLY;INTERVAL=1;COUNT=1"
register: result
- assert:
that:
- result is not changed
- name: Create a Demo Project
project:
name: "{{ proj1 }}"
organization: Default
allow_override: true
state: present
scm_type: git
scm_url: https://github.com/ansible/ansible-tower-samples.git
- name: "Create a new organization"
organization:
name: "{{ org_name }}"
- name: Create a Demo Project in another org
project:
name: "{{ proj2 }}"
organization: "{{ org_name }}"
allow_override: true
state: present
scm_type: git
scm_url: https://github.com/ansible/ansible-tower-samples.git
- name: Create Credential1
credential:
name: "{{ cred1 }}"
organization: Default
credential_type: Red Hat Ansible Automation Platform
register: cred1_result
- name: Create Job Template with all prompts
job_template:
name: "{{ jt1 }}"
organization: Default
project: "{{ proj1 }}"
inventory: Demo Inventory
playbook: hello_world.yml
ask_variables_on_launch: true
ask_inventory_on_launch: true
ask_scm_branch_on_launch: true
ask_credential_on_launch: true
ask_job_type_on_launch: true
ask_tags_on_launch: true
ask_skip_tags_on_launch: true
ask_limit_on_launch: true
ask_diff_mode_on_launch: true
ask_verbosity_on_launch: true
ask_execution_environment_on_launch: true
ask_forks_on_launch: true
ask_instance_groups_on_launch: true
ask_job_slice_count_on_launch: true
ask_labels_on_launch: true
ask_timeout_on_launch: true
job_type: run
state: present
register: result
- assert:
that:
- "result is changed"
- name: Create labels
label:
name: "{{ item }}"
organization: "{{ org_name }}"
loop:
- "{{ label1 }}"
- "{{ label2 }}"
- name: Create an execution environment
execution_environment:
name: "{{ ee1 }}"
image: "junk"
- name: Create instance groups
instance_group:
name: "{{ item }}"
loop:
- "{{ ig1 }}"
- "{{ ig2 }}"
- name: Create proper inventory for slice count
inventory:
name: "{{ slice_inventory }}"
organization: "{{ org_name }}"
state: present
register: result
- name: Create a Host
host:
name: "{{ host_name }}-{{ item }}"
inventory: "{{ slice_inventory }}"
state: present
variables:
ansible_connection: local
loop: "{{ range(slice_num)|list }}"
register: result
- name: Create with options that the JT does support
schedule:
name: "{{ sched2 }}"
state: present
organization: Default
unified_job_template: "{{ jt1 }}"
rrule: "DTSTART:20191219T130551Z RRULE:FREQ=WEEKLY;INTERVAL=1;COUNT=1"
description: "This hopefully will work"
extra_data:
some: var
inventory: "{{ slice_inventory }}"
scm_branch: asdf1234
credentials:
- "{{ cred1 }}"
job_type: run
job_tags: other_tags
skip_tags: some_tags
limit: node1
diff_mode: true
verbosity: 4
enabled: true
execution_environment: "{{ ee1 }}"
forks: 10
instance_groups:
- "{{ ig1 }}"
- "{{ ig2 }}"
job_slice_count: "{{ slice_num }}"
labels:
- "{{ label1 }}"
- "{{ label2 }}"
timeout: 10
register: result
ignore_errors: true
- assert:
that:
- "result is changed"
- name: Reset some options
schedule:
name: "{{ sched2 }}"
state: present
execution_environment: ""
forks: 1
instance_groups: []
job_slice_count: 1
labels: []
timeout: 60
register: result
ignore_errors: true
- assert:
that:
- "result is changed"
- name: Disable a schedule
schedule:
name: "{{ sched1 }}"
unified_job_template: "Demo Job Template"
state: present
enabled: "false"
register: result
- assert:
that:
- result is changed
- name: Create a second Job Template in new org
job_template:
name: "{{ jt2 }}"
project: "{{ proj2 }}"
inventory: Demo Inventory
playbook: hello_world.yml
job_type: run
state: present
- name: Build a schedule with a job template's name in two orgs
schedule:
name: "{{ sched1 }}"
state: present
unified_job_template: "{{ jt2 }}"
rrule: "DTSTART:20191219T130551Z RRULE:FREQ=WEEKLY;INTERVAL=1;COUNT=1"
register: result
- name: Verify we can't find the schedule without the UJT lookup
schedule:
name: "{{ sched1 }}"
state: present
rrule: "DTSTART:20201219T130551Z RRULE:FREQ=WEEKLY;INTERVAL=1;COUNT=1"
register: result
ignore_errors: true
- assert:
that:
- result is failed
- name: Verify we can find the schedule with the UJT lookup and delete it
schedule:
name: "{{ sched1 }}"
state: absent
unified_job_template: "{{ jt2 }}"
register: result
- assert:
that:
- result is changed
always:
- name: Delete the schedules
schedule:
name: "{{ item }}"
state: absent
loop:
- "{{ sched1 }}"
- "{{ sched2 }}"
ignore_errors: True
- name: Delete the jt1
job_template:
name: "{{ jt1 }}"
project: "{{ proj1 }}"
playbook: hello_world.yml
state: absent
ignore_errors: True
- name: Delete the jt2
job_template:
name: "{{ jt2 }}"
project: "{{ proj2 }}"
playbook: hello_world.yml
state: absent
ignore_errors: True
- name: Delete the Project2
project:
name: "{{ proj2 }}"
organization: "{{ org_name }}"
state: absent
scm_type: git
scm_url: https://github.com/ansible/ansible-tower-samples.git
ignore_errors: True
- name: Delete the Project1
project:
name: "{{ proj1 }}"
organization: Default
state: absent
scm_type: git
scm_url: https://github.com/ansible/ansible-tower-samples.git
ignore_errors: True
- name: Delete Credential1
credential:
name: "{{ cred1 }}"
organization: Default
credential_type: Red Hat Ansible Automation Platform
state: absent
ignore_errors: True
# Labels can not be deleted
- name: Delete an execution environment
execution_environment:
name: "{{ ee1 }}"
image: "junk"
state: absent
ignore_errors: True
- name: Delete instance groups
instance_group:
name: "{{ item }}"
state: absent
loop:
- "{{ ig1 }}"
- "{{ ig2 }}"
ignore_errors: True
- name: "Remove the organization"
organization:
name: "{{ org_name }}"
state: absent
ignore_errors: True
- name: "Delete slice inventory"
inventory:
name: "{{ slice_inventory }}"
organization: "{{ org_name }}"
state: absent
ignore_errors: True
- name: Delete slice hosts
host:
name: "{{ host_name }}-{{ item }}"
inventory: "{{ slice_inventory }}"
state: absent
loop: "{{ range(slice_num)|list }}"
ignore_errors: True
|