ansible/test/integration/targets/unarchive/tasks/test_exclude.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

39 lines
1,013 B
YAML

- name: "Create {{ remote_tmp_dir }}/exclude directory"
file:
state: directory
path: "{{ remote_tmp_dir }}/exclude-{{item}}"
with_items:
- zip
- tar
- name: Unpack archive file excluding regular and glob files.
unarchive:
src: "{{ remote_tmp_dir }}/unarchive-00.{{item}}"
dest: "{{ remote_tmp_dir }}/exclude-{{item}}"
remote_src: yes
exclude:
- "exclude/exclude-*.txt"
- "other/exclude-1.ext"
with_items:
- zip
- tar
- name: verify that the file was unarchived
shell: find {{ remote_tmp_dir }}/exclude-{{item}} chdir={{ remote_tmp_dir }}
register: unarchive00
with_items:
- zip
- tar
- name: verify that archive extraction excluded the files
assert:
that:
- "'exclude/exclude-1.txt' not in item.stdout"
- "'other/exclude-1.ext' not in item.stdout"
with_items:
- "{{ unarchive00.results }}"
- name: remove our zip unarchive destination
file:
path: '{{remote_tmp_dir}}/test-unarchive-zip'
state: absent