Debian Codegraph @

test/integration/targets/unarchive/tasks/test_missing_binaries.yml

raw
1 - name: Test missing binaries
2 when: ansible_pkg_mgr in ('dnf', 'apt', 'pkgng')
3 block:
4 - name: Remove zip binaries
5 package:
6 state: absent
7 name:
8 - zip
9 - unzip
10 notify: restore packages
11
12 - name: create unarchive destinations
13 file:
14 path: '{{ remote_tmp_dir }}/test-unarchive-{{ item }}'
15 state: directory
16 loop:
17 - zip
18 - tar
19
20 # With the zip binaries absent and tar still present, this task should work
21 - name: unarchive a tar file
22 unarchive:
23 src: '{{remote_tmp_dir}}/test-unarchive.tar'
24 dest: '{{remote_tmp_dir}}/test-unarchive-tar'
25 remote_src: yes
26 register: tar
27
28 - name: unarchive a zip file
29 unarchive:
30 src: '{{remote_tmp_dir}}/test-unarchive.zip'
31 dest: '{{remote_tmp_dir}}/test-unarchive-zip'
32 list_files: True
33 remote_src: yes
34 register: zip_fail
35 ignore_errors: yes
36 # FreeBSD does not have zipinfo, but does have a bootstrapped unzip in /usr/bin
37 # which alone is sufficient to run unarchive.
38 # Exclude /usr/bin from the PATH to test having no binary available.
39 environment:
40 PATH: "{{ ENV_PATH }}"
41 vars:
42 ENV_PATH: "{{ ansible_env['PATH']| regex_replace(re, '') }}"
43 re: '[^A-Za-z](\/usr\/bin:?)'
44
45 - name: Ensure tasks worked as expected
46 assert:
47 that:
48 - tar is success
49 - zip_fail is failed
50 - zip_fail.msg is search('Unable to find required')
51
52 - name: unarchive a zip file using unzip without zipinfo
53 unarchive:
54 src: '{{remote_tmp_dir}}/test-unarchive.zip'
55 dest: '{{remote_tmp_dir}}/test-unarchive-zip'
56 list_files: True
57 remote_src: yes
58 register: zip_success
59 # FreeBSD does not have zipinfo, but does have a bootstrapped unzip in /usr/bin
60 # which alone is sufficient to run unarchive.
61 when: ansible_pkg_mgr == 'pkgng'
62
63 - assert:
64 that:
65 - zip_success is success
66 - zip_success.changed
67 # Verify that file list is generated
68 - "'files' in zip_success"
69 - zip_success['files'] | length == 3
70 - "'foo-unarchive.txt' in zip_success['files']"
71 - "'foo-unarchive-777.txt' in zip_success['files']"
72 - "'FOO-UNAR.TXT' in zip_success['files']"
73 when: ansible_pkg_mgr == 'pkgng'
74
75 - name: Remove unarchive destinations
76 file:
77 path: '{{ remote_tmp_dir }}/test-unarchive-{{ item }}'
78 state: absent
79 loop:
80 - zip
81 - tar
82
83 - name: Reinstall zip binaries
84 package:
85 name:
86 - zip
87 - unzip