summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/unarchive/tasks/prepare_tests.yml
blob: 98a8ba1118b8c5875836fa7feac5e98979fde5ea (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
- name: Include system specific variables
  include_vars: "{{ ansible_facts.system }}.yml"

# Need unzip for unarchive module, and zip for archive creation.
- name: Ensure required binaries are present
  package:
    name: "{{ unarchive_packages }}"
  when: ansible_pkg_mgr in ('yum', 'dnf', 'apt', 'pkgng')

- name: prep our file
  copy:
    src: foo.txt
    dest: "{{remote_tmp_dir}}/foo-unarchive.txt"
    mode: preserve

- name: prep a tar file
  shell: tar cvf test-unarchive.tar foo-unarchive.txt chdir={{remote_tmp_dir}}

- name: prep a tar.gz file
  shell: tar czvf test-unarchive.tar.gz foo-unarchive.txt chdir={{remote_tmp_dir}}

- name: see if we have the zstd executable
  ignore_errors: true
  shell: zstd --version
  register: zstd_available

- when: zstd_available.rc == 0
  block:
    - name: find gnu tar
      shell: |
        #!/bin/sh
        which gtar 2>/dev/null
        if test $? -ne 0; then
            if test -z "`tar --version | grep bsdtar`"; then
               which tar
            fi
        fi
      register: gnu_tar

    - name: prep a tar.zst file
      shell: "{{ gnu_tar.stdout }} --use-compress-program=zstd -cvf test-unarchive.tar.zst foo-unarchive.txt chdir={{remote_tmp_dir}}"
      when: gnu_tar.stdout != ""

- name: prep a chmodded file for zip
  copy:
    src: foo.txt
    dest: '{{remote_tmp_dir}}/foo-unarchive-777.txt'
    mode: '0777'

- name: prep a windows permission file for our zip
  copy:
    src: foo.txt
    dest: '{{remote_tmp_dir}}/FOO-UNAR.TXT'
    mode: preserve

# This gets around an unzip timestamp bug in some distributions
# Recent unzip on Ubuntu and BSD will randomly round some timestamps up.
# But that doesn't seem to happen when the timestamp has an even second.
- name: Bug work around
  command: touch -t "201705111530.00" {{remote_tmp_dir}}/foo-unarchive.txt {{remote_tmp_dir}}/foo-unarchive-777.txt {{remote_tmp_dir}}/FOO-UNAR.TXT
# See Ubuntu bug 1691636: https://bugs.launchpad.net/ubuntu/+source/unzip/+bug/1691636
# When these are fixed, this code should be removed.

- name: prep a zip file
  shell: zip test-unarchive.zip foo-unarchive.txt foo-unarchive-777.txt chdir={{remote_tmp_dir}}

- name: Prepare - Create test dirs
  file:
    path: "{{remote_tmp_dir}}/{{item}}"
    state: directory
  with_items:
    - created/include
    - created/exclude
    - created/other

- name: Prepare - Create test files
  file:
    path: "{{remote_tmp_dir}}/created/{{item}}"
    state: touch
  with_items:
    - include/include-1.txt
    - include/include-2.txt
    - include/include-3.txt
    - exclude/exclude-1.txt
    - exclude/exclude-2.txt
    - exclude/exclude-3.txt
    - other/include-1.ext
    - other/include-2.ext
    - other/exclude-1.ext
    - other/exclude-2.ext
    - other/other-1.ext
    - other/other-2.ext

- name: Prepare - zip file
  shell: zip -r {{remote_tmp_dir}}/unarchive-00.zip * chdir={{remote_tmp_dir}}/created/

- name: Prepare - tar file
  shell: tar czvf {{remote_tmp_dir}}/unarchive-00.tar * chdir={{remote_tmp_dir}}/created/

- name: add a file with Windows permissions to zip file
  shell: zip -k test-unarchive.zip FOO-UNAR.TXT chdir={{remote_tmp_dir}}

- name: prep a subdirectory
  file:
    path: '{{remote_tmp_dir}}/unarchive-dir'
    state: directory

- name: prep our file
  copy:
    src: foo.txt
    dest: '{{remote_tmp_dir}}/unarchive-dir/foo-unarchive.txt'
    mode: preserve

- name: prep a tar.gz file with directory
  shell: tar czvf test-unarchive-dir.tar.gz unarchive-dir chdir={{remote_tmp_dir}}