summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/unarchive/tasks/test_missing_binaries.yml
blob: 58d38f4f91e79efbef2a70918af68789f20dd790 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
- name: Test missing binaries
  when: ansible_pkg_mgr in ('yum', 'dnf', 'apt', 'pkgng')
  block:
    - name: Remove zip binaries
      package:
        state: absent
        name:
          - zip
          - unzip
      notify: restore packages

    - name: create unarchive destinations
      file:
        path: '{{ remote_tmp_dir }}/test-unarchive-{{ item }}'
        state: directory
      loop:
        - zip
        - tar

    # With the zip binaries absent and tar still present, this task should work
    - name: unarchive a tar file
      unarchive:
        src: '{{remote_tmp_dir}}/test-unarchive.tar'
        dest: '{{remote_tmp_dir}}/test-unarchive-tar'
        remote_src: yes
      register: tar

    - name: unarchive a zip file
      unarchive:
        src: '{{remote_tmp_dir}}/test-unarchive.zip'
        dest: '{{remote_tmp_dir}}/test-unarchive-zip'
        list_files: True
        remote_src: yes
      register: zip_fail
      ignore_errors: yes
      # FreeBSD does not have zipinfo, but does have a bootstrapped unzip in /usr/bin
      # which alone is sufficient to run unarchive.
      # Exclude /usr/bin from the PATH to test having no binary available.
      environment:
        PATH: "{{ ENV_PATH }}"
      vars:
        ENV_PATH: "{{ lookup('env', 'PATH') | regex_replace(re, '') }}"
        re: "[^A-Za-z](\/usr\/bin:?)"

    - name: Ensure tasks worked as expected
      assert:
        that:
          - tar is success
          - zip_fail is failed
          - zip_fail.msg is search('Unable to find required')

    - name: unarchive a zip file using unzip without zipinfo
      unarchive:
        src: '{{remote_tmp_dir}}/test-unarchive.zip'
        dest: '{{remote_tmp_dir}}/test-unarchive-zip'
        list_files: True
        remote_src: yes
      register: zip_success
      # FreeBSD does not have zipinfo, but does have a bootstrapped unzip in /usr/bin
      # which alone is sufficient to run unarchive.
      when: ansible_pkg_mgr == 'pkgng'

    - assert:
        that:
          - zip_success is success
          - zip_success.changed
          # Verify that file list is generated
          - "'files' in zip_success"
          - "{{zip_success['files']| length}} == 3"
          - "'foo-unarchive.txt' in zip_success['files']"
          - "'foo-unarchive-777.txt' in zip_success['files']"
          - "'FOO-UNAR.TXT' in zip_success['files']"
      when: ansible_pkg_mgr == 'pkgng'

    - name: Remove unarchive destinations
      file:
        path: '{{ remote_tmp_dir }}/test-unarchive-{{ item }}'
        state: absent
      loop:
        - zip
        - tar

    - name: Reinsntall zip binaries
      package:
        name:
          - zip
          - unzip