2014-02-20 18:59:46 +00:00
|
|
|
# Test code for the unarchive module.
|
|
|
|
# (c) 2014, Richard Isaacson <richard.c.isaacson@gmail.com>
|
|
|
|
|
|
|
|
# This file is part of Ansible
|
|
|
|
#
|
|
|
|
# Ansible is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Ansible is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
2015-01-22 18:37:19 +00:00
|
|
|
# Make sure we start fresh
|
|
|
|
|
2018-05-24 20:14:15 +00:00
|
|
|
# Need unzip for unarchive module, and zip for archive creation.
|
2017-08-11 19:36:46 +00:00
|
|
|
- name: Ensure zip and unzip is present to create test archive (yum)
|
|
|
|
yum: name=zip,unzip state=latest
|
2015-01-22 18:37:19 +00:00
|
|
|
when: ansible_pkg_mgr == 'yum'
|
|
|
|
|
2016-05-26 21:47:11 +00:00
|
|
|
#- name: Ensure zip is present to create test archive (dnf)
|
|
|
|
# dnf: name=zip state=latest
|
|
|
|
# when: ansible_pkg_mgr == 'dnf'
|
2015-12-20 16:06:26 +00:00
|
|
|
|
2018-05-24 20:14:15 +00:00
|
|
|
- name: Ensure zip & unzip is present to create test archive (apt)
|
2017-08-11 19:36:46 +00:00
|
|
|
apt: name=zip,unzip state=latest
|
2015-01-22 18:37:19 +00:00
|
|
|
when: ansible_pkg_mgr == 'apt'
|
2014-02-20 18:59:46 +00:00
|
|
|
|
2018-05-24 20:14:15 +00:00
|
|
|
- name: Ensure zip & unzip is present to create test archive (pkg)
|
2017-08-11 19:36:46 +00:00
|
|
|
pkgng: name=zip,unzip state=present
|
|
|
|
when: ansible_pkg_mgr == 'pkgng'
|
|
|
|
|
2014-02-20 18:59:46 +00:00
|
|
|
- name: prep our file
|
|
|
|
copy: src=foo.txt dest={{output_dir}}/foo-unarchive.txt
|
|
|
|
|
|
|
|
- name: prep a tar file
|
|
|
|
shell: tar cvf test-unarchive.tar foo-unarchive.txt chdir={{output_dir}}
|
|
|
|
|
|
|
|
- name: prep a tar.gz file
|
2015-04-15 12:09:09 +00:00
|
|
|
shell: tar czvf test-unarchive.tar.gz foo-unarchive.txt chdir={{output_dir}}
|
2014-02-20 18:59:46 +00:00
|
|
|
|
2017-08-11 19:36:46 +00:00
|
|
|
- name: prep a chmodded file for zip
|
|
|
|
copy: src=foo.txt dest={{output_dir}}/foo-unarchive-777.txt mode=0777
|
|
|
|
|
|
|
|
- name: prep a windows permission file for our zip
|
|
|
|
copy: src=foo.txt dest={{output_dir}}/FOO-UNAR.TXT
|
|
|
|
|
|
|
|
# This gets around an unzip timestamp bug in some distributions
|
2017-08-11 23:58:26 +00:00
|
|
|
# Recent unzip on Ubuntu and BSD will randomly round some timestamps up.
|
2018-05-24 20:14:15 +00:00
|
|
|
# But that doesn't seem to happen when the timestamp has an even second.
|
2017-08-11 19:36:46 +00:00
|
|
|
- name: Bug work around
|
|
|
|
command: touch -t "201705111530.00" {{output_dir}}/foo-unarchive.txt {{output_dir}}/foo-unarchive-777.txt {{output_dir}}/FOO-UNAR.TXT
|
|
|
|
# See Ubuntu bug 1691636: https://bugs.launchpad.net/ubuntu/+source/unzip/+bug/1691636
|
2018-05-24 20:14:15 +00:00
|
|
|
# When these are fixed, this code should be removed.
|
2017-08-11 19:36:46 +00:00
|
|
|
|
2014-02-20 18:59:46 +00:00
|
|
|
- name: prep a zip file
|
2017-08-11 19:36:46 +00:00
|
|
|
shell: zip test-unarchive.zip foo-unarchive.txt foo-unarchive-777.txt chdir={{output_dir}}
|
2014-02-20 18:59:46 +00:00
|
|
|
|
2018-06-22 15:28:14 +00:00
|
|
|
- name: Prepare - Create test dirs
|
|
|
|
file:
|
|
|
|
path: "{{output_dir}}/{{item}}"
|
|
|
|
state: directory
|
|
|
|
with_items:
|
|
|
|
- created/include
|
|
|
|
- created/exclude
|
|
|
|
- created/other
|
|
|
|
|
|
|
|
- name: Prepare - Create test files
|
|
|
|
file:
|
|
|
|
path: "{{output_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 {{output_dir}}/unarchive-00.zip * chdir={{output_dir}}/created/
|
|
|
|
|
|
|
|
- name: Prepare - tar file
|
|
|
|
shell: tar czvf {{output_dir}}/unarchive-00.tar * chdir={{output_dir}}/created/
|
|
|
|
|
2017-08-11 19:36:46 +00:00
|
|
|
- name: add a file with Windows permissions to zip file
|
|
|
|
shell: zip -k test-unarchive.zip FOO-UNAR.TXT chdir={{output_dir}}
|
2018-05-24 20:14:15 +00:00
|
|
|
|
2015-04-15 12:09:09 +00:00
|
|
|
- name: prep a subdirectory
|
|
|
|
file: path={{output_dir}}/unarchive-dir state=directory
|
|
|
|
|
|
|
|
- name: prep our file
|
|
|
|
copy: src=foo.txt dest={{output_dir}}/unarchive-dir/foo-unarchive.txt
|
|
|
|
|
|
|
|
- name: prep a tar.gz file with directory
|
|
|
|
shell: tar czvf test-unarchive-dir.tar.gz unarchive-dir chdir={{output_dir}}
|
|
|
|
|
2014-02-20 18:59:46 +00:00
|
|
|
- name: create our tar unarchive destination
|
|
|
|
file: path={{output_dir}}/test-unarchive-tar state=directory
|
|
|
|
|
|
|
|
- name: unarchive a tar file
|
2016-07-14 16:23:21 +00:00
|
|
|
unarchive: src={{output_dir}}/test-unarchive.tar dest="{{output_dir | expanduser}}/test-unarchive-tar" remote_src=yes
|
2014-02-20 18:59:46 +00:00
|
|
|
register: unarchive01
|
|
|
|
|
|
|
|
- name: verify that the file was marked as changed
|
2014-02-20 19:25:42 +00:00
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "unarchive01.changed == true"
|
2014-02-20 18:59:46 +00:00
|
|
|
|
|
|
|
- name: verify that the file was unarchived
|
|
|
|
file: path={{output_dir}}/test-unarchive-tar/foo-unarchive.txt state=file
|
|
|
|
|
|
|
|
- name: remove our tar unarchive destination
|
|
|
|
file: path={{output_dir}}/test-unarchive-tar state=absent
|
|
|
|
|
|
|
|
- name: create our tar.gz unarchive destination
|
|
|
|
file: path={{output_dir}}/test-unarchive-tar-gz state=directory
|
|
|
|
|
|
|
|
- name: unarchive a tar.gz file
|
2016-07-14 16:23:21 +00:00
|
|
|
unarchive: src={{output_dir}}/test-unarchive.tar.gz dest={{output_dir | expanduser}}/test-unarchive-tar-gz remote_src=yes
|
2014-02-20 18:59:46 +00:00
|
|
|
register: unarchive02
|
|
|
|
|
|
|
|
- name: verify that the file was marked as changed
|
2014-02-20 19:25:42 +00:00
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "unarchive02.changed == true"
|
2015-04-15 16:28:50 +00:00
|
|
|
# Verify that no file list is generated
|
|
|
|
- "'files' not in unarchive02"
|
2014-02-20 18:59:46 +00:00
|
|
|
|
|
|
|
- name: verify that the file was unarchived
|
|
|
|
file: path={{output_dir}}/test-unarchive-tar-gz/foo-unarchive.txt state=file
|
|
|
|
|
|
|
|
- name: remove our tar.gz unarchive destination
|
|
|
|
file: path={{output_dir}}/test-unarchive-tar-gz state=absent
|
|
|
|
|
2014-03-08 00:19:46 +00:00
|
|
|
- name: create our tar.gz unarchive destination for creates
|
|
|
|
file: path={{output_dir}}/test-unarchive-tar-gz state=directory
|
|
|
|
|
|
|
|
- name: unarchive a tar.gz file with creates set
|
2016-07-14 16:23:21 +00:00
|
|
|
unarchive: src={{output_dir}}/test-unarchive.tar.gz dest={{output_dir | expanduser}}/test-unarchive-tar-gz remote_src=yes creates={{output_dir}}/test-unarchive-tar-gz/foo-unarchive.txt
|
2014-03-08 00:19:46 +00:00
|
|
|
register: unarchive02b
|
|
|
|
|
|
|
|
- name: verify that the file was marked as changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "unarchive02b.changed == true"
|
|
|
|
|
|
|
|
- name: verify that the file was unarchived
|
|
|
|
file: path={{output_dir}}/test-unarchive-tar-gz/foo-unarchive.txt state=file
|
|
|
|
|
|
|
|
- name: unarchive a tar.gz file with creates over an existing file
|
2016-07-14 16:23:21 +00:00
|
|
|
unarchive: src={{output_dir}}/test-unarchive.tar.gz dest={{output_dir | expanduser}}/test-unarchive-tar-gz remote_src=yes creates={{output_dir}}/test-unarchive-tar-gz/foo-unarchive.txt
|
2014-03-08 00:19:46 +00:00
|
|
|
register: unarchive02c
|
|
|
|
|
|
|
|
- name: verify that the file was not marked as changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "unarchive02c.changed == false"
|
|
|
|
|
2015-01-14 21:03:21 +00:00
|
|
|
- name: unarchive a tar.gz file with creates over an existing file using complex_args
|
|
|
|
unarchive:
|
|
|
|
src: "{{output_dir}}/test-unarchive.tar.gz"
|
|
|
|
dest: "{{output_dir | expanduser}}/test-unarchive-tar-gz"
|
2016-07-14 16:23:21 +00:00
|
|
|
remote_src: yes
|
2015-01-14 21:03:21 +00:00
|
|
|
creates: "{{output_dir}}/test-unarchive-tar-gz/foo-unarchive.txt"
|
2015-01-15 03:23:12 +00:00
|
|
|
register: unarchive02d
|
2015-01-14 21:03:21 +00:00
|
|
|
|
|
|
|
- name: verify that the file was not marked as changed
|
|
|
|
assert:
|
|
|
|
that:
|
2015-01-15 03:23:12 +00:00
|
|
|
- "unarchive02d.changed == false"
|
2015-01-14 21:03:21 +00:00
|
|
|
|
2014-03-08 00:19:46 +00:00
|
|
|
- name: remove our tar.gz unarchive destination
|
|
|
|
file: path={{output_dir}}/test-unarchive-tar-gz state=absent
|
|
|
|
|
2014-02-20 18:59:46 +00:00
|
|
|
- name: create our zip unarchive destination
|
|
|
|
file: path={{output_dir}}/test-unarchive-zip state=directory
|
|
|
|
|
|
|
|
- name: unarchive a zip file
|
2016-07-14 16:23:21 +00:00
|
|
|
unarchive: src={{output_dir}}/test-unarchive.zip dest={{output_dir | expanduser}}/test-unarchive-zip remote_src=yes list_files=True
|
2014-02-20 18:59:46 +00:00
|
|
|
register: unarchive03
|
|
|
|
|
|
|
|
- name: verify that the file was marked as changed
|
2014-02-20 19:25:42 +00:00
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "unarchive03.changed == true"
|
2015-04-15 16:28:50 +00:00
|
|
|
# Verify that file list is generated
|
|
|
|
- "'files' in unarchive03"
|
2017-08-11 19:36:46 +00:00
|
|
|
- "{{unarchive03['files']| length}} == 3"
|
2015-04-15 16:28:50 +00:00
|
|
|
- "'foo-unarchive.txt' in unarchive03['files']"
|
2017-08-11 19:36:46 +00:00
|
|
|
- "'foo-unarchive-777.txt' in unarchive03['files']"
|
|
|
|
- "'FOO-UNAR.TXT' in unarchive03['files']"
|
2017-08-11 23:58:26 +00:00
|
|
|
|
2014-02-20 18:59:46 +00:00
|
|
|
- name: verify that the file was unarchived
|
2017-08-11 19:36:46 +00:00
|
|
|
file: path={{output_dir}}/test-unarchive-zip/{{item}} state=file
|
|
|
|
with_items:
|
|
|
|
- foo-unarchive.txt
|
|
|
|
- foo-unarchive-777.txt
|
|
|
|
- FOO-UNAR.TXT
|
2017-08-11 23:58:26 +00:00
|
|
|
|
2017-08-11 19:36:46 +00:00
|
|
|
- name: repeat the last request to verify no changes
|
|
|
|
unarchive: src={{output_dir}}/test-unarchive.zip dest={{output_dir | expanduser}}/test-unarchive-zip remote_src=yes list_files=True
|
|
|
|
register: unarchive03b
|
2018-05-24 20:14:15 +00:00
|
|
|
|
2017-08-11 19:36:46 +00:00
|
|
|
- name: verify that the task was not marked as changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "unarchive03b.changed == false"
|
2017-08-11 23:58:26 +00:00
|
|
|
|
2018-05-24 20:14:15 +00:00
|
|
|
- name: "Create {{ output_dir }}/exclude directory"
|
|
|
|
file:
|
|
|
|
state: directory
|
2018-06-22 15:28:14 +00:00
|
|
|
path: "{{ output_dir }}/exclude-{{item}}"
|
|
|
|
with_items:
|
|
|
|
- zip
|
|
|
|
- tar
|
2018-05-24 20:14:15 +00:00
|
|
|
|
2018-06-22 15:28:14 +00:00
|
|
|
- name: Unpack archive file excluding glob files.
|
2018-05-24 20:14:15 +00:00
|
|
|
unarchive:
|
2018-06-22 15:28:14 +00:00
|
|
|
src: "{{ output_dir }}/unarchive-00.{{item}}"
|
|
|
|
dest: "{{ output_dir }}/exclude-{{item}}"
|
|
|
|
exclude: "exclude/exclude-*.txt"
|
|
|
|
with_items:
|
|
|
|
- zip
|
|
|
|
- tar
|
2018-05-24 20:14:15 +00:00
|
|
|
|
|
|
|
- name: verify that the file was unarchived
|
2018-06-22 15:28:14 +00:00
|
|
|
shell: find {{ output_dir }}/exclude-{{item}} chdir={{ output_dir }}
|
|
|
|
register: unarchive00
|
|
|
|
with_items:
|
|
|
|
- zip
|
|
|
|
- tar
|
2018-05-24 20:14:15 +00:00
|
|
|
|
2018-06-22 15:28:14 +00:00
|
|
|
- name: verify that archive extraction excluded the files
|
2018-05-24 20:14:15 +00:00
|
|
|
assert:
|
|
|
|
that:
|
2018-06-22 15:28:14 +00:00
|
|
|
- "'exclude/exclude-1.txt' not in item.stdout"
|
|
|
|
with_items:
|
|
|
|
- "{{ unarchive00.results }}"
|
2018-05-24 20:14:15 +00:00
|
|
|
|
2015-01-15 03:23:12 +00:00
|
|
|
- name: remove our zip unarchive destination
|
2014-02-20 18:59:46 +00:00
|
|
|
file: path={{output_dir}}/test-unarchive-zip state=absent
|
|
|
|
|
2017-08-11 19:36:46 +00:00
|
|
|
- name: remove our test files for the archive
|
|
|
|
file: path={{output_dir}}/{{item}} state=absent
|
|
|
|
with_items:
|
|
|
|
- foo-unarchive.txt
|
|
|
|
- foo-unarchive-777.txt
|
|
|
|
- FOO-UNAR.TXT
|
2014-08-05 00:41:26 +00:00
|
|
|
|
|
|
|
- name: check if /tmp/foo-unarchive.text exists
|
|
|
|
stat: path=/tmp/foo-unarchive.txt
|
|
|
|
ignore_errors: True
|
|
|
|
register: unarchive04
|
|
|
|
|
|
|
|
- name: fail if the proposed destination file exists for safey
|
|
|
|
fail: msg="/tmp/foo-unarchive.txt already exists, aborting"
|
|
|
|
when: unarchive04.stat.exists
|
|
|
|
|
|
|
|
- name: try unarchiving to /tmp
|
2018-05-24 20:14:15 +00:00
|
|
|
unarchive: src={{output_dir}}/test-unarchive.tar.gz dest=/tmp remote_src=yes
|
2014-08-05 00:41:26 +00:00
|
|
|
register: unarchive05
|
|
|
|
|
|
|
|
- name: verify that the file was marked as changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "unarchive05.changed == true"
|
|
|
|
|
|
|
|
- name: verify that the file was unarchived
|
|
|
|
file: path=/tmp/foo-unarchive.txt state=file
|
|
|
|
|
|
|
|
- name: remove our unarchive destination
|
|
|
|
file: path=/tmp/foo-unarchive.txt state=absent
|
2015-01-15 03:23:12 +00:00
|
|
|
|
|
|
|
- name: create our unarchive destination
|
|
|
|
file: path={{output_dir}}/test-unarchive-tar-gz state=directory
|
|
|
|
|
2017-08-11 23:58:26 +00:00
|
|
|
- name: unarchive and set mode to 0600, directories 0700
|
2015-01-15 03:23:12 +00:00
|
|
|
unarchive:
|
|
|
|
src: "{{ output_dir }}/test-unarchive.tar.gz"
|
|
|
|
dest: "{{ output_dir | expanduser }}/test-unarchive-tar-gz"
|
2016-07-14 16:23:21 +00:00
|
|
|
remote_src: yes
|
2015-01-15 03:23:12 +00:00
|
|
|
mode: "u+rwX,g-rwx,o-rwx"
|
2015-04-15 16:28:50 +00:00
|
|
|
list_files: True
|
2015-01-15 03:23:12 +00:00
|
|
|
register: unarchive06
|
|
|
|
|
|
|
|
- name: Test that the file modes were changed
|
|
|
|
stat:
|
|
|
|
path: "{{ output_dir | expanduser }}/test-unarchive-tar-gz/foo-unarchive.txt"
|
|
|
|
register: unarchive06_stat
|
|
|
|
|
|
|
|
- name: Test that the file modes were changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "unarchive06.changed == true"
|
|
|
|
- "unarchive06_stat.stat.mode == '0600'"
|
2015-04-15 16:28:50 +00:00
|
|
|
# Verify that file list is generated
|
|
|
|
- "'files' in unarchive06"
|
|
|
|
- "{{unarchive06['files']| length}} == 1"
|
|
|
|
- "'foo-unarchive.txt' in unarchive06['files']"
|
2015-01-15 03:23:12 +00:00
|
|
|
|
2015-04-15 12:09:09 +00:00
|
|
|
- name: remove our tar.gz unarchive destination
|
|
|
|
file: path={{ output_dir }}/test-unarchive-tar-gz state=absent
|
|
|
|
|
|
|
|
- name: create our unarchive destination
|
|
|
|
file: path={{output_dir}}/test-unarchive-tar-gz state=directory
|
|
|
|
|
|
|
|
- name: unarchive over existing extraction and set mode to 0644
|
2015-01-15 03:23:12 +00:00
|
|
|
unarchive:
|
|
|
|
src: "{{ output_dir }}/test-unarchive.tar.gz"
|
|
|
|
dest: "{{ output_dir | expanduser }}/test-unarchive-tar-gz"
|
2016-07-14 16:23:21 +00:00
|
|
|
remote_src: yes
|
2015-04-15 12:09:09 +00:00
|
|
|
mode: "u+rwX,g-wx,o-wx,g+r,o+r"
|
|
|
|
register: unarchive06_2
|
|
|
|
|
|
|
|
- name: Test that the file modes were changed
|
|
|
|
stat:
|
|
|
|
path: "{{ output_dir | expanduser }}/test-unarchive-tar-gz/foo-unarchive.txt"
|
|
|
|
register: unarchive06_2_stat
|
|
|
|
|
|
|
|
- debug: var=unarchive06_2_stat.stat.mode
|
|
|
|
- name: Test that the files were changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "unarchive06_2.changed == true"
|
|
|
|
- "unarchive06_2_stat.stat.mode == '0644'"
|
|
|
|
|
|
|
|
- name: Repeat the last request to verify no changes
|
|
|
|
unarchive:
|
|
|
|
src: "{{ output_dir }}/test-unarchive.tar.gz"
|
|
|
|
dest: "{{ output_dir | expanduser }}/test-unarchive-tar-gz"
|
2016-07-14 16:23:21 +00:00
|
|
|
remote_src: yes
|
2017-08-11 23:58:26 +00:00
|
|
|
mode: "u+rwX-x,g-wx,o-wx,g+r,o+r"
|
2015-04-15 16:28:50 +00:00
|
|
|
list_files: True
|
2015-01-15 03:23:12 +00:00
|
|
|
register: unarchive07
|
|
|
|
|
|
|
|
- name: Test that the files were not changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "unarchive07.changed == false"
|
2015-04-15 16:28:50 +00:00
|
|
|
# Verify that file list is generated
|
|
|
|
- "'files' in unarchive07"
|
|
|
|
- "{{unarchive07['files']| length}} == 1"
|
|
|
|
- "'foo-unarchive.txt' in unarchive07['files']"
|
2015-01-15 03:23:12 +00:00
|
|
|
|
|
|
|
- name: remove our tar.gz unarchive destination
|
2015-01-22 20:31:32 +00:00
|
|
|
file: path={{ output_dir }}/test-unarchive-tar-gz state=absent
|
|
|
|
|
2017-08-11 23:58:26 +00:00
|
|
|
- name: create our unarchive destination
|
|
|
|
file: path={{output_dir}}/test-unarchive-zip state=directory
|
|
|
|
|
|
|
|
- name: unarchive and set mode to 0601, directories 0700
|
|
|
|
unarchive:
|
|
|
|
src: "{{ output_dir }}/test-unarchive.zip"
|
|
|
|
dest: "{{ output_dir | expanduser }}/test-unarchive-zip"
|
|
|
|
remote_src: yes
|
|
|
|
mode: "u+rwX-x,g-rwx,o=x"
|
|
|
|
list_files: True
|
|
|
|
register: unarchive08
|
|
|
|
|
|
|
|
- name: Test that the file modes were changed
|
|
|
|
stat:
|
|
|
|
path: "{{ output_dir | expanduser }}/test-unarchive-zip/foo-unarchive.txt"
|
|
|
|
register: unarchive08_stat
|
|
|
|
|
|
|
|
- name: Test that the file modes were changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "unarchive08.changed == true"
|
|
|
|
- "unarchive08_stat.stat.mode == '0601'"
|
|
|
|
# Verify that file list is generated
|
|
|
|
- "'files' in unarchive08"
|
|
|
|
- "{{unarchive08['files']| length}} == 3"
|
|
|
|
- "'foo-unarchive.txt' in unarchive08['files']"
|
|
|
|
- "'foo-unarchive-777.txt' in unarchive08['files']"
|
|
|
|
- "'FOO-UNAR.TXT' in unarchive08['files']"
|
|
|
|
|
|
|
|
- name: unarchive zipfile a second time and set mode to 0601, directories 0700
|
|
|
|
unarchive:
|
|
|
|
src: "{{ output_dir }}/test-unarchive.zip"
|
|
|
|
dest: "{{ output_dir | expanduser }}/test-unarchive-zip"
|
|
|
|
remote_src: yes
|
|
|
|
mode: "u+rwX-x,g-rwx,o=x"
|
|
|
|
list_files: True
|
|
|
|
register: unarchive08
|
|
|
|
|
|
|
|
- name: Test that the file modes were not changed
|
|
|
|
stat:
|
|
|
|
path: "{{ output_dir | expanduser }}/test-unarchive-zip/foo-unarchive.txt"
|
|
|
|
register: unarchive08_stat
|
|
|
|
|
|
|
|
- debug:
|
|
|
|
var: unarchive08
|
|
|
|
|
|
|
|
- debug:
|
|
|
|
var: unarchive08_stat
|
|
|
|
|
|
|
|
- name: Test that the files did not change
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "unarchive08.changed == false"
|
|
|
|
- "unarchive08_stat.stat.mode == '0601'"
|
|
|
|
# Verify that file list is generated
|
|
|
|
- "'files' in unarchive08"
|
|
|
|
- "{{unarchive08['files']| length}} == 3"
|
|
|
|
- "'foo-unarchive.txt' in unarchive08['files']"
|
|
|
|
- "'foo-unarchive-777.txt' in unarchive08['files']"
|
|
|
|
- "'FOO-UNAR.TXT' in unarchive08['files']"
|
|
|
|
|
|
|
|
- name: remove our zip unarchive destination
|
|
|
|
file: path={{ output_dir }}/test-unarchive-zip state=absent
|
|
|
|
|
2015-04-15 12:09:09 +00:00
|
|
|
- name: create our unarchive destination
|
|
|
|
file: path={{output_dir}}/test-unarchive-tar-gz state=directory
|
|
|
|
|
2015-01-22 20:31:32 +00:00
|
|
|
- name: create a directory with quotable chars
|
|
|
|
file: path="{{ output_dir }}/test-quotes~root" state=directory
|
|
|
|
|
|
|
|
- name: unarchive into directory with quotable chars
|
|
|
|
unarchive:
|
|
|
|
src: "{{ output_dir }}/test-unarchive.tar.gz"
|
|
|
|
dest: "{{ output_dir | expanduser }}/test-quotes~root"
|
2016-07-14 16:23:21 +00:00
|
|
|
remote_src: yes
|
2015-01-22 20:31:32 +00:00
|
|
|
register: unarchive08
|
|
|
|
|
|
|
|
- name: Test that unarchive succeeded
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "unarchive08.changed == true"
|
|
|
|
|
|
|
|
- name: unarchive into directory with quotable chars a second time
|
|
|
|
unarchive:
|
|
|
|
src: "{{ output_dir }}/test-unarchive.tar.gz"
|
|
|
|
dest: "{{ output_dir | expanduser }}/test-quotes~root"
|
2016-07-14 16:23:21 +00:00
|
|
|
remote_src: yes
|
2015-01-22 20:31:32 +00:00
|
|
|
register: unarchive09
|
|
|
|
|
|
|
|
- name: Test that unarchive did nothing
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "unarchive09.changed == false"
|
2015-01-15 03:23:12 +00:00
|
|
|
|
2015-01-22 20:31:32 +00:00
|
|
|
- name: remove quotable chars test
|
|
|
|
file: path="{{ output_dir }}/test-quotes~root" state=absent
|
2015-04-15 12:09:09 +00:00
|
|
|
|
2016-05-26 21:47:11 +00:00
|
|
|
- name: create our unarchive destination
|
|
|
|
file:
|
2016-06-01 20:20:54 +00:00
|
|
|
path: "{{ output_dir }}/test-unarchive-nonascii-くらとみ-tar-gz"
|
2016-05-26 21:47:11 +00:00
|
|
|
state: directory
|
|
|
|
|
|
|
|
- name: test that unarchive works with an archive that contains non-ascii filenames
|
|
|
|
unarchive:
|
|
|
|
# Both the filename of the tarball and the filename inside the tarball have
|
|
|
|
# nonascii chars
|
2016-06-01 20:20:54 +00:00
|
|
|
src: "test-unarchive-nonascii-くらとみ.tar.gz"
|
|
|
|
dest: "{{ output_dir }}/test-unarchive-nonascii-くらとみ-tar-gz"
|
2016-05-26 21:47:11 +00:00
|
|
|
mode: "u+rwX,go+rX"
|
2016-08-19 13:16:21 +00:00
|
|
|
remote_src: no
|
2016-05-26 21:47:11 +00:00
|
|
|
register: nonascii_result0
|
|
|
|
|
|
|
|
- name: Check that file is really there
|
|
|
|
stat:
|
2016-06-01 20:20:54 +00:00
|
|
|
path: "{{ output_dir | expanduser }}/test-unarchive-nonascii-くらとみ-tar-gz/storage/àâæçéèïîôœ(copy)!@#$%^&-().jpg"
|
2016-05-26 21:47:11 +00:00
|
|
|
register: nonascii_stat0
|
|
|
|
|
|
|
|
- name: Assert that nonascii tests succeeded
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "nonascii_result0.changed == true"
|
|
|
|
- "nonascii_stat0.stat.exists == true"
|
|
|
|
|
|
|
|
- name: remove nonascii test
|
2016-06-01 20:20:54 +00:00
|
|
|
file: path="{{ output_dir }}/test-unarchive-nonascii-くらとみ-tar-gz" state=absent
|
2016-05-26 21:47:11 +00:00
|
|
|
|
2015-04-15 12:09:09 +00:00
|
|
|
# Test that unarchiving is performed if files are missing
|
|
|
|
# https://github.com/ansible/ansible-modules-core/issues/1064
|
|
|
|
- name: create our unarchive destination
|
|
|
|
file: path={{output_dir}}/test-unarchive-tar-gz state=directory
|
|
|
|
|
|
|
|
- name: unarchive a tar that has directories
|
|
|
|
unarchive:
|
|
|
|
src: "{{ output_dir }}/test-unarchive-dir.tar.gz"
|
|
|
|
dest: "{{ output_dir }}/test-unarchive-tar-gz"
|
|
|
|
mode: "0700"
|
2016-07-14 16:23:21 +00:00
|
|
|
remote_src: yes
|
2015-04-15 12:09:09 +00:00
|
|
|
register: unarchive10
|
|
|
|
|
|
|
|
- name: Test that unarchive succeeded
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "unarchive10.changed == true"
|
|
|
|
|
|
|
|
- name: Change the mode of the toplevel dir
|
|
|
|
file:
|
|
|
|
path: "{{ output_dir }}/test-unarchive-tar-gz/unarchive-dir"
|
|
|
|
mode: 0701
|
|
|
|
|
|
|
|
- name: Remove a file from the extraction point
|
|
|
|
file:
|
|
|
|
path: "{{ output_dir }}/test-unarchive-tar-gz/unarchive-dir/foo-unarchive.txt"
|
|
|
|
state: absent
|
|
|
|
|
|
|
|
- name: unarchive a tar that has directories
|
|
|
|
unarchive:
|
|
|
|
src: "{{ output_dir }}/test-unarchive-dir.tar.gz"
|
|
|
|
dest: "{{ output_dir }}/test-unarchive-tar-gz"
|
|
|
|
mode: "0700"
|
2016-07-14 16:23:21 +00:00
|
|
|
remote_src: yes
|
2015-04-15 12:09:09 +00:00
|
|
|
register: unarchive10_1
|
|
|
|
|
|
|
|
- name: Test that unarchive succeeded
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "unarchive10_1.changed == true"
|
|
|
|
|
|
|
|
- name: remove our tar.gz unarchive destination
|
|
|
|
file: path={{ output_dir }}/test-unarchive-tar-gz state=absent
|
2016-05-26 21:47:11 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Symlink tests
|
|
|
|
#
|
|
|
|
|
|
|
|
- name: Create a destination dir
|
|
|
|
file:
|
|
|
|
path: "{{ output_dir }}/test-unarchive-tar-gz"
|
|
|
|
state: directory
|
|
|
|
|
|
|
|
- name: Create a symlink to the detination dir
|
|
|
|
file:
|
|
|
|
path: "{{ output_dir }}/link-to-unarchive-dir"
|
|
|
|
src: "{{ output_dir }}/test-unarchive-tar-gz"
|
|
|
|
state: "link"
|
|
|
|
|
|
|
|
- name: test that unarchive works when dest is a symlink to a dir
|
|
|
|
unarchive:
|
|
|
|
src: "{{ output_dir }}/test-unarchive.tar.gz"
|
|
|
|
dest: "{{ output_dir | expanduser }}/link-to-unarchive-dir"
|
|
|
|
mode: "u+rwX,go+rX"
|
2016-07-14 16:23:21 +00:00
|
|
|
remote_src: yes
|
2016-05-26 21:47:11 +00:00
|
|
|
register: unarchive_11
|
|
|
|
|
|
|
|
- name: Check that file is really there
|
|
|
|
stat:
|
|
|
|
path: "{{ output_dir | expanduser }}/test-unarchive-tar-gz/foo-unarchive.txt"
|
|
|
|
register: unarchive11_stat0
|
|
|
|
|
|
|
|
- name: Assert that unarchive when dest is a symlink to a dir worked
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "unarchive_11.changed == true"
|
|
|
|
- "unarchive11_stat0.stat.exists == true"
|
|
|
|
|
|
|
|
- name: remove our tar.gz unarchive destination
|
|
|
|
file: path={{ output_dir }}/test-unarchive-tar-gz state=absent
|
|
|
|
|
|
|
|
- name: Create a file
|
|
|
|
file:
|
|
|
|
path: "{{ output_dir }}/test-unarchive-tar-gz"
|
|
|
|
state: touch
|
|
|
|
|
|
|
|
- name: Create a symlink to the file
|
|
|
|
file:
|
|
|
|
path: "{{ output_dir }}/link-to-unarchive-file"
|
|
|
|
src: "{{ output_dir }}/test-unarchive-tar-gz"
|
|
|
|
state: "link"
|
|
|
|
|
|
|
|
- name: test that unarchive fails when dest is a link to a file
|
|
|
|
unarchive:
|
|
|
|
src: "{{ output_dir }}/test-unarchive.tar.gz"
|
|
|
|
dest: "{{ output_dir | expanduser }}/link-to-unarchive-file"
|
|
|
|
mode: "u+rwX,go+rX"
|
2016-07-14 16:23:21 +00:00
|
|
|
remote_src: yes
|
2016-05-26 21:47:11 +00:00
|
|
|
ignore_errors: True
|
|
|
|
register: unarchive_12
|
|
|
|
|
|
|
|
- name: Assert that unarchive when dest is a file failed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "unarchive_12.failed == true"
|
|
|
|
|
|
|
|
- name: remove our tar.gz unarchive destination
|
|
|
|
file: path={{ output_dir }}/test-unarchive-tar-gz state=absent
|
2018-10-08 12:41:57 +00:00
|
|
|
|
|
|
|
# Test downloading a file before unarchiving it
|
|
|
|
- name: create our unarchive destination
|
|
|
|
file: path={{output_dir}}/test-unarchive-tar-gz state=directory
|
|
|
|
|
|
|
|
- name: unarchive a tar from an URL
|
|
|
|
unarchive:
|
|
|
|
src: "https://releases.ansible.com/ansible/ansible-latest.tar.gz"
|
|
|
|
dest: "{{ output_dir }}/test-unarchive-tar-gz"
|
|
|
|
mode: "0700"
|
|
|
|
remote_src: yes
|
|
|
|
register: unarchive13
|
|
|
|
|
|
|
|
- name: Test that unarchive succeeded
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "unarchive13.changed == true"
|
|
|
|
|
|
|
|
- name: remove our tar.gz unarchive destination
|
|
|
|
file: path={{ output_dir }}/test-unarchive-tar-gz state=absent
|