Debian Codegraph @

test/integration/targets/apt/tasks/apt.yml

raw
1 # UNINSTALL 'python3-apt'
2 # The `apt` module has the smarts to auto-install `python3-apt`. To test, we
3 # will first uninstall `python3-apt`.
4 - name: uninstall python3-apt with apt
5 apt:
6 pkg: python3-apt
7 state: absent
8 purge: yes
9 register: apt_result
10
11 # In check mode, auto-install of `python3-apt` must fail
12 - name: test fail uninstall hello without required apt deps in check mode
13 apt:
14 pkg: hello
15 state: absent
16 purge: yes
17 register: apt_result
18 check_mode: yes
19 ignore_errors: yes
20
21 - name: verify fail uninstall hello without required apt deps in check mode
22 assert:
23 that:
24 - apt_result is failed
25 - '"If run normally this module can auto-install it" in apt_result.msg'
26
27 - name: check with dpkg
28 shell: dpkg -s python3-apt
29 register: dpkg_result
30 ignore_errors: true
31
32 - name: Test the auto_install_module_deps option
33 apt:
34 pkg: hello
35 auto_install_module_deps: false
36 register: r
37 ignore_errors: true
38
39 - assert:
40 that:
41 - r is failed
42 - r.msg is contains("Could not import the python3-apt module")
43
44 # UNINSTALL 'hello'
45 # With 'python-apt' uninstalled, the first call to 'apt' should install
46 # python-apt without updating the cache.
47 - name: uninstall hello with apt and prevent updating the cache
48 apt:
49 pkg: hello
50 state: absent
51 purge: yes
52 update_cache: no
53 register: apt_result
54
55 - name: check hello with dpkg
56 shell: dpkg-query -l hello
57 failed_when: False
58 register: dpkg_result
59
60 - name: verify uninstall hello with apt and prevent updating the cache
61 assert:
62 that:
63 - "'changed' in apt_result"
64 - apt_result is not changed
65 - "dpkg_result.rc == 1"
66
67 - name: Test installing fnmatch package
68 apt:
69 name:
70 - hel?o
71 - he?lo
72 register: apt_install_fnmatch
73
74 - name: Test uninstalling fnmatch package
75 apt:
76 name:
77 - hel?o
78 - he?lo
79 state: absent
80 register: apt_uninstall_fnmatch
81
82 - name: verify fnmatch
83 assert:
84 that:
85 - apt_install_fnmatch is changed
86 - apt_uninstall_fnmatch is changed
87
88 - name: Test update_cache 1 (check mode)
89 apt:
90 update_cache: true
91 cache_valid_time: 10
92 register: apt_update_cache_1_check_mode
93 check_mode: true
94
95 - name: Test update_cache 1
96 apt:
97 update_cache: true
98 cache_valid_time: 10
99 register: apt_update_cache_1
100
101 - name: Test update_cache 2 (check mode)
102 apt:
103 update_cache: true
104 cache_valid_time: 10
105 register: apt_update_cache_2_check_mode
106 check_mode: true
107
108 - name: Test update_cache 2
109 apt:
110 update_cache: true
111 cache_valid_time: 10
112 register: apt_update_cache_2
113
114 - name: verify update_cache
115 assert:
116 that:
117 - apt_update_cache_1_check_mode is changed
118 - apt_update_cache_1 is changed
119 - apt_update_cache_2_check_mode is not changed
120 - apt_update_cache_2 is not changed
121
122 - name: uninstall apt bindings with apt again
123 apt:
124 pkg: [python-apt, python3-apt]
125 state: absent
126 purge: yes
127
128 # UNINSTALL 'hello'
129 # With 'python-apt' uninstalled, the first call to 'apt' should install
130 # python-apt.
131 - name: uninstall hello with apt
132 apt: pkg=hello state=absent purge=yes
133 register: apt_result
134 until: apt_result is success
135
136 - name: check hello with dpkg
137 shell: dpkg-query -l hello
138 failed_when: False
139 register: dpkg_result
140
141 - name: verify uninstallation of hello
142 assert:
143 that:
144 - "'changed' in apt_result"
145 - apt_result is not changed
146 - "dpkg_result.rc == 1"
147
148 # UNINSTALL AGAIN
149 - name: uninstall hello with apt
150 apt: pkg=hello state=absent purge=yes
151 register: apt_result
152
153 - name: verify no change on re-uninstall
154 assert:
155 that:
156 - "not apt_result.changed"
157
158 # INSTALL
159 - name: install hello with apt
160 apt: name=hello state=present
161 register: apt_result
162
163 - name: check hello with dpkg
164 shell: dpkg-query -l hello
165 failed_when: False
166 register: dpkg_result
167
168 - name: verify installation of hello
169 assert:
170 that:
171 - "apt_result.changed"
172 - "dpkg_result.rc == 0"
173
174 - name: verify apt module outputs
175 assert:
176 that:
177 - "'changed' in apt_result"
178 - "'stderr' in apt_result"
179 - "'stdout' in apt_result"
180 - "'stdout_lines' in apt_result"
181
182 # INSTALL AGAIN
183 - name: install hello with apt
184 apt: name=hello state=present
185 register: apt_result
186
187 - name: verify no change on re-install
188 assert:
189 that:
190 - "not apt_result.changed"
191
192 # UNINSTALL AGAIN
193 - name: uninstall hello with apt
194 apt: pkg=hello state=absent purge=yes
195 register: apt_result
196
197 # INSTALL WITH VERSION WILDCARD
198 - name: install hello with apt
199 apt: name=hello=2.* state=present
200 register: apt_result
201
202 - name: check hello with wildcard with dpkg
203 shell: dpkg-query -l hello
204 failed_when: False
205 register: dpkg_result
206
207 - name: verify installation of hello
208 assert:
209 that:
210 - "apt_result.changed"
211 - "dpkg_result.rc == 0"
212
213 - name: check hello version
214 shell: dpkg -s hello | grep Version | awk '{print $2}'
215 register: hello_version
216
217 - name: check hello architecture
218 shell: dpkg -s hello | grep Architecture | awk '{print $2}'
219 register: hello_architecture
220
221 - name: uninstall hello with apt
222 apt: pkg=hello state=absent purge=yes
223
224 ### Get the most recent version string of the hello package
225 ### (It will be used in the subsequent tests)
226 - name: Search the apt cache for the hello package
227 shell: apt-cache policy hello | grep Candidate | awk '{print $2}'
228 register: apt_cache_result
229
230 - name: Store the latest hello package version string
231 set_fact:
232 hello_version_current: "{{ apt_cache_result.stdout_lines[0] }}"
233
234 ### Install an exact package version with =
235 - name: Install an exact version of the hello package
236 apt:
237 name: "hello={{ hello_version_current }}"
238 state: present
239 register: apt_result
240
241 - name: Check hello version install with dpkg
242 shell: dpkg-query -l hello
243 failed_when: no
244 register: dpkg_result
245
246 - name: Verify installation of hello
247 assert:
248 that:
249 - "apt_result.changed"
250 - "dpkg_result.rc == 0"
251
252 - name: Check hello version
253 shell: dpkg -s hello | grep Version | awk '{print $2}'
254 register: hello_version_installed
255
256 - name: Check that the latest version was installed
257 assert:
258 that:
259 - hello_version_installed.stdout_lines[0] == hello_version_current
260
261 - name: Uninstall hello with apt
262 apt:
263 name: hello
264 state: absent
265 purge: yes
266
267 ### Installing an unavailable package version with = must fail
268 - name: Try to install an unavailable version of the hello package
269 apt:
270 name: "hello=10"
271 state: present
272 register: apt_result
273 ignore_errors: true
274
275 - name: Check hello version install with dpkg
276 shell: dpkg-query -l hello
277 failed_when: no
278 register: dpkg_result
279
280 - name: Verify installation of hello
281 assert:
282 that:
283 - apt_result is failed
284 - "not apt_result.changed"
285 - "dpkg_result.rc != 0"
286
287 ### Install the latest package version with >=
288 - name: Install the most recent version of a package with the >= operator
289 apt:
290 name: "hello>={{ hello_version_current }}"
291 state: present
292 register: apt_result
293
294 - name: Check hello version install with dpkg
295 shell: dpkg-query -l hello
296 failed_when: no
297 register: dpkg_result
298
299 - name: Verify installation of hello
300 assert:
301 that:
302 - "apt_result.changed"
303 - "dpkg_result.rc == 0"
304
305 - name: Check hello version
306 shell: dpkg -s hello | grep Version | awk '{print $2}'
307 register: hello_version_installed
308
309 - name: Check that the latest version was installed
310 assert:
311 that:
312 - hello_version_installed.stdout_lines[0] == hello_version_current
313
314 - name: Uninstall hello with apt
315 apt:
316 name: hello
317 state: absent
318 purge: yes
319
320 ### Install a more recent package version with >=
321 - name: Install some version of a package with the >= operator
322 apt:
323 name: "hello>=1"
324 state: present
325 register: apt_result
326
327 - name: Check hello version install with dpkg
328 shell: dpkg-query -l hello
329 failed_when: no
330 register: dpkg_result
331
332 - name: Verify installation of hello
333 assert:
334 that:
335 - "apt_result.changed"
336 - "dpkg_result.rc == 0"
337
338 - name: Uninstall hello with apt
339 apt:
340 name: hello
341 state: absent
342 purge: yes
343
344 ### Installing an unavailable package version with >= must fail
345 - name: Try to install an unavailable package version with the >= operator
346 apt:
347 name: "hello>=10"
348 state: present
349 register: apt_result
350 ignore_errors: true
351
352 - name: Check hello version install with dpkg
353 shell: dpkg-query -l hello
354 failed_when: no
355 register: dpkg_result
356
357 - name: Verify installation of hello
358 assert:
359 that:
360 - apt_result is failed
361 - "not apt_result.changed"
362 - "dpkg_result.rc != 0"
363
364 # INSTALL WITHOUT REMOVALS
365 - name: Install hello, that conflicts with hello-traditional
366 apt:
367 pkg: hello
368 state: present
369 update_cache: no
370
371 - name: check hello
372 shell: dpkg-query -l hello
373 register: dpkg_result
374
375 - name: verify installation of hello
376 assert:
377 that:
378 - "dpkg_result.rc == 0"
379
380 - name: Try installing hello-traditional, that conflicts with hello
381 apt:
382 pkg: hello-traditional
383 state: present
384 fail_on_autoremove: yes
385 ignore_errors: yes
386 register: apt_result
387
388 - name: hello-traditional was removed in newer versions, but we can build if needed.
389 include_tasks: hello-traditional.yml
390 when:
391 - apt_result is failed
392 - '"No package matching" in apt_result.msg'
393
394 - name: verify failure of installing hello-traditional, because it is required to remove hello to install.
395 assert:
396 that:
397 - apt_result is failed
398 - '"Packages need to be removed but remove is disabled." in apt_result.msg or "Conflicts with the installed package" in apt_result.msg'
399
400 - name: uninstall hello with apt
401 apt:
402 pkg: hello
403 state: absent
404 purge: yes
405 update_cache: no
406
407 - name: install deb file
408 apt: deb="/var/cache/apt/archives/hello_{{ hello_version.stdout }}_{{ hello_architecture.stdout }}.deb"
409 register: apt_initial
410
411 - name: install deb file again
412 apt: deb="/var/cache/apt/archives/hello_{{ hello_version.stdout }}_{{ hello_architecture.stdout }}.deb"
413 register: apt_secondary
414
415 - name: verify installation of hello
416 assert:
417 that:
418 - "apt_initial.changed"
419 - "not apt_secondary.changed"
420
421 - name: uninstall hello with apt
422 apt: pkg=hello state=absent purge=yes
423
424 - name: install deb file from URL
425 apt: "deb=https://ci-files.testing.ansible.com/test/integration/targets/apt/hello_{{ hello_old_version }}_{{ hello_architecture.stdout }}.deb"
426 register: apt_url
427
428 - name: verify installation of hello
429 assert:
430 that:
431 - "apt_url.changed"
432
433 - name: uninstall hello with apt
434 apt: pkg=hello state=absent purge=yes
435
436 - name: force install of deb
437 apt: deb="/var/cache/apt/archives/hello_{{ hello_version.stdout }}_{{ hello_architecture.stdout }}.deb" force=true
438 register: dpkg_force
439
440 - name: verify installation of hello
441 assert:
442 that:
443 - "dpkg_force.changed"
444
445 # NEGATIVE: upgrade all packages while providing additional packages to install
446 - name: provide additional packages to install while upgrading all installed packages
447 apt: pkg=*,test state=latest
448 ignore_errors: True
449 register: apt_result
450
451 - name: verify failure of upgrade packages and install
452 assert:
453 that:
454 - "not apt_result.changed"
455 - "apt_result.failed"
456
457 - name: autoclean during install
458 apt: pkg=hello state=present autoclean=yes
459
460 - name: undo previous install
461 apt: pkg=hello state=absent
462
463 # https://github.com/ansible/ansible/issues/23155
464 - name: create a repo file
465 copy:
466 dest: /etc/apt/sources.list.d/non-existing.list
467 content: deb http://ppa.launchpad.net/non-existing trusty main
468
469 - name: test for logical error message
470 apt:
471 update_cache: yes
472 register: apt_result
473 ignore_errors: yes
474
475 - name: verify logical error message
476 assert:
477 that:
478 - "'Failed to update apt cache' in apt_result['msg']"
479 - "'403' in apt_result['msg']"
480
481 - name: Clean up
482 file:
483 name: /etc/apt/sources.list.d/non-existing.list
484 state: absent
485
486 # https://github.com/ansible/ansible/issues/28907
487 - name: Install parent package
488 apt:
489 name: libcaca-dev
490
491 - name: Install child package
492 apt:
493 name: libslang2-dev
494
495 - shell: apt-mark showmanual | grep libcaca-dev
496 ignore_errors: yes
497 register: parent_output
498
499 - name: Check that parent package is marked as installed manually
500 assert:
501 that:
502 - "'libcaca-dev' in parent_output.stdout"
503
504 - shell: apt-mark showmanual | grep libslang2-dev
505 ignore_errors: yes
506 register: child_output
507
508 - name: Check that child package is marked as installed manually
509 assert:
510 that:
511 - "'libslang2-dev' in child_output.stdout"
512
513 - name: Clean up
514 apt:
515 name: "{{ pkgs }}"
516 state: absent
517 vars:
518 pkgs:
519 - libcaca-dev
520 - libslang2-dev
521
522 # # https://github.com/ansible/ansible/issues/38995
523 - name: Make sure that at least one build dependency is missing
524 apt:
525 name: build-essential
526 state: absent
527
528 - name: build-dep for a package
529 apt:
530 name: tree
531 state: build-dep
532 register: apt_result
533
534 - name: Check the result
535 assert:
536 that:
537 - apt_result is changed
538
539 - name: build-dep for a package (idempotency)
540 apt:
541 name: tree
542 state: build-dep
543 register: apt_result
544
545 - name: Check the result
546 assert:
547 that:
548 - apt_result is not changed
549
550 # check policy_rc_d parameter
551
552 - name: Install unscd but forbid service start
553 apt:
554 name: unscd
555 policy_rc_d: 101
556
557 - name: Stop unscd service
558 service:
559 name: unscd
560 state: stopped
561 register: service_unscd_stop
562
563 - name: unscd service shouldn't have been stopped by previous task
564 assert:
565 that: service_unscd_stop is not changed
566
567 - name: Uninstall unscd
568 apt:
569 name: unscd
570 policy_rc_d: 101
571
572 - name: Create incorrect /usr/sbin/policy-rc.d
573 copy:
574 dest: /usr/sbin/policy-rc.d
575 content: apt integration test
576 mode: 0755
577
578 - name: Install unscd but forbid service start
579 apt:
580 name: unscd
581 policy_rc_d: 101
582
583 - name: Stop unscd service
584 service:
585 name: unscd
586 state: stopped
587 register: service_unscd_stop
588
589 - name: unscd service shouldn't have been stopped by previous task
590 assert:
591 that: service_unscd_stop is not changed
592
593 - name: Create incorrect /usr/sbin/policy-rc.d
594 copy:
595 dest: /usr/sbin/policy-rc.d
596 content: apt integration test
597 mode: 0755
598 register: policy_rc_d
599
600 - name: Check if /usr/sbin/policy-rc.d was correctly backed-up during unscd install
601 assert:
602 that: policy_rc_d is not changed
603
604 - name: Delete /usr/sbin/policy-rc.d
605 file:
606 path: /usr/sbin/policy-rc.d
607 state: absent
608
609 # https://github.com/ansible/ansible/issues/65325
610 - name: Download and install old version of hello (to test allow_change_held_packages option)
611 apt: "deb=https://ci-files.testing.ansible.com/test/integration/targets/apt/hello_{{ hello_old_version }}_{{ hello_architecture.stdout }}.deb"
612 notify:
613 - remove package hello
614
615 - name: Put hello on hold
616 shell: apt-mark hold hello
617
618 - name: Get hold list
619 shell: apt-mark showhold
620 register: allow_change_held_packages_hold
621
622 - name: Check that the package hello is on the hold list
623 assert:
624 that:
625 - "'hello' in allow_change_held_packages_hold.stdout"
626
627 - name: Try updating package to the latest version (allow_change_held_packages=no)
628 apt:
629 name: hello
630 state: latest
631 ignore_errors: True
632 register: allow_change_held_packages_failed_update
633
634 - name: Get the version of the package
635 shell: dpkg -s hello | grep Version | awk '{print $2}'
636 register: allow_change_held_packages_hello_version
637
638 - name: Verify that the package was not updated (apt returns with an error)
639 assert:
640 that:
641 - "allow_change_held_packages_failed_update is failed"
642 - "'--allow-change-held-packages' in allow_change_held_packages_failed_update.stderr"
643 - "allow_change_held_packages_hello_version.stdout == hello_old_version"
644
645 - name: Try updating package to the latest version (allow_change_held_packages=yes)
646 apt:
647 name: hello
648 state: latest
649 allow_change_held_packages: yes
650 register: allow_change_held_packages_successful_update
651
652 - name: Get the version of the package
653 shell: dpkg -s hello | grep Version | awk '{print $2}'
654 register: allow_change_held_packages_hello_version
655
656 - name: Verify that the package was updated
657 assert:
658 that:
659 - "allow_change_held_packages_successful_update is changed"
660 - "allow_change_held_packages_hello_version.stdout != hello_old_version"
661
662 - name: Try updating package to the latest version again
663 apt:
664 name: hello
665 state: latest
666 allow_change_held_packages: yes
667 register: allow_change_held_packages_no_update
668
669 - name: Get the version of the package
670 shell: dpkg -s hello | grep Version | awk '{print $2}'
671 register: allow_change_held_packages_hello_version_again
672
673 - name: Verify that the package was not updated
674 assert:
675 that:
676 - "allow_change_held_packages_no_update is not changed"
677 - "allow_change_held_packages_hello_version.stdout == allow_change_held_packages_hello_version_again.stdout"
678
679 # Remove pkg on hold
680 - name: Put hello on hold
681 shell: apt-mark hold hello
682
683 - name: Get hold list
684 shell: apt-mark showhold
685 register: hello_hold
686
687 - name: Check that the package hello is on the hold list
688 assert:
689 that:
690 - "'hello' in hello_hold.stdout"
691
692 - name: Try removing package hello
693 apt:
694 name: hello
695 state: absent
696 register: package_removed
697 ignore_errors: true
698
699 - name: verify the package is not removed with dpkg
700 shell: dpkg -l hello
701 register: dpkg_result
702
703 - name: Verify that package was not removed
704 assert:
705 that:
706 - package_removed is failed
707 - dpkg_result is success
708
709 - name: Try removing package (allow_change_held_packages=yes)
710 apt:
711 name: hello
712 state: absent
713 allow_change_held_packages: yes
714 register: package_removed
715
716 - name: verify the package is removed with dpkg
717 shell: dpkg -l hello
718 register: dpkg_result
719 ignore_errors: true
720
721 - name: Verify that package removal was successful
722 assert:
723 that:
724 - package_removed is success
725 - dpkg_result is failed
726 - package_removed.changed
727
728 # Virtual package
729 - name: Install a virtual package
730 apt:
731 package:
732 - emacs-nox
733 - yaml-mode # <- the virtual package
734 state: latest
735 register: install_virtual_package_result
736
737 - name: Check the virtual package install result
738 assert:
739 that:
740 - install_virtual_package_result is changed
741
742 - name: Clean up virtual-package install
743 apt:
744 package:
745 - emacs-nox
746 - elpa-yaml-mode
747 state: absent
748 purge: yes
749
750 # https://github.com/ansible/ansible/issues/82611
751 - name: clean apt cache
752 apt:
753 clean: true
754
755 - name: check for /var/cache/apt/pkgcache.bin
756 stat:
757 path: /var/cache/apt/pkgcache.bin
758 register: pkgcache_bin
759
760 - name: check for /var/cache/apt/srcpkgcache.bin
761 stat:
762 path: /var/cache/apt/srcpkgcache.bin
763 register: srcpkgcache_bin
764
765 - name: verify apt cache files are cleaned
766 assert:
767 that:
768 - not pkgcache_bin.stat.exists
769 - not srcpkgcache_bin.stat.exists
770 fail_msg: "apt cache files still exist."
771 success_msg: "apt cache files are cleaned."