Debian Codegraph @

test/integration/targets/ansible-galaxy-collection/tasks/install.yml

raw
1 ---
2 - name: create test collection install directory - {{ test_id }}
3 file:
4 path: '{{ galaxy_dir }}/ansible_collections'
5 state: directory
6
7 - name: install simple collection from specific server
8 command: ansible-galaxy collection install namespace1.name1 -s galaxy_ng_token -vvvv
9 environment:
10 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
11
12 - name: remove collection
13 file:
14 path: '{{ galaxy_dir }}/ansible_collections/namespace1/name1'
15 state: absent
16
17 - name: install simple collection from first accessible server
18 command: ansible-galaxy collection install namespace1.name1 -vvvv
19 environment:
20 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
21 register: from_first_good_server
22
23 - name: get installed files of install simple collection from first good server
24 find:
25 path: '{{ galaxy_dir }}/ansible_collections/namespace1/name1'
26 file_type: file
27 register: install_normal_files
28
29 - name: get the manifest of install simple collection from first good server
30 slurp:
31 path: '{{ galaxy_dir }}/ansible_collections/namespace1/name1/MANIFEST.json'
32 register: install_normal_manifest
33
34 - name: assert install simple collection from first good server
35 assert:
36 that:
37 - '"Installing ''namespace1.name1:1.0.9'' to" in from_first_good_server.stdout'
38 - install_normal_files.files | length == 3
39 - install_normal_files.files[0].path | basename in ['MANIFEST.json', 'FILES.json', 'README.md']
40 - install_normal_files.files[1].path | basename in ['MANIFEST.json', 'FILES.json', 'README.md']
41 - install_normal_files.files[2].path | basename in ['MANIFEST.json', 'FILES.json', 'README.md']
42 - (install_normal_manifest.content | b64decode | from_json).collection_info.version == '1.0.9'
43 - "info_dir is is_dir"
44 vars:
45 info_dir: "{{ galaxy_dir }}/ansible_collections/namespace1.name1-1.0.9.info"
46
47 - name: Remove the collection
48 file:
49 path: '{{ galaxy_dir }}/ansible_collections/namespace1'
50 state: absent
51
52 - name: install simple collection with implicit path - {{ test_id }}
53 command: ansible-galaxy collection install namespace1.name1 -s '{{ test_name }}' {{ galaxy_verbosity }}
54 environment:
55 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
56 register: install_normal
57
58 - name: get installed files of install simple collection with implicit path - {{ test_id }}
59 find:
60 path: '{{ galaxy_dir }}/ansible_collections/namespace1/name1'
61 file_type: file
62 register: install_normal_files
63
64 - name: get the manifest of install simple collection with implicit path - {{ test_id }}
65 slurp:
66 path: '{{ galaxy_dir }}/ansible_collections/namespace1/name1/MANIFEST.json'
67 register: install_normal_manifest
68
69 - name: assert install simple collection with implicit path - {{ test_id }}
70 assert:
71 that:
72 - '"Installing ''namespace1.name1:1.0.9'' to" in install_normal.stdout'
73 - install_normal_files.files | length == 3
74 - install_normal_files.files[0].path | basename in ['MANIFEST.json', 'FILES.json', 'README.md']
75 - install_normal_files.files[1].path | basename in ['MANIFEST.json', 'FILES.json', 'README.md']
76 - install_normal_files.files[2].path | basename in ['MANIFEST.json', 'FILES.json', 'README.md']
77 - (install_normal_manifest.content | b64decode | from_json).collection_info.version == '1.0.9'
78
79 - name: install existing without --force - {{ test_id }}
80 command: ansible-galaxy collection install namespace1.name1 -s '{{ test_name }}' {{ galaxy_verbosity }}
81 environment:
82 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
83 register: install_existing_no_force
84
85 - name: assert install existing without --force - {{ test_id }}
86 assert:
87 that:
88 - '"Nothing to do. All requested collections are already installed" in install_existing_no_force.stdout'
89
90 - name: install existing with --force - {{ test_id }}
91 command: ansible-galaxy collection install namespace1.name1 -s '{{ test_name }}' --force {{ galaxy_verbosity }}
92 environment:
93 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
94 register: install_existing_force
95
96 - name: assert install existing with --force - {{ test_id }}
97 assert:
98 that:
99 - '"Installing ''namespace1.name1:1.0.9'' to" in install_existing_force.stdout'
100
101 - name: remove test installed collection - {{ test_id }}
102 file:
103 path: '{{ galaxy_dir }}/ansible_collections/namespace1'
104 state: absent
105
106 - name: install pre-release as explicit version to custom dir - {{ test_id }}
107 command: ansible-galaxy collection install 'namespace1.name1:1.1.0-beta.1' -s '{{ test_name }}' -p '{{ galaxy_dir }}/ansible_collections' {{ galaxy_verbosity }}
108 register: install_prerelease
109
110 - name: get result of install pre-release as explicit version to custom dir - {{ test_id }}
111 slurp:
112 path: '{{ galaxy_dir }}/ansible_collections/namespace1/name1/MANIFEST.json'
113 register: install_prerelease_actual
114
115 - name: assert install pre-release as explicit version to custom dir - {{ test_id }}
116 assert:
117 that:
118 - '"Installing ''namespace1.name1:1.1.0-beta.1'' to" in install_prerelease.stdout'
119 - (install_prerelease_actual.content | b64decode | from_json).collection_info.version == '1.1.0-beta.1'
120 - not ([info_dir, "namespace1.name1-1.0.9.info"] | path_join) is is_dir
121 - ([info_dir, "namespace1.name1-1.1.0-beta.1.info"] | path_join) is is_dir
122 vars:
123 info_dir: "{{ galaxy_dir }}/ansible_collections"
124
125 - name: Remove beta
126 file:
127 path: '{{ galaxy_dir }}/ansible_collections/namespace1/name1'
128 state: absent
129
130 - name: install pre-release version with --pre to custom dir - {{ test_id }}
131 command: ansible-galaxy collection install --pre 'namespace1.name1' -s '{{ test_name }}' -p '{{ galaxy_dir }}/ansible_collections' {{ galaxy_verbosity }}
132 register: install_prerelease
133
134 - name: get result of install pre-release version with --pre to custom dir - {{ test_id }}
135 slurp:
136 path: '{{ galaxy_dir }}/ansible_collections/namespace1/name1/MANIFEST.json'
137 register: install_prerelease_actual
138
139 - name: assert install pre-release version with --pre to custom dir - {{ test_id }}
140 assert:
141 that:
142 - '"Installing ''namespace1.name1:1.1.0-beta.1'' to" in install_prerelease.stdout'
143 - (install_prerelease_actual.content | b64decode | from_json).collection_info.version == '1.1.0-beta.1'
144
145 - name: install multiple collections with dependencies - {{ test_id }}
146 command: ansible-galaxy collection install parent_dep.parent_collection:1.0.0 namespace2.name -s {{ test_name }} {{ galaxy_verbosity }}
147 args:
148 chdir: '{{ galaxy_dir }}/ansible_collections'
149 environment:
150 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
151 ANSIBLE_CONFIG: '{{ galaxy_dir }}/ansible.cfg'
152 register: install_multiple_with_dep
153
154 - name: get result of install multiple collections with dependencies - {{ test_id }}
155 slurp:
156 path: '{{ galaxy_dir }}/ansible_collections/{{ collection.namespace }}/{{ collection.name }}/MANIFEST.json'
157 register: install_multiple_with_dep_actual
158 loop_control:
159 loop_var: collection
160 loop:
161 - namespace: namespace2
162 name: name
163 - namespace: parent_dep
164 name: parent_collection
165 - namespace: child_dep
166 name: child_collection
167 - namespace: child_dep
168 name: child_dep2
169
170 - name: assert install multiple collections with dependencies - {{ test_id }}
171 assert:
172 that:
173 - (install_multiple_with_dep_actual.results[0].content | b64decode | from_json).collection_info.version == '1.0.0'
174 - (install_multiple_with_dep_actual.results[1].content | b64decode | from_json).collection_info.version == '1.0.0'
175 - (install_multiple_with_dep_actual.results[2].content | b64decode | from_json).collection_info.version == '0.9.9'
176 - (install_multiple_with_dep_actual.results[3].content | b64decode | from_json).collection_info.version == '1.2.2'
177
178 - name: expect failure with dep resolution failure - {{ test_id }}
179 command: ansible-galaxy collection install fail_namespace.fail_collection -s {{ test_name }} {{ galaxy_verbosity }}
180 register: fail_dep_mismatch
181 failed_when:
182 - '"Could not satisfy the following requirements" not in fail_dep_mismatch.stderr'
183 - '" fail_dep2.name:<0.0.5 (dependency of fail_namespace.fail_collection:2.1.2)" not in fail_dep_mismatch.stderr'
184 - 'pre_release_hint not in fail_dep_mismatch.stderr'
185 vars:
186 pre_release_hint: 'Hint: Pre-releases are not installed by default unless the specific version is given. To enable pre-releases, use --pre.'
187
188 - name: Find artifact url for namespace3.name
189 uri:
190 url: '{{ test_api_server }}/v3/plugin/ansible/content/published/collections/index/namespace3/name/versions/1.0.0/'
191 user: '{{ galaxy_user }}'
192 password: '{{ galaxy_password }}'
193 force_basic_auth: true
194 register: artifact_url_response
195
196 - name: download a collection for an offline install - {{ test_id }}
197 get_url:
198 url: '{{ artifact_url_response.json.download_url }}'
199 dest: '{{ galaxy_dir }}/namespace3.tar.gz'
200 url_username: '{{ galaxy_user }}'
201 url_password: '{{ galaxy_password }}'
202 force_basic_auth: true
203
204 - name: install a collection from a tarball - {{ test_id }}
205 command: ansible-galaxy collection install '{{ galaxy_dir }}/namespace3.tar.gz' {{ galaxy_verbosity }}
206 register: install_tarball
207 environment:
208 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
209
210 - name: get result of install collection from a tarball - {{ test_id }}
211 slurp:
212 path: '{{ galaxy_dir }}/ansible_collections/namespace3/name/MANIFEST.json'
213 register: install_tarball_actual
214
215 - name: assert install a collection from a tarball - {{ test_id }}
216 assert:
217 that:
218 - '"Installing ''namespace3.name:1.0.0'' to" in install_tarball.stdout'
219 - (install_tarball_actual.content | b64decode | from_json).collection_info.version == '1.0.0'
220
221 - name: write a requirements file using the artifact and a conflicting version
222 copy:
223 content: |
224 collections:
225 - name: {{ galaxy_dir }}/namespace3.tar.gz
226 version: 1.2.0
227 dest: '{{ galaxy_dir }}/test_req.yml'
228
229 - name: install the requirements file with mismatched versions
230 command: ansible-galaxy collection install -r '{{ galaxy_dir }}/test_req.yml' {{ galaxy_verbosity }}
231 ignore_errors: True
232 register: result
233 environment:
234 ANSIBLE_NOCOLOR: True
235 ANSIBLE_FORCE_COLOR: False
236
237 - name: remove the requirements file
238 file:
239 path: '{{ galaxy_dir }}/test_req.yml'
240 state: absent
241
242 - assert:
243 that: expected_error in error
244 vars:
245 error: "{{ result.stderr | regex_replace('\\n', ' ') }}"
246 expected_error: >-
247 Failed to resolve the requested dependencies map.
248 Got the candidate namespace3.name:1.0.0 (direct request)
249 which didn't satisfy all of the following requirements:
250 * namespace3.name:1.2.0
251
252 - name: test error for mismatched dependency versions
253 vars:
254 error: "{{ result.stderr | regex_replace('\\n', ' ') }}"
255 expected_error: >-
256 Failed to resolve the requested dependencies map.
257 Got the candidate namespace3.name:1.0.0 (dependency of tmp_parent.name:1.0.0)
258 which didn't satisfy all of the following requirements:
259 * namespace3.name:1.2.0
260 environment:
261 ANSIBLE_NOCOLOR: True
262 ANSIBLE_FORCE_COLOR: False
263 block:
264 - name: init a new parent collection
265 command: ansible-galaxy collection init tmp_parent.name --init-path '{{ galaxy_dir }}/scratch'
266
267 - name: replace the dependencies
268 lineinfile:
269 path: "{{ galaxy_dir }}/scratch/tmp_parent/name/galaxy.yml"
270 regexp: "^dependencies:*"
271 line: "dependencies: { '{{ galaxy_dir }}/namespace3.tar.gz': '1.2.0' }"
272
273 - name: build the new artifact
274 command: ansible-galaxy collection build {{ galaxy_dir }}/scratch/tmp_parent/name
275 args:
276 chdir: "{{ galaxy_dir }}"
277
278 - name: install the artifact to verify the error is handled
279 command: ansible-galaxy collection install '{{ galaxy_dir }}/tmp_parent-name-1.0.0.tar.gz'
280 ignore_errors: yes
281 register: result
282
283 - debug:
284 msg: "Actual - {{ error }}"
285
286 - debug:
287 msg: "Expected - {{ expected_error }}"
288
289 - assert:
290 that: expected_error in error
291 always:
292 - name: clean up collection skeleton and artifact
293 file:
294 state: absent
295 path: "{{ item }}"
296 loop:
297 - "{{ galaxy_dir }}/scratch/tmp_parent/"
298 - "{{ galaxy_dir }}/tmp_parent-name-1.0.0.tar.gz"
299
300 - name: setup bad tarball - {{ test_id }}
301 script: build_bad_tar.py {{ galaxy_dir | quote }}
302
303 - name: fail to install a collection from a bad tarball - {{ test_id }}
304 command: ansible-galaxy collection install '{{ galaxy_dir }}/suspicious-test-1.0.0.tar.gz' {{ galaxy_verbosity }}
305 register: fail_bad_tar
306 failed_when: fail_bad_tar.rc != 1 and "Cannot extract tar entry '../../outside.sh' as it will be placed outside the collection directory" not in fail_bad_tar.stderr
307 environment:
308 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
309
310 - name: get result of failed collection install - {{ test_id }}
311 stat:
312 path: '{{ galaxy_dir }}/ansible_collections\suspicious'
313 register: fail_bad_tar_actual
314
315 - name: assert result of failed collection install - {{ test_id }}
316 assert:
317 that:
318 - not fail_bad_tar_actual.stat.exists
319
320 - name: install a collection from a URI - {{ test_id }}
321 command: ansible-galaxy collection install {{ amanda }}/artifacts/namespace4-name-1.0.0.tar.gz {{ galaxy_verbosity }}
322 register: install_uri
323 environment:
324 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
325
326 - name: get result of install collection from a URI - {{ test_id }}
327 slurp:
328 path: '{{ galaxy_dir }}/ansible_collections/namespace4/name/MANIFEST.json'
329 register: install_uri_actual
330
331 - name: assert install a collection from a URI - {{ test_id }}
332 assert:
333 that:
334 - '"Installing ''namespace4.name:1.0.0'' to" in install_uri.stdout'
335 - (install_uri_actual.content | b64decode | from_json).collection_info.version == '1.0.0'
336
337 - name: fail to install a collection with missing URL - {{ test_id }}
338 command: ansible-galaxy collection install namespace5.name {{ galaxy_verbosity }}
339 register: fail_undefined_server
340 failed_when: fail_undefined_server.stderr is not contains "config 'url' for 'bogus' galaxy_server plugin not provided"
341 environment:
342 ANSIBLE_GALAXY_SERVER_LIST: bogus
343
344 - name: create test requirements file with both roles and collections - {{ test_id }}
345 copy:
346 content: |
347 collections:
348 - namespace6.name
349 - name: namespace7.name
350 roles:
351 - skip.me
352 dest: '{{ galaxy_dir }}/ansible_collections/requirements-with-role.yml'
353
354 - name: install roles from requirements file with collection-only keyring option
355 command: ansible-galaxy role install -r {{ req_file }} -s {{ test_name }} --keyring {{ keyring }}
356 vars:
357 req_file: '{{ galaxy_dir }}/ansible_collections/requirements-with-role.yml'
358 keyring: "{{ gpg_homedir }}/pubring.kbx"
359 ignore_errors: yes
360 register: invalid_opt
361
362 - assert:
363 that:
364 - invalid_opt is failed
365 - "'unrecognized arguments: --keyring' in invalid_opt.stderr"
366
367 # Need to run with -vvv to validate the roles will be skipped msg
368 - name: install collections only with requirements-with-role.yml - {{ test_id }}
369 command: ansible-galaxy collection install -r '{{ galaxy_dir }}/ansible_collections/requirements-with-role.yml' -s '{{ test_name }}' -vvv
370 register: install_req_collection
371 environment:
372 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
373
374 - name: get result of install collections only with requirements-with-roles.yml - {{ test_id }}
375 slurp:
376 path: '{{ galaxy_dir }}/ansible_collections/{{ collection }}/name/MANIFEST.json'
377 register: install_req_collection_actual
378 loop_control:
379 loop_var: collection
380 loop:
381 - namespace6
382 - namespace7
383
384 - name: assert install collections only with requirements-with-role.yml - {{ test_id }}
385 assert:
386 that:
387 - '"contains roles which will be ignored" in install_req_collection.stdout'
388 - '"Installing ''namespace6.name:1.0.0'' to" in install_req_collection.stdout'
389 - '"Installing ''namespace7.name:1.0.0'' to" in install_req_collection.stdout'
390 - (install_req_collection_actual.results[0].content | b64decode | from_json).collection_info.version == '1.0.0'
391 - (install_req_collection_actual.results[1].content | b64decode | from_json).collection_info.version == '1.0.0'
392
393 - name: create test requirements file with just collections - {{ test_id }}
394 copy:
395 content: |
396 collections:
397 - namespace8.name
398 - name: namespace9.name
399 dest: '{{ galaxy_dir }}/ansible_collections/requirements.yaml'
400
401 - name: install collections with ansible-galaxy install - {{ test_id }}
402 command: ansible-galaxy install -r '{{ galaxy_dir }}/ansible_collections/requirements.yaml' -s '{{ test_name }}'
403 register: install_req
404 environment:
405 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
406
407 - name: get result of install collections with ansible-galaxy install - {{ test_id }}
408 slurp:
409 path: '{{ galaxy_dir }}/ansible_collections/{{ collection }}/name/MANIFEST.json'
410 register: install_req_actual
411 loop_control:
412 loop_var: collection
413 loop:
414 - namespace8
415 - namespace9
416
417 - name: assert install collections with ansible-galaxy install - {{ test_id }}
418 assert:
419 that:
420 - '"Installing ''namespace8.name:1.0.0'' to" in install_req.stdout'
421 - '"Installing ''namespace9.name:1.0.0'' to" in install_req.stdout'
422 - (install_req_actual.results[0].content | b64decode | from_json).collection_info.version == '1.0.0'
423 - (install_req_actual.results[1].content | b64decode | from_json).collection_info.version == '1.0.0'
424
425 - name: Test deviations on -r and --role-file without collection or role sub command
426 command: '{{ cmd }}'
427 loop:
428 - ansible-galaxy install -vr '{{ galaxy_dir }}/ansible_collections/requirements.yaml' -s '{{ test_name }}' -vv
429 - ansible-galaxy install --role-file '{{ galaxy_dir }}/ansible_collections/requirements.yaml' -s '{{ test_name }}' -vvv
430 - ansible-galaxy install --role-file='{{ galaxy_dir }}/ansible_collections/requirements.yaml' -s '{{ test_name }}' -vvv
431 loop_control:
432 loop_var: cmd
433
434 - name: uninstall collections for next requirements file test
435 file:
436 path: '{{ galaxy_dir }}/ansible_collections/{{ collection }}/name'
437 state: absent
438 loop_control:
439 loop_var: collection
440 loop:
441 - namespace7
442 - namespace8
443 - namespace9
444
445 - name: store signatures
446 copy:
447 dest: "{{ gpg_homedir }}/{{ item.namespace }}-{{ item.name }}-{{ item.version }}-MANIFEST.json.asc"
448 content: "{{ version_data.signatures.0.signature }}"
449 loop:
450 - namespace: namespace1
451 name: name1
452 version: "1.0.0"
453 - namespace: namespace1
454 name: name1
455 version: "1.0.9"
456 - namespace: namespace2
457 name: name
458 version: "1.0.0"
459 - namespace: namespace7
460 name: name
461 version: "1.0.0"
462 - namespace: namespace9
463 name: name
464 version: "1.0.0"
465 vars:
466 version_url: '{{ galaxy_ng_server }}/v3/collections/{{ item.namespace }}/{{ item.name }}/versions/{{ item.version }}/'
467 version_data: "{{ lookup('url', version_url, username=galaxy_user, password=galaxy_password, force_basic_auth=true)|from_json }}"
468
469 - name: rewrite requirements file with collections and signatures
470 copy:
471 content: |
472 collections:
473 - name: namespace7.name
474 version: "1.0.0"
475 signatures:
476 - "{{ not_mine }}"
477 - "{{ also_not_mine }}"
478 - "file://{{ gpg_homedir }}/namespace7-name-1.0.0-MANIFEST.json.asc"
479 - namespace8.name
480 - name: namespace9.name
481 signatures:
482 - "file://{{ gpg_homedir }}/namespace9-name-1.0.0-MANIFEST.json.asc"
483 dest: '{{ galaxy_dir }}/ansible_collections/requirements.yaml'
484 vars:
485 not_mine: "file://{{ gpg_homedir }}/namespace1-name1-1.0.0-MANIFEST.json.asc"
486 also_not_mine: "file://{{ gpg_homedir }}/namespace1-name1-1.0.9-MANIFEST.json.asc"
487
488 - name: installing only roles does not fail if keyring for collections is not provided
489 command: ansible-galaxy role install -r {{ galaxy_dir }}/ansible_collections/requirements.yaml
490 register: roles_only
491
492 - assert:
493 that:
494 - roles_only is success
495
496 - name: installing only roles implicitly does not fail if keyring for collections is not provided
497 # if -p/--roles-path are specified, only roles are installed
498 command: ansible-galaxy install -r {{ galaxy_dir }}/ansible_collections/requirements.yaml }} -p {{ galaxy_dir }}
499 register: roles_only
500
501 - assert:
502 that:
503 - roles_only is success
504
505 - name: installing roles and collections requires keyring if collections have signatures
506 command: ansible-galaxy install -r {{ galaxy_dir }}/ansible_collections/requirements.yaml }}
507 ignore_errors: yes
508 register: collections_and_roles
509
510 - assert:
511 that:
512 - collections_and_roles is failed
513 - "'no keyring was configured' in collections_and_roles.stderr"
514
515 - name: install collection with mutually exclusive options
516 command: ansible-galaxy collection install -r {{ req_file }} -s {{ test_name }} {{ cli_signature }}
517 vars:
518 req_file: "{{ galaxy_dir }}/ansible_collections/requirements.yaml"
519 # --signature is an ansible-galaxy collection install subcommand, but mutually exclusive with -r
520 cli_signature: "--signature file://{{ gpg_homedir }}/namespace7-name-1.0.0-MANIFEST.json.asc"
521 ignore_errors: yes
522 register: mutually_exclusive_opts
523
524 - assert:
525 that:
526 - mutually_exclusive_opts is failed
527 - expected_error in actual_error
528 vars:
529 expected_error: >-
530 The --signatures option and --requirements-file are mutually exclusive.
531 Use the --signatures with positional collection_name args or provide a
532 'signatures' key for requirements in the --requirements-file.
533 actual_error: "{{ mutually_exclusive_opts.stderr }}"
534
535 - name: install a collection with user-supplied signatures for verification but no keyring
536 command: ansible-galaxy collection install namespace1.name1:1.0.0 {{ cli_signature }}
537 vars:
538 cli_signature: "--signature file://{{ gpg_homedir }}/namespace1-name1-1.0.0-MANIFEST.json.asc"
539 ignore_errors: yes
540 register: required_together
541
542 - assert:
543 that:
544 - required_together is failed
545 - required_together.stderr is contains("Signatures were provided to verify namespace1.name1 but no keyring was configured.")
546
547 - name: install collections with ansible-galaxy install -r with invalid signatures - {{ test_id }}
548 # Note that --keyring is a valid option for 'ansible-galaxy install -r ...', not just 'ansible-galaxy collection ...'
549 command: ansible-galaxy install -r {{ req_file }} -s {{ test_name }} --keyring {{ keyring }} {{ galaxy_verbosity }}
550 register: install_req
551 ignore_errors: yes
552 vars:
553 req_file: "{{ galaxy_dir }}/ansible_collections/requirements.yaml"
554 keyring: "{{ gpg_homedir }}/pubring.kbx"
555 environment:
556 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
557 ANSIBLE_GALAXY_REQUIRED_VALID_SIGNATURE_COUNT: all
558
559 - name: assert invalid signature is fatal with ansible-galaxy install - {{ test_id }}
560 assert:
561 that:
562 - install_req is failed
563 - '"Installing ''namespace7.name:1.0.0'' to" in install_req.stdout'
564 - '"Not installing namespace7.name because GnuPG signature verification failed" in install_req.stderr'
565 # The other collections shouldn't be installed because they're listed
566 # after the failing collection and --ignore-errors was not provided
567 - '"Installing ''namespace8.name:1.0.0'' to" not in install_req.stdout'
568 - '"Installing ''namespace9.name:1.0.0'' to" not in install_req.stdout'
569
570 # This command is hardcoded with -vvvv purposefully to evaluate extra verbosity messages
571 - name: install collections with ansible-galaxy install and --ignore-errors - {{ test_id }}
572 command: ansible-galaxy install -r {{ req_file }} {{ cli_opts }} -vvvv
573 register: install_req
574 vars:
575 req_file: "{{ galaxy_dir }}/ansible_collections/requirements.yaml"
576 cli_opts: "-s {{ test_name }} --keyring {{ keyring }} --ignore-errors"
577 keyring: "{{ gpg_homedir }}/pubring.kbx"
578 environment:
579 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
580 ANSIBLE_GALAXY_REQUIRED_VALID_SIGNATURE_COUNT: all
581 ANSIBLE_NOCOLOR: True
582 ANSIBLE_FORCE_COLOR: False
583
584 - name: get result of install collections with ansible-galaxy install - {{ test_id }}
585 slurp:
586 path: '{{ galaxy_dir }}/ansible_collections/{{ collection }}/name/MANIFEST.json'
587 register: install_req_actual
588 loop_control:
589 loop_var: collection
590 loop:
591 - namespace8
592 - namespace9
593
594 - name: assert invalid signature is not fatal with ansible-galaxy install --ignore-errors - {{ test_id }}
595 assert:
596 that:
597 - install_req is success
598 - '"Installing ''namespace7.name:1.0.0'' to" in install_req.stdout'
599 - '"Signature verification failed for ''namespace7.name'' (return code 1)" in install_req.stdout'
600 - '"Not installing namespace7.name because GnuPG signature verification failed." in install_stderr'
601 - '"Failed to install collection namespace7.name:1.0.0 but skipping due to --ignore-errors being set." in install_stderr'
602 - '"Installing ''namespace8.name:1.0.0'' to" in install_req.stdout'
603 - '"Installing ''namespace9.name:1.0.0'' to" in install_req.stdout'
604 - (install_req_actual.results[0].content | b64decode | from_json).collection_info.version == '1.0.0'
605 - (install_req_actual.results[1].content | b64decode | from_json).collection_info.version == '1.0.0'
606 vars:
607 install_stderr: "{{ install_req.stderr | regex_replace('\\n', ' ') }}"
608
609 - name: clean up collections from last test
610 file:
611 path: '{{ galaxy_dir }}/ansible_collections/{{ collection }}/name'
612 state: absent
613 loop_control:
614 loop_var: collection
615 loop:
616 - namespace8
617 - namespace9
618
619 - name: install collections with only one valid signature using ansible-galaxy install - {{ test_id }}
620 command: ansible-galaxy install -r {{ req_file }} {{ cli_opts }} {{ galaxy_verbosity }}
621 register: install_req
622 vars:
623 req_file: "{{ galaxy_dir }}/ansible_collections/requirements.yaml"
624 cli_opts: "-s {{ test_name }} --keyring {{ keyring }}"
625 keyring: "{{ gpg_homedir }}/pubring.kbx"
626 environment:
627 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
628 ANSIBLE_NOCOLOR: True
629 ANSIBLE_FORCE_COLOR: False
630
631 - name: get result of install collections with ansible-galaxy install - {{ test_id }}
632 slurp:
633 path: '{{ galaxy_dir }}/ansible_collections/{{ collection }}/name/MANIFEST.json'
634 register: install_req_actual
635 loop_control:
636 loop_var: collection
637 loop:
638 - namespace7
639 - namespace8
640 - namespace9
641
642 - name: assert just one valid signature is not fatal with ansible-galaxy install - {{ test_id }}
643 assert:
644 that:
645 - install_req is success
646 - '"Installing ''namespace7.name:1.0.0'' to" in install_req.stdout'
647 - '"Signature verification failed for ''namespace7.name'' (return code 1)" not in install_req.stdout'
648 - '"Not installing namespace7.name because GnuPG signature verification failed." not in install_stderr'
649 - '"Installing ''namespace8.name:1.0.0'' to" in install_req.stdout'
650 - '"Installing ''namespace9.name:1.0.0'' to" in install_req.stdout'
651 - (install_req_actual.results[0].content | b64decode | from_json).collection_info.version == '1.0.0'
652 - (install_req_actual.results[1].content | b64decode | from_json).collection_info.version == '1.0.0'
653 - (install_req_actual.results[2].content | b64decode | from_json).collection_info.version == '1.0.0'
654 vars:
655 install_stderr: "{{ install_req.stderr | regex_replace('\\n', ' ') }}"
656
657 - name: clean up collections from last test
658 file:
659 path: '{{ galaxy_dir }}/ansible_collections/{{ collection }}/name'
660 state: absent
661 loop_control:
662 loop_var: collection
663 loop:
664 - namespace7
665 - namespace8
666 - namespace9
667
668 # test --ignore-signature-status-code extends ANSIBLE_GALAXY_IGNORE_SIGNATURE_STATUS_CODES env var
669 - name: install collections with only one valid signature by ignoring the other errors
670 command: ansible-galaxy install -r {{ req_file }} {{ cli_opts }} {{ galaxy_verbosity }} --ignore-signature-status-code FAILURE
671 register: install_req
672 vars:
673 req_file: "{{ galaxy_dir }}/ansible_collections/requirements.yaml"
674 cli_opts: "-s {{ test_name }} --keyring {{ keyring }}"
675 keyring: "{{ gpg_homedir }}/pubring.kbx"
676 environment:
677 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
678 ANSIBLE_GALAXY_REQUIRED_VALID_SIGNATURE_COUNT: all
679 ANSIBLE_GALAXY_IGNORE_SIGNATURE_STATUS_CODES: BADSIG # cli option is appended and both status codes are ignored
680 ANSIBLE_NOCOLOR: True
681 ANSIBLE_FORCE_COLOR: False
682
683 - name: get result of install collections with ansible-galaxy install - {{ test_id }}
684 slurp:
685 path: '{{ galaxy_dir }}/ansible_collections/{{ collection }}/name/MANIFEST.json'
686 register: install_req_actual
687 loop_control:
688 loop_var: collection
689 loop:
690 - namespace7
691 - namespace8
692 - namespace9
693
694 - name: assert invalid signature is not fatal with ansible-galaxy install - {{ test_id }}
695 assert:
696 that:
697 - install_req is success
698 - '"Installing ''namespace7.name:1.0.0'' to" in install_req.stdout'
699 - '"Signature verification failed for ''namespace7.name'' (return code 1)" not in install_req.stdout'
700 - '"Not installing namespace7.name because GnuPG signature verification failed." not in install_stderr'
701 - '"Installing ''namespace8.name:1.0.0'' to" in install_req.stdout'
702 - '"Installing ''namespace9.name:1.0.0'' to" in install_req.stdout'
703 - (install_req_actual.results[0].content | b64decode | from_json).collection_info.version == '1.0.0'
704 - (install_req_actual.results[1].content | b64decode | from_json).collection_info.version == '1.0.0'
705 - (install_req_actual.results[2].content | b64decode | from_json).collection_info.version == '1.0.0'
706 vars:
707 install_stderr: "{{ install_req.stderr | regex_replace('\\n', ' ') }}"
708
709 # test --ignore-signature-status-code passed multiple times
710 - name: reinstall collections with only one valid signature by ignoring the other errors
711 command: ansible-galaxy install -r {{ req_file }} {{ cli_opts }} {{ galaxy_verbosity }} {{ ignore_errors }}
712 register: install_req
713 vars:
714 req_file: "{{ galaxy_dir }}/ansible_collections/requirements.yaml"
715 cli_opts: "-s {{ test_name }} --keyring {{ keyring }} --force"
716 keyring: "{{ gpg_homedir }}/pubring.kbx"
717 ignore_errors: "--ignore-signature-status-code BADSIG --ignore-signature-status-code FAILURE"
718 environment:
719 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
720 ANSIBLE_GALAXY_REQUIRED_VALID_SIGNATURE_COUNT: all
721 ANSIBLE_NOCOLOR: True
722 ANSIBLE_FORCE_COLOR: False
723
724 - name: assert invalid signature is not fatal with ansible-galaxy install - {{ test_name }}
725 assert:
726 that:
727 - install_req is success
728 - '"Installing ''namespace7.name:1.0.0'' to" in install_req.stdout'
729 - '"Signature verification failed for ''namespace7.name'' (return code 1)" not in install_req.stdout'
730 - '"Not installing namespace7.name because GnuPG signature verification failed." not in install_stderr'
731 - '"Installing ''namespace8.name:1.0.0'' to" in install_req.stdout'
732 - '"Installing ''namespace9.name:1.0.0'' to" in install_req.stdout'
733 vars:
734 install_stderr: "{{ install_req.stderr | regex_replace('\\n', ' ') }}"
735
736 # test --ignore-signature-status-code passed once with a list
737 - name: reinstall collections with only one valid signature by ignoring the other errors
738 command: ansible-galaxy install -r {{ req_file }} {{ cli_opts }} {{ galaxy_verbosity }} {{ ignore_errors }}
739 register: install_req
740 vars:
741 req_file: "{{ galaxy_dir }}/ansible_collections/requirements.yaml"
742 cli_opts: "-s {{ test_name }} --keyring {{ keyring }} --force"
743 keyring: "{{ gpg_homedir }}/pubring.kbx"
744 ignore_errors: "--ignore-signature-status-codes BADSIG FAILURE"
745 environment:
746 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
747 ANSIBLE_GALAXY_REQUIRED_VALID_SIGNATURE_COUNT: all
748 ANSIBLE_NOCOLOR: True
749 ANSIBLE_FORCE_COLOR: False
750
751 - name: assert invalid signature is not fatal with ansible-galaxy install - {{ test_name }}
752 assert:
753 that:
754 - install_req is success
755 - '"Installing ''namespace7.name:1.0.0'' to" in install_req.stdout'
756 - '"Signature verification failed for ''namespace7.name'' (return code 1)" not in install_req.stdout'
757 - '"Not installing namespace7.name because GnuPG signature verification failed." not in install_stderr'
758 - '"Installing ''namespace8.name:1.0.0'' to" in install_req.stdout'
759 - '"Installing ''namespace9.name:1.0.0'' to" in install_req.stdout'
760 vars:
761 install_stderr: "{{ install_req.stderr | regex_replace('\\n', ' ') }}"
762
763 - name: clean up collections from last test
764 file:
765 path: '{{ galaxy_dir }}/ansible_collections/{{ collection }}/name'
766 state: absent
767 loop_control:
768 loop_var: collection
769 loop:
770 - namespace7
771 - namespace8
772 - namespace9
773
774 - name: install cache.cache at the current latest version
775 command: ansible-galaxy collection install cache.cache -s '{{ test_name }}' -vvv
776 environment:
777 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
778
779 - set_fact:
780 cache_version_build: '{{ (cache_version_build | int) + 1 }}'
781
782 - name: copy cache collection to tmpdir
783 copy:
784 src: '{{ galaxy_dir }}/ansible_collections/cache/cache/'
785 dest: '{{ galaxy_dir }}/cache-src'
786 remote_src: true
787
788 - name: write galaxy.yml file
789 copy:
790 dest: '{{ galaxy_dir }}/cache-src/galaxy.yml'
791 content: |
792 {{ (lookup('file', manifest)|from_json).collection_info|to_nice_yaml }}
793 vars:
794 manifest: '{{ galaxy_dir }}/cache-src/MANIFEST.json'
795
796 - name: update cache.cache src version
797 replace:
798 path: '{{ galaxy_dir }}/cache-src/galaxy.yml'
799 regexp: '^version:.*$'
800 replace: 'version: 1.0.{{ cache_version_build }}'
801
802 - name: build updated cache.cache
803 command:
804 cmd: ansible-galaxy collection build
805 chdir: '{{ galaxy_dir }}/cache-src'
806 register: cache_cache_build
807
808 - name: publish updated cache.cache
809 command:
810 cmd: ansible-galaxy collection publish -s galaxy_ng "{{ cache_cache_build.stdout_lines|last|split|last }}"
811 chdir: '{{ galaxy_dir }}/cache-src'
812
813 - name: make sure the cache version list is ignored on a collection version change - {{ test_id }}
814 command: ansible-galaxy collection install cache.cache -s '{{ test_name }}' --force -vvv
815 register: install_cached_update
816 environment:
817 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
818
819 - name: get result of cache version list is ignored on a collection version change - {{ test_id }}
820 slurp:
821 path: '{{ galaxy_dir }}/ansible_collections/cache/cache/MANIFEST.json'
822 register: install_cached_update_actual
823
824 - name: assert cache version list is ignored on a collection version change - {{ test_id }}
825 assert:
826 that:
827 - '"Installing ''cache.cache:1.0." ~ cache_version_build ~ "'' to" in install_cached_update.stdout'
828 - (install_cached_update_actual.content | b64decode | from_json).collection_info.version == '1.0.' ~ cache_version_build
829
830 - name: install collection with symlink - {{ test_id }}
831 command: ansible-galaxy collection install symlink.symlink -s '{{ test_name }}' {{ galaxy_verbosity }}
832 environment:
833 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
834 register: install_symlink
835
836 - find:
837 paths: '{{ galaxy_dir }}/ansible_collections/symlink/symlink'
838 recurse: yes
839 file_type: any
840
841 - name: get result of install collection with symlink - {{ test_id }}
842 stat:
843 path: '{{ galaxy_dir }}/ansible_collections/symlink/symlink/{{ path }}'
844 register: install_symlink_actual
845 loop_control:
846 loop_var: path
847 loop:
848 - REÅDMÈ.md-link
849 - docs/REÅDMÈ.md
850 - plugins/REÅDMÈ.md
851 - REÅDMÈ.md-outside-link
852 - docs-link
853 - docs-link/REÅDMÈ.md
854
855 - name: assert install collection with symlink - {{ test_id }}
856 assert:
857 that:
858 - '"Installing ''symlink.symlink:1.0.0'' to" in install_symlink.stdout'
859 - install_symlink_actual.results[0].stat.islnk
860 - install_symlink_actual.results[0].stat.lnk_target == 'REÅDMÈ.md'
861 - install_symlink_actual.results[1].stat.islnk
862 - install_symlink_actual.results[1].stat.lnk_target == '../REÅDMÈ.md'
863 - install_symlink_actual.results[2].stat.islnk
864 - install_symlink_actual.results[2].stat.lnk_target == '../REÅDMÈ.md'
865 - install_symlink_actual.results[3].stat.isreg
866 - install_symlink_actual.results[4].stat.islnk
867 - install_symlink_actual.results[4].stat.lnk_target == 'docs'
868 - install_symlink_actual.results[5].stat.islnk
869 - install_symlink_actual.results[5].stat.lnk_target == '../REÅDMÈ.md'
870
871
872 # Testing an install from source to check that symlinks to directories
873 # are preserved (see issue https://github.com/ansible/ansible/issues/78442)
874 - name: symlink_dirs collection install from source test
875 block:
876
877 - name: create symlink_dirs collection
878 command: ansible-galaxy collection init symlink_dirs.symlink_dirs --init-path "{{ galaxy_dir }}/scratch"
879
880 - name: create directory in collection
881 file:
882 path: "{{ galaxy_dir }}/scratch/symlink_dirs/symlink_dirs/folderA"
883 state: directory
884
885 - name: create symlink to folderA
886 file:
887 dest: "{{ galaxy_dir }}/scratch/symlink_dirs/symlink_dirs/folderB"
888 src: ./folderA
889 state: link
890 force: yes
891
892 - name: install symlink_dirs collection from source
893 command: ansible-galaxy collection install {{ galaxy_dir }}/scratch/symlink_dirs/symlink_dirs/
894 environment:
895 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
896 register: install_symlink_dirs
897
898 - name: get result of install collection with symlink_dirs - {{ test_id }}
899 stat:
900 path: '{{ galaxy_dir }}/ansible_collections/symlink_dirs/symlink_dirs/{{ path }}'
901 register: install_symlink_dirs_actual
902 loop_control:
903 loop_var: path
904 loop:
905 - folderA
906 - folderB
907
908 - name: assert install collection with symlink_dirs - {{ test_id }}
909 assert:
910 that:
911 - '"Installing ''symlink_dirs.symlink_dirs:1.0.0'' to" in install_symlink_dirs.stdout'
912 - install_symlink_dirs_actual.results[0].stat.isdir
913 - install_symlink_dirs_actual.results[1].stat.islnk
914 - install_symlink_dirs_actual.results[1].stat.lnk_target == './folderA'
915 always:
916 - name: clean up symlink_dirs collection directory
917 file:
918 path: "{{ galaxy_dir }}/scratch/symlink_dirs"
919 state: absent
920
921 - name: remove install directory for the next test because parent_dep.parent_collection was installed - {{ test_id }}
922 file:
923 path: '{{ galaxy_dir }}/ansible_collections'
924 state: absent
925
926 - name: install collection and dep compatible with multiple requirements - {{ test_id }}
927 command: ansible-galaxy collection install parent_dep.parent_collection parent_dep2.parent_collection
928 environment:
929 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
930 register: install_req
931
932 - name: assert install collections with ansible-galaxy install - {{ test_id }}
933 assert:
934 that:
935 - '"Installing ''parent_dep.parent_collection:1.0.0'' to" in install_req.stdout'
936 - '"Installing ''parent_dep2.parent_collection:1.0.0'' to" in install_req.stdout'
937 - '"Installing ''child_dep.child_collection:0.5.0'' to" in install_req.stdout'
938
939 - name: install a collection to a directory that contains another collection with no metadata
940 block:
941
942 # Collections are usable in ansible without a galaxy.yml or MANIFEST.json
943 - name: create a collection directory
944 file:
945 state: directory
946 path: '{{ galaxy_dir }}/ansible_collections/unrelated_namespace/collection_without_metadata/plugins'
947
948 - name: install a collection to the same installation directory - {{ test_id }}
949 command: ansible-galaxy collection install namespace1.name1
950 environment:
951 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
952 register: install_req
953
954 - name: assert installed collections with ansible-galaxy install - {{ test_id }}
955 assert:
956 that:
957 - '"Installing ''namespace1.name1:1.0.9'' to" in install_req.stdout'
958
959 - name: remove test collection install directory - {{ test_id }}
960 file:
961 path: '{{ galaxy_dir }}/ansible_collections'
962 state: absent
963
964 # This command is hardcoded with -vvvv purposefully to evaluate extra verbosity messages
965 - name: install collection with signature with invalid keyring
966 command: ansible-galaxy collection install namespace1.name1 -vvvv {{ signature_option }} {{ keyring_option }}
967 environment:
968 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
969 ANSIBLE_NOCOLOR: True
970 ANSIBLE_FORCE_COLOR: False
971 vars:
972 signature_option: "--signature file://{{ gpg_homedir }}/namespace1-name1-1.0.9-MANIFEST.json.asc"
973 keyring_option: '--keyring {{ gpg_homedir }}/i_do_not_exist.kbx'
974 ignore_errors: yes
975 register: keyring_error
976
977 - assert:
978 that:
979 - keyring_error is failed
980 - expected_errors[0] in actual_error
981 - expected_errors[1] in actual_error
982 - expected_errors[2] in actual_error
983 - unexpected_warning not in actual_warning
984 vars:
985 keyring: "{{ gpg_homedir }}/i_do_not_exist.kbx"
986 expected_errors:
987 - "Signature verification failed for 'namespace1.name1' (return code 2):"
988 - "* The public key is not available."
989 - >-
990 * It was not possible to check the signature. This may be caused
991 by a missing public key or an unsupported algorithm. A RC of 4
992 indicates unknown algorithm, a 9 indicates a missing public key.
993 unexpected_warning: >-
994 The GnuPG keyring used for collection signature
995 verification was not configured but signatures were
996 provided by the Galaxy server to verify authenticity.
997 Configure a keyring for ansible-galaxy to use
998 or disable signature verification.
999 Skipping signature verification.
1000 actual_warning: "{{ keyring_error.stderr | regex_replace('\\n', ' ') }}"
1001 # Remove formatting from the reason so it's one line
1002 actual_error: "{{ keyring_error.stdout | regex_replace('\"') | regex_replace('\\n') | regex_replace(' ', ' ') }}"
1003
1004 # TODO: Uncomment once signatures are provided by pulp-galaxy-ng
1005 #- name: install collection with signature provided by Galaxy server (no keyring)
1006 # command: ansible-galaxy collection install namespace1.name1 {{ galaxy_verbosity }}
1007 # environment:
1008 # ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
1009 # ANSIBLE_NOCOLOR: True
1010 # ANSIBLE_FORCE_COLOR: False
1011 # ignore_errors: yes
1012 # register: keyring_warning
1013 #
1014 #- name: assert a warning was given but signature verification did not occur without configuring the keyring
1015 # assert:
1016 # that:
1017 # - keyring_warning is not failed
1018 # - - '"Installing ''namespace1.name1:1.0.9'' to" in keyring_warning.stdout'
1019 # # TODO: Don't just check the stdout, make sure the collection was installed.
1020 # - expected_warning in actual_warning
1021 # vars:
1022 # expected_warning: >-
1023 # The GnuPG keyring used for collection signature
1024 # verification was not configured but signatures were
1025 # provided by the Galaxy server to verify authenticity.
1026 # Configure a keyring for ansible-galaxy to use
1027 # or disable signature verification.
1028 # Skipping signature verification.
1029 # actual_warning: "{{ keyring_warning.stderr | regex_replace('\\n', ' ') }}"
1030
1031 - name: install simple collection from first accessible server with valid detached signature
1032 command: ansible-galaxy collection install namespace1.name1 {{ galaxy_verbosity }} {{ signature_options }}
1033 environment:
1034 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
1035 vars:
1036 signature_options: "--signature {{ signature }} --keyring {{ keyring }}"
1037 signature: "file://{{ gpg_homedir }}/namespace1-name1-1.0.9-MANIFEST.json.asc"
1038 keyring: "{{ gpg_homedir }}/pubring.kbx"
1039 register: from_first_good_server
1040
1041 - name: get installed files of install simple collection from first good server
1042 find:
1043 path: '{{ galaxy_dir }}/ansible_collections/namespace1/name1'
1044 file_type: file
1045 register: install_normal_files
1046
1047 - name: get the manifest of install simple collection from first good server
1048 slurp:
1049 path: '{{ galaxy_dir }}/ansible_collections/namespace1/name1/MANIFEST.json'
1050 register: install_normal_manifest
1051
1052 - name: assert install simple collection from first good server
1053 assert:
1054 that:
1055 - '"Installing ''namespace1.name1:1.0.9'' to" in from_first_good_server.stdout'
1056 - install_normal_files.files | length == 3
1057 - install_normal_files.files[0].path | basename in ['MANIFEST.json', 'FILES.json', 'README.md']
1058 - install_normal_files.files[1].path | basename in ['MANIFEST.json', 'FILES.json', 'README.md']
1059 - install_normal_files.files[2].path | basename in ['MANIFEST.json', 'FILES.json', 'README.md']
1060 - (install_normal_manifest.content | b64decode | from_json).collection_info.version == '1.0.9'
1061
1062 - name: Remove the collection
1063 file:
1064 path: '{{ galaxy_dir }}/ansible_collections/namespace1'
1065 state: absent
1066
1067 # This command is hardcoded with -vvvv purposefully to evaluate extra verbosity messages
1068 - name: install simple collection with invalid detached signature
1069 command: ansible-galaxy collection install namespace1.name1 -vvvv {{ signature_options }}
1070 environment:
1071 ANSIBLE_GALAXY_REQUIRED_VALID_SIGNATURE_COUNT: "all"
1072 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
1073 ANSIBLE_NOCOLOR: True
1074 ANSIBLE_FORCE_COLOR: False
1075 vars:
1076 signature_options: "--signature {{ signature }} --keyring {{ keyring }}"
1077 signature: "file://{{ gpg_homedir }}/namespace2-name-1.0.0-MANIFEST.json.asc"
1078 keyring: "{{ gpg_homedir }}/pubring.kbx"
1079 ignore_errors: yes
1080 register: invalid_signature
1081
1082 - assert:
1083 that:
1084 - invalid_signature is failed
1085 - "'Not installing namespace1.name1 because GnuPG signature verification failed.' in invalid_signature.stderr"
1086 - expected_errors[0] in install_stdout
1087 - expected_errors[1] in install_stdout
1088 vars:
1089 expected_errors:
1090 - "* This is the counterpart to SUCCESS and used to indicate a program failure."
1091 - "* The signature with the keyid has not been verified okay."
1092 # Remove formatting from the reason so it's one line
1093 install_stdout: "{{ invalid_signature.stdout | regex_replace('\"') | regex_replace('\\n') | regex_replace(' ', ' ') }}"
1094
1095 - name: validate collection directory was not created
1096 file:
1097 path: '{{ galaxy_dir }}/ansible_collections/namespace1/name1'
1098 state: absent
1099 register: collection_dir
1100 check_mode: yes
1101 failed_when: collection_dir is changed
1102
1103 - name: disable signature verification and install simple collection with invalid detached signature
1104 command: ansible-galaxy collection install namespace1.name1 {{ galaxy_verbosity }} {{ signature_options }}
1105 environment:
1106 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
1107 vars:
1108 signature_options: "--signature {{ signature }} --keyring {{ keyring }} --disable-gpg-verify"
1109 signature: "file://{{ gpg_homedir }}/namespace2-name-1.0.0-MANIFEST.json.asc"
1110 keyring: "{{ gpg_homedir }}/pubring.kbx"
1111 ignore_errors: yes
1112 register: ignore_invalid_signature
1113
1114 - assert:
1115 that:
1116 - ignore_invalid_signature is success
1117 - '"Installing ''namespace1.name1:1.0.9'' to" in ignore_invalid_signature.stdout'
1118
1119 - name: use lenient signature verification (default) without providing signatures
1120 command: ansible-galaxy collection install namespace1.name1:1.0.0 -vvvv --keyring {{ gpg_homedir }}/pubring.kbx --force
1121 environment:
1122 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
1123 ANSIBLE_GALAXY_REQUIRED_VALID_SIGNATURE_COUNT: "all"
1124 register: missing_signature
1125
1126 - assert:
1127 that:
1128 - missing_signature is success
1129 - missing_signature.rc == 0
1130 - '"namespace1.name1:1.0.0 was installed successfully" in missing_signature.stdout'
1131 - '"Signature verification failed for ''namespace1.name1'': no successful signatures" not in missing_signature.stdout'
1132
1133 # These steps use secondary (amanda) as it has no signatures provided
1134 - name: use strict signature verification without providing signatures
1135 command: ansible-galaxy collection install -s secondary namespace1.name1:1.0.0 -vvvv --keyring {{ gpg_homedir }}/pubring.kbx --force
1136 environment:
1137 ANSIBLE_GALAXY_REQUIRED_VALID_SIGNATURE_COUNT: "+1"
1138 ignore_errors: yes
1139 register: missing_signature
1140
1141 - assert:
1142 that:
1143 - missing_signature is failed
1144 - missing_signature.rc == 1
1145 - '"Signature verification failed for ''namespace1.name1'': no successful signatures" in missing_signature.stdout'
1146 - '"Not installing namespace1.name1 because GnuPG signature verification failed" in missing_signature.stderr'
1147
1148 - name: Remove the collection
1149 file:
1150 path: '{{ galaxy_dir }}/ansible_collections/namespace1'
1151 state: absent
1152
1153 - name: download collections with pre-release dep - {{ test_id }}
1154 command: ansible-galaxy collection download dep_with_beta.parent namespace1.name1:1.1.0-beta.1 -p '{{ galaxy_dir }}/scratch'
1155
1156 - name: install collection with concrete pre-release dep - {{ test_id }}
1157 command: ansible-galaxy collection install -r '{{ galaxy_dir }}/scratch/requirements.yml'
1158 args:
1159 chdir: '{{ galaxy_dir }}/scratch'
1160 environment:
1161 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
1162 register: install_concrete_pre
1163
1164 - name: get result of install collections with concrete pre-release dep - {{ test_id }}
1165 slurp:
1166 path: '{{ galaxy_dir }}/ansible_collections/{{ collection }}/MANIFEST.json'
1167 register: install_concrete_pre_actual
1168 loop_control:
1169 loop_var: collection
1170 loop:
1171 - namespace1/name1
1172 - dep_with_beta/parent
1173
1174 - name: assert install collections with ansible-galaxy install - {{ test_id }}
1175 assert:
1176 that:
1177 - '"Installing ''namespace1.name1:1.1.0-beta.1'' to" in install_concrete_pre.stdout'
1178 - '"Installing ''dep_with_beta.parent:1.0.0'' to" in install_concrete_pre.stdout'
1179 - (install_concrete_pre_actual.results[0].content | b64decode | from_json).collection_info.version == '1.1.0-beta.1'
1180 - (install_concrete_pre_actual.results[1].content | b64decode | from_json).collection_info.version == '1.0.0'
1181
1182 - block:
1183 - name: create skeleton collection for trailing slash test
1184 command: ansible-galaxy collection init trailing_dir.name --init-path "{{ galaxy_dir }}/scratch"
1185
1186 - name: install collection with directory source and trailing slash - {{ test_id }}
1187 command: ansible-galaxy collection install '{{ galaxy_dir }}/scratch/trailing_dir/name/' {{ galaxy_verbosity }}
1188 environment:
1189 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
1190 register: install_dir_slash
1191
1192 - name: get result of install collections with with trailing slash - {{ test_id }}
1193 slurp:
1194 path: '{{ galaxy_dir }}/ansible_collections/trailing_dir/name/MANIFEST.json'
1195 register: install_dir_slash_actual
1196
1197 - name: assert install collections with with trailing slash - {{ test_id }}
1198 assert:
1199 that:
1200 - '"Installing ''trailing_dir.name:1.0.0'' to" in install_dir_slash.stdout'
1201 - (install_dir_slash_actual.content | b64decode | from_json).collection_info.version == '1.0.0'
1202
1203 always:
1204 - name: remove trailing dir skeleton
1205 file:
1206 path: '{{ galaxy_dir }}/scratch/trailing_dir'
1207 state: absent
1208
1209 - name: test collection FQCN mismatch warning
1210 block:
1211 - name: create test collection install directory for FQCN mismatch test
1212 file:
1213 path: '{{ galaxy_dir }}/ansible_collections'
1214 state: directory
1215
1216 - name: Install a collection for FQCN mismatch test
1217 command: ansible-galaxy collection install namespace1.name1
1218 environment:
1219 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
1220
1221 - name: Create wrong namespace directory
1222 file:
1223 path: '{{ galaxy_dir }}/ansible_collections/wrongnamespace'
1224 state: directory
1225
1226 - name: Move the installed collection to a mismatched path
1227 command: mv {{ galaxy_dir }}/ansible_collections/namespace1/name1 {{ galaxy_dir }}/ansible_collections/wrongnamespace/wrongname
1228
1229 - name: Re-install the same collection to trigger path scanning
1230 command: ansible-galaxy collection install namespace1.name1
1231 environment:
1232 ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
1233 register: second_install
1234
1235 - name: Assert second install succeeded and warning was displayed
1236 assert:
1237 that:
1238 - second_install is success
1239 - expected_warning in second_install.stderr
1240 - correct_name in second_install.stdout
1241 - incorrect_name not in second_install.stdout
1242 vars:
1243 mismatched_path: "{{ galaxy_dir }}/ansible_collections/wrongnamespace/wrongname"
1244 expected_warning: "Collection at {{ mismatched_path }} documents incorrect FQCN 'namespace1.name1'"
1245 correct_name: 'namespace1.name1'
1246 incorrect_name: 'wrongnamespace.wrongname'
1247
1248 - name: Stat for collection paths
1249 stat:
1250 path: "{{ item }}"
1251 loop:
1252 - '{{ galaxy_dir }}/ansible_collections/namespace1/name1'
1253 - '{{ galaxy_dir }}/ansible_collections/wrongnamespace/wrongname'
1254 register: collection_paths
1255
1256 - name: Assert both correct and incorrect collection directories exist
1257 assert:
1258 that:
1259 - collection_paths.results[0].stat.exists and collection_paths.results[0].stat.isdir
1260 - collection_paths.results[1].stat.exists and collection_paths.results[1].stat.isdir
1261
1262
1263 - name: remove collection dir after round of testing - {{ test_id }}
1264 file:
1265 path: '{{ galaxy_dir }}/ansible_collections'
1266 state: absent