Debian Codegraph @

ansible_collections/community/general/tests/integration/targets/pkgng/tasks/freebsd.yml

raw
1 ---
2 # Copyright (c) Ansible Project
3 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
4 # SPDX-License-Identifier: GPL-3.0-or-later
5
6 ##
7 ## pkgng - prepare test environment
8 ##
9 - name: Remove test package
10 pkgng:
11 name: '{{ pkgng_test_pkg_name }}'
12 state: absent
13
14 ##
15 ## pkgng - example - state=present for single package
16 ##
17 - name: 'state=present for single package'
18 include_tasks: install_single_package.yml
19
20 ##
21 ## pkgng - example - state=latest for already up-to-date package
22 ##
23 - name: Upgrade package (idempotent)
24 pkgng:
25 name: '{{ pkgng_test_pkg_name }}'
26 state: latest
27 register: pkgng_example2
28
29 - name: Ensure pkgng does not upgrade up-to-date package
30 assert:
31 that:
32 - not pkgng_example2.changed
33
34 ##
35 ## pkgng - example - state=absent for single package
36 ##
37 - name: Verify package sentinel file is present
38 stat:
39 path: '{{ pkgng_test_pkg_sentinelfile_path }}'
40 get_attributes: false
41 get_checksum: false
42 get_mime: false
43 register: pkgng_example3_stat_before
44
45 - name: Install package (checkmode)
46 pkgng:
47 name: '{{ pkgng_test_pkg_name }}'
48 check_mode: true
49 register: pkgng_example3_checkmode
50
51 - name: Remove package
52 pkgng:
53 name: '{{ pkgng_test_pkg_name }}'
54 state: absent
55 register: pkgng_example3
56
57 - name: Remove package (idempotent)
58 pkgng:
59 name: '{{ pkgng_test_pkg_name }}'
60 state: absent
61 register: pkgng_example3_idempotent
62
63 - name: Verify package sentinel file is not present
64 stat:
65 path: '{{ pkgng_test_pkg_sentinelfile_path }}'
66 get_attributes: false
67 get_checksum: false
68 get_mime: false
69 register: pkgng_example3_stat_after
70
71 - name: Ensure pkgng installs package correctly
72 assert:
73 that:
74 - pkgng_example3_stat_before.stat.exists
75 - pkgng_example3_stat_before.stat.executable
76 - not pkgng_example3_checkmode.changed
77 - pkgng_example3.changed
78 - not pkgng_example3_idempotent.changed
79 - not pkgng_example3_stat_after.stat.exists
80
81 ##
82 ## pkgng - example - state=latest for out-of-date package
83 ##
84 - name: Install intentionally out-of-date package and upgrade it
85 #
86 # NOTE: The out-of-date package provided is a minimal,
87 # no-contents test package that declares {{ pkgng_test_pkg_name }} with
88 # a version of 0, so it should always be upgraded.
89 #
90 # This test might fail at some point in the
91 # future if the FreeBSD package format receives
92 # breaking changes that prevent pkg from installing
93 # older package formats.
94 #
95 block:
96 - name: Create out-of-date test package
97 import_tasks: create-outofdate-pkg.yml
98
99 - name: Install out-of-date test package
100 command: 'pkg add {{ pkgng_test_outofdate_pkg_path }}'
101 register: pkgng_example4_prepare
102
103 - name: Check for any available package upgrades (checkmode)
104 pkgng:
105 name: '*'
106 state: latest
107 check_mode: true
108 register: pkgng_example4_wildcard_checkmode
109
110 - name: Check for available package upgrade (checkmode)
111 pkgng:
112 name: '{{ pkgng_test_pkg_name }}'
113 state: latest
114 check_mode: true
115 register: pkgng_example4_checkmode
116
117 - name: Upgrade out-of-date package
118 pkgng:
119 name: '{{ pkgng_test_pkg_name }}'
120 state: latest
121 register: pkgng_example4
122
123 - name: Upgrade out-of-date package (idempotent)
124 pkgng:
125 name: '{{ pkgng_test_pkg_name }}'
126 state: latest
127 register: pkgng_example4_idempotent
128
129 - name: Remove test out-of-date package
130 pkgng:
131 name: '{{ pkgng_test_pkg_name }}'
132 state: absent
133
134 - name: Ensure pkgng upgrades package correctly
135 assert:
136 that:
137 - not pkgng_example4_prepare.failed
138 - pkgng_example4_wildcard_checkmode.changed
139 - pkgng_example4_checkmode.changed
140 - pkgng_example4.changed
141 - not pkgng_example4_idempotent.changed
142
143 ##
144 ## pkgng - example - state=latest for out-of-date package without privileges
145 ##
146 - name: Install intentionally out-of-date package and try to upgrade it with unprivileged user
147 block:
148 - ansible.builtin.user:
149 name: powerless
150 shell: /bin/bash
151
152 - name: Create out-of-date test package
153 import_tasks: create-outofdate-pkg.yml
154
155 - name: Install out-of-date test package
156 command: 'pkg add {{ pkgng_test_outofdate_pkg_path }}'
157 register: pkgng_example4_nopower_prepare
158
159 - name: Check for any available package upgrades with unprivileged user
160 become: true
161 become_user: powerless
162 pkgng:
163 name: '*'
164 state: latest
165 register: pkgng_example4_nopower_wildcard
166 ignore_errors: true
167
168 - name: Remove test out-of-date package
169 pkgng:
170 name: '{{ pkgng_test_pkg_name }}'
171 state: absent
172
173 - name: Ensure pkgng upgrades package correctly
174 assert:
175 that:
176 - not pkgng_example4_nopower_prepare.failed
177 - pkgng_example4_nopower_wildcard.failed
178
179 ##
180 ## pkgng - example - Install multiple packages in one command
181 ##
182 - name: Remove test package (checkmode)
183 pkgng:
184 name: '{{ pkgng_test_pkg_name }}'
185 state: absent
186 check_mode: true
187 register: pkgng_example5_prepare
188
189 - name: Install three packages
190 pkgng:
191 name:
192 - '{{ pkgng_test_pkg_name }}'
193 - fish
194 - busybox
195 register: pkgng_example5
196
197 - name: Remove three packages
198 pkgng:
199 name:
200 - '{{ pkgng_test_pkg_name }}'
201 - fish
202 - busybox
203 state: absent
204 register: pkgng_example5_cleanup
205
206 - name: Ensure pkgng installs multiple packages with one command
207 assert:
208 that:
209 - not pkgng_example5_prepare.changed
210 - pkgng_example5.changed
211 - '(pkgng_example5.stdout | regex_search("^Number of packages to be installed: (\d+)", "\\1", multiline=True) | first | int) >= 3'
212 - '(pkgng_example5.stdout | regex_findall("^Number of packages to be", multiline=True) | count) == 1'
213 - pkgng_example5_cleanup.changed
214
215 ##
216 ## pkgng - example - state=latest multiple packages, some already installed
217 ##
218 - name: Remove test package (checkmode)
219 pkgng:
220 name: '{{ pkgng_test_pkg_name }}'
221 state: absent
222 check_mode: true
223 register: pkgng_example6_check
224
225 - name: Create out-of-date test package
226 import_tasks: create-outofdate-pkg.yml
227
228 - name: Install out-of-date test package
229 command: 'pkg add {{ pkgng_test_outofdate_pkg_path }}'
230 register: pkgng_example6_prepare
231
232 - name: Upgrade and/or install two packages
233 pkgng:
234 name:
235 - '{{ pkgng_test_pkg_name }}'
236 - fish
237 state: latest
238 register: pkgng_example6
239
240 - name: Remove two packages
241 pkgng:
242 name:
243 - '{{ pkgng_test_pkg_name }}'
244 - fish
245 state: absent
246 register: pkgng_example6_cleanup
247
248 - name: Ensure pkgng installs multiple packages with one command
249 assert:
250 that:
251 - not pkgng_example6_check.changed
252 - not pkgng_example6_prepare.failed
253 - pkgng_example6.changed
254 - '(pkgng_example6.stdout | regex_search("^Number of packages to be installed: (\d+)", "\\1", multiline=True) | first | int) >= 1'
255 - '(pkgng_example6.stdout | regex_search("^Number of packages to be upgraded: (\d+)", "\\1", multiline=True) | first | int) >= 1'
256 # Checking that "will be affected" occurs twice in the output ensures
257 # that the module runs two separate commands for install and upgrade,
258 # as the pkg command only outputs the string once per invocation.
259 - '(pkgng_example6.stdout | regex_findall("will be affected", multiline=True) | count) == 2'
260 - pkgng_example6_cleanup.changed
261
262 ##
263 ## pkgng - example - autoremove=yes
264 ##
265 - name: "Test autoremove=yes"
266 #
267 # NOTE: FreeBSD 12.0 test runner receives a "connection reset by peer" after ~20% downloaded so we are
268 # only running this on 12.1 or higher
269 #
270 when: ansible_facts.distribution_version is version('12.01', '>=')
271 block:
272 - name: Install GNU autotools
273 pkgng:
274 name: autotools
275 state: latest
276 register: pkgng_example7_prepare_install
277
278 - name: Remove GNU autotools and run pkg autoremove
279 pkgng:
280 name: autotools
281 state: absent
282 autoremove: true
283 register: pkgng_example7
284
285 - name: Check if autoremove uninstalled known autotools dependencies
286 pkgng:
287 name:
288 - autoconf
289 - automake
290 - libtool
291 state: absent
292 check_mode: true
293 register: pkgng_example7_cleanup
294
295 - name: Ensure pkgng autoremove works correctly
296 assert:
297 that:
298 - pkgng_example7_prepare_install is changed
299 - "'autoremoved' is in(pkgng_example7.msg)"
300 - pkgng_example7_cleanup is not changed
301
302 ##
303 ## pkgng - example - single annotations
304 ##
305 - name: Install and annotate single package
306 pkgng:
307 name: '{{ pkgng_test_pkg_name }}'
308 annotation: '+ansibletest_example8=added'
309 register: pkgng_example8_add_annotation
310
311 - name: Should fail to add duplicate annotation
312 pkgng:
313 name: '{{ pkgng_test_pkg_name }}'
314 annotation: '+ansibletest_example8=duplicate'
315 ignore_errors: true
316 register: pkgng_example8_add_annotation_failure
317
318 - name: Verify annotation is actually there
319 command: 'pkg annotate -q -S {{ pkgng_test_pkg_name }} ansibletest_example8'
320 register: pkgng_example8_add_annotation_verify
321
322 - name: Install and annotate single package (checkmode, not changed)
323 pkgng:
324 name: '{{ pkgng_test_pkg_name }}'
325 annotation: '+ansibletest_example8=added'
326 check_mode: true
327 register: pkgng_example8_add_annotation_checkmode_nochange
328
329 - name: Install and annotate single package (checkmode, changed)
330 pkgng:
331 name: '{{ pkgng_test_pkg_name }}'
332 annotation: '+ansibletest_example8_checkmode=added'
333 check_mode: true
334 register: pkgng_example8_add_annotation_checkmode_change
335
336 - name: Verify check_mode did not add an annotation
337 command: 'pkg annotate -q -S {{ pkgng_test_pkg_name }} ansibletest_example8_checkmode'
338 register: pkgng_example8_add_annotation_checkmode_change_verify
339
340 - name: Modify annotation on single package
341 pkgng:
342 name: '{{ pkgng_test_pkg_name }}'
343 annotation: ':ansibletest_example8=modified'
344 register: pkgng_example8_modify_annotation
345
346 - name: Should fail to modify missing annotation
347 pkgng:
348 name: '{{ pkgng_test_pkg_name }}'
349 annotation: ':ansiblemissing=modified'
350 ignore_errors: true
351 register: pkgng_example8_modify_annotation_failure
352
353 - name: Verify annotation has been modified
354 command: 'pkg annotate -q -S {{ pkgng_test_pkg_name }} ansibletest_example8'
355 register: pkgng_example8_modify_annotation_verify
356
357 - name: Remove annotation on single package
358 pkgng:
359 name: '{{ pkgng_test_pkg_name }}'
360 annotation: '-ansibletest_example8'
361 register: pkgng_example8_remove_annotation
362
363 - name: Verify annotation has been removed
364 command: 'pkg annotate -q -S {{ pkgng_test_pkg_name }} ansibletest_example8'
365 register: pkgng_example8_remove_annotation_verify
366
367 - name: Ensure pkgng annotations on single packages work correctly
368 assert:
369 that:
370 - pkgng_example8_add_annotation.changed
371 - pkgng_example8_add_annotation_failure.failed
372 - pkgng_example8_add_annotation_checkmode_nochange is not changed
373 - pkgng_example8_add_annotation_checkmode_change is changed
374 - 'pkgng_example8_add_annotation_checkmode_change_verify.stdout_lines | count == 0'
375 - 'pkgng_example8_add_annotation_verify.stdout_lines | first == "added"'
376 - pkgng_example8_modify_annotation.changed
377 - pkgng_example8_modify_annotation_failure.failed
378 - 'pkgng_example8_modify_annotation_verify.stdout_lines | first == "modified"'
379 - pkgng_example8_remove_annotation.changed
380 - 'pkgng_example8_remove_annotation_verify.stdout_lines | count == 0'
381
382 ##
383 ## pkgng - example - multiple annotations
384 ##
385 - name: Annotate single package with multiple annotations
386 pkgng:
387 name: '{{ pkgng_test_pkg_name }}'
388 annotation:
389 - '+ansibletest_example9_1=added'
390 - '+ansibletest_example9_2=added'
391 register: pkgng_example9_add_annotation
392
393 - name: Verify annotation is actually there
394 command: 'pkg info -q -A {{ pkgng_test_pkg_name }}'
395 register: pkgng_example9_add_annotation_verify
396 # Assert, below, tests that stdout includes:
397 # ```
398 # ansibletest_example9_1 : added
399 # ansibletest_example9_2 : added
400 # ```
401
402 - name: Multiple annotation operations on single package
403 pkgng:
404 name: '{{ pkgng_test_pkg_name }}'
405 annotation:
406 - ':ansibletest_example9_1=modified'
407 - '+ansibletest_example9_3=added'
408 register: pkgng_example9_multiple_annotation
409
410 - name: Verify multiple operations succeeded
411 command: 'pkg info -q -A {{ pkgng_test_pkg_name }}'
412 register: pkgng_example9_multiple_annotation_verify
413 # Assert, below, tests that stdout includes:
414 # ```
415 # ansibletest_example9_1 : modified
416 # ansibletest_example9_2 : added
417 # ansibletest_example9_3 : added
418 # ```
419
420 - name: Add multiple annotations with old syntax
421 pkgng:
422 name: '{{ pkgng_test_pkg_name }}'
423 annotation: '+ansibletest_example9_4=added,+ansibletest_example9_5=added'
424 register: pkgng_example9_add_annotation_old
425
426 - name: Verify annotation is actually there
427 command: 'pkg info -q -A {{ pkgng_test_pkg_name }}'
428 register: pkgng_example9_add_annotation_old_verify
429 # Assert, below, tests that stdout includes:
430 # ```
431 # ansibletest_example9_4 : added
432 # ansibletest_example9_5 : added
433 # ```
434
435 - name: Ensure multiple annotations work correctly
436 assert:
437 that:
438 - pkgng_example9_add_annotation.changed
439 - '(pkgng_example9_add_annotation_verify.stdout_lines | select("match", "ansibletest_example9_[12]\s*:\s*added") | list | count) == 2'
440 - pkgng_example9_multiple_annotation.changed
441 - '(pkgng_example9_multiple_annotation_verify.stdout_lines | select("match", "ansibletest_example9_1\s*:\s*modified") | list | count) == 1'
442 - '(pkgng_example9_multiple_annotation_verify.stdout_lines | select("match", "ansibletest_example9_[23]\s*:\s*added") | list | count) == 2'
443 - pkgng_example9_add_annotation_old.changed
444 - '(pkgng_example9_add_annotation_old_verify.stdout_lines | select("match", "ansibletest_example9_[45]\s*:\s*added") | list | count) == 2'
445
446 ##
447 ## pkgng - example - invalid annotation strings
448 ##
449 - name: Should fail on invalid annotate strings
450 pkgng:
451 name: '{{ pkgng_test_pkg_name }}'
452 annotation: '{{ item }}'
453 ignore_errors: true
454 register: pkgng_example8_invalid_annotation_failure
455 loop:
456 - 'naked_string'
457 - '/invalid_operation'
458 - ',empty_first_tag=validsecond'
459 - '=notag'
460
461 - name: Verify invalid annotate strings did not add annotations
462 command: 'pkg info -q -A {{ pkgng_test_pkg_name }}'
463 register: pkgng_example8_invalid_annotation_verify
464
465 - name: Ensure invalid annotate strings fail safely
466 assert:
467 that:
468 # Invalid strings should not change anything
469 - '(pkgng_example8_invalid_annotation_failure.results | selectattr("changed") | list | count) == 0'
470 # Invalid strings should always fail
471 - '(pkgng_example8_invalid_annotation_failure.results | rejectattr("failed") | list | count) == 0'
472 # Invalid strings should not cause a module crash
473 - '(pkgng_example8_invalid_annotation_failure.results | selectattr("module_stdout", "defined") | list | count) == 0'
474 # Invalid strings should have a proper msg field
475 - '(pkgng_example8_invalid_annotation_failure.results | selectattr("msg", "match", "failed to annotate zsh, invalid annotate string: .*") | list | count) == 4'
476 # Verify annotations are unaffected
477 - '(pkgng_example8_invalid_annotation_verify.stdout_lines | select("search", "(naked_string|invalid_operation|empty_first_tag|validsecond|notag)") | list | count) == 0'
478
479 ##
480 ## pkgng - example - pkgsite=...
481 ##
482 # NOTE: testing for failure here to not have to set up our own
483 # or depend on a third-party, alternate package repo
484 - name: Should fail with invalid pkgsite
485 pkgng:
486 name: '{{ pkgng_test_pkg_name }}'
487 pkgsite: DoesNotExist
488 ignore_errors: true
489 register: pkgng_example10_invalid_pkgsite_failure
490
491 - name: Ensure invalid pkgsite fails as expected
492 assert:
493 that:
494 - pkgng_example10_invalid_pkgsite_failure.failed
495 - 'pkgng_example10_invalid_pkgsite_failure.stdout is search("^No repositories are enabled.", multiline=True)'
496
497 ##
498 ## pkgng - example - Install single package in jail
499 ##
500 - name: Test within jail
501 #
502 # NOTE: FreeBSD 12.0 test runner receives a "connection reset by peer" after ~20% downloaded so we are
503 # only running this on 12.1 or higher
504 #
505 # NOTE: FreeBSD 12.3 fails with some kernel mismatch for packages
506 # (someone with FreeBSD knowledge has to take a look)
507 #
508 # NOTE: FreeBSD 12.4 fails to update repositories because it cannot load certificates from /usr/share/keys/pkg/trusted
509 # (someone with FreeBSD knowledge has to take a look)
510 #
511 # NOTE: FreeBSD 13.0 fails to update the package catalogue for unknown reasons (someone with FreeBSD
512 # knowledge has to take a look)
513 #
514 # NOTE: FreeBSD 13.1 fails to update the package catalogue for unknown reasons (someone with FreeBSD
515 # knowledge has to take a look)
516 #
517 # NOTE: FreeBSD 13.2 fails to update the package catalogue for unknown reasons (someone with FreeBSD
518 # knowledge has to take a look)
519 #
520 # NOTE: FreeBSD 13.3 fails to update the package catalogue for unknown reasons (someone with FreeBSD
521 # knowledge has to take a look)
522 #
523 # NOTE: FreeBSD 13.4 fails to update the package catalogue for unknown reasons (someone with FreeBSD
524 # knowledge has to take a look)
525 #
526 # NOTE: FreeBSD 13.5 fails to update the package catalogue for unknown reasons (someone with FreeBSD
527 # knowledge has to take a look)
528 #
529 # NOTE: FreeBSD 14.0 fails to update the package catalogue for unknown reasons (someone with FreeBSD
530 # knowledge has to take a look)
531 #
532 # NOTE: FreeBSD 14.1 fails to update the package catalogue for unknown reasons (someone with FreeBSD
533 # knowledge has to take a look)
534 #
535 # NOTE: FreeBSD 14.2 fails as well (someone with FreeBSD knowledge has to take a look)
536 #
537 # NOTE: FreeBSD 14.3 fails as well (someone with FreeBSD knowledge has to take a look)
538 #
539 # See also
540 # https://github.com/ansible-collections/community.general/issues/5795
541 when: >-
542 (ansible_facts.distribution_version is version('12.01', '>=') and ansible_facts.distribution_version is version('12.3', '<'))
543 or (ansible_facts.distribution_version is version('13.6', '>=') and ansible_facts.distribution_version is version('14.0', '<'))
544 or ansible_facts.distribution_version is version('14.4', '>=')
545 block:
546 - name: Setup testjail
547 include_tasks: setup-testjail.yml
548
549 - name: Install package in jail as rootdir
550 include_tasks: install_single_package.yml
551 vars:
552 pkgng_test_rootdir: /usr/jails/testjail
553 pkgng_test_install_prefix: /usr/jails/testjail
554 pkgng_test_install_cleanup: true
555
556 - name: Install package in jail
557 include_tasks: install_single_package.yml
558 vars:
559 pkgng_test_jail: testjail
560 pkgng_test_install_prefix: /usr/jails/testjail
561 pkgng_test_install_cleanup: true
562
563 - name: Install package in jail as chroot
564 include_tasks: install_single_package.yml
565 vars:
566 pkgng_test_chroot: /usr/jails/testjail
567 pkgng_test_install_prefix: /usr/jails/testjail
568 pkgng_test_install_cleanup: true
569 always:
570 - name: Stop and remove testjail
571 failed_when: false
572 changed_when: false
573 command: "ezjail-admin delete -wf testjail"