diff options
author | Tadej Borovšak <70951+tadeboro@users.noreply.github.com> | 2022-01-19 02:02:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-18 17:02:38 -0800 |
commit | 6da3cf51a329194d5b81fe1e8a10797eecfeb0fa (patch) | |
tree | 4f8ab44c4e25b25e0c019c461914de9d81e1d6f3 | |
parent | 070ae15c522ae2eb7481cb9ef1cc20b8a49b4f5c (diff) | |
download | ansible-6da3cf51a329194d5b81fe1e8a10797eecfeb0fa.tar.gz |
Fix zip content filtering in unarchive module (#76069) (#76420)
When we introduced an include parameter to the unarchive module, we
inadvertenly flipped the exclusion logic. This flip meant that the
unarchive module started rejecting files that should be extracted.
This commit flips the bad logic and adds some tests that will make
sure things do not go bad again.
(cherry picked from commit f92830d16e2fcca394a69b13e1017350e07152a3)
-rw-r--r-- | changelogs/fragments/76069-fix-unarchive-file-listing-in-zip.yaml | 3 | ||||
-rw-r--r-- | lib/ansible/modules/unarchive.py | 2 | ||||
-rw-r--r-- | test/integration/targets/unarchive/tasks/test_exclude.yml | 15 |
3 files changed, 19 insertions, 1 deletions
diff --git a/changelogs/fragments/76069-fix-unarchive-file-listing-in-zip.yaml b/changelogs/fragments/76069-fix-unarchive-file-listing-in-zip.yaml new file mode 100644 index 0000000000..31b91c4d98 --- /dev/null +++ b/changelogs/fragments/76069-fix-unarchive-file-listing-in-zip.yaml @@ -0,0 +1,3 @@ +bugfixes: +- unarchive - Fix zip archive file listing that caused issues with content + postprocessing (https://github.com/ansible/ansible/issues/76067). diff --git a/lib/ansible/modules/unarchive.py b/lib/ansible/modules/unarchive.py index 4867f8d79a..d1ccd01066 100644 --- a/lib/ansible/modules/unarchive.py +++ b/lib/ansible/modules/unarchive.py @@ -360,7 +360,7 @@ class ZipArchive(object): exclude_flag = False if self.excludes: for exclude in self.excludes: - if not fnmatch.fnmatch(member, exclude): + if fnmatch.fnmatch(member, exclude): exclude_flag = True break if not exclude_flag: diff --git a/test/integration/targets/unarchive/tasks/test_exclude.yml b/test/integration/targets/unarchive/tasks/test_exclude.yml index bf9f14fb51..8d3183c392 100644 --- a/test/integration/targets/unarchive/tasks/test_exclude.yml +++ b/test/integration/targets/unarchive/tasks/test_exclude.yml @@ -11,13 +11,28 @@ src: "{{ remote_tmp_dir }}/unarchive-00.{{item}}" dest: "{{ remote_tmp_dir }}/exclude-{{item}}" remote_src: yes + list_files: yes exclude: - "exclude/exclude-*.txt" - "other/exclude-1.ext" + register: result_of_unarchive with_items: - zip - tar +- name: Make sure unarchive module reported back extracted files + assert: + that: + - "'include/include-1.txt' in item.files" + - "'include/include-2.txt' in item.files" + - "'include/include-3.txt' in item.files" + - "'other/include-1.ext' in item.files" + - "'other/include-2.ext' in item.files" + - "'other/exclude-2.ext' in item.files" + - "'other/other-1.ext' in item.files" + - "'other/other-2.ext' in item.files" + loop: "{{ result_of_unarchive.results }}" + - name: verify that the file was unarchived shell: find {{ remote_tmp_dir }}/exclude-{{item}} chdir={{ remote_tmp_dir }} register: unarchive00 |