ansible/test/integration/targets/unarchive/tasks/prepare_tests.yml
Sijis Aviles 034e9b0252
unarchive - add include option (#40522)
This should allow users to extract specific files from an archive as
desired.

Fixes #16130, #27081.

* Rebase and make a few minor changes
* Add changelog
* Improve tests

- move to separate tasks file
- change assertions to check for exactly one file
- use remote_tmp_dir for output dir

* Make exclude and include mutually exclusive
* Don't remove files needed by other tasks
* Fix sanity tests
* Improve feature documentation
* Skip tests that use map() on CentOS 6
* Use fnmatch on include for zip archives
  This matches the behavior of exclude

Co-authored-by: Sam Doran <sdoran@redhat.com>
2020-12-07 12:49:41 -05:00

92 lines
2.7 KiB
YAML

# Need unzip for unarchive module, and zip for archive creation.
- name: Ensure zip & unzip are present
package:
name:
- zip
- unzip
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: 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}}