2014-02-20 19:59:46 +01: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 19:37:19 +01:00
|
|
|
# Make sure we start fresh
|
|
|
|
|
|
|
|
- name: Ensure zip is present to create test archive (yum)
|
|
|
|
yum: name=zip state=latest
|
|
|
|
when: ansible_pkg_mgr == 'yum'
|
|
|
|
|
|
|
|
- name: Ensure zip is present to create test archive (apt)
|
2015-01-22 21:31:32 +01:00
|
|
|
apt: name=zip state=latest
|
2015-01-22 19:37:19 +01:00
|
|
|
when: ansible_pkg_mgr == 'apt'
|
2014-02-20 19:59:46 +01: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 14:09:09 +02:00
|
|
|
shell: tar czvf test-unarchive.tar.gz foo-unarchive.txt chdir={{output_dir}}
|
2014-02-20 19:59:46 +01:00
|
|
|
|
|
|
|
- name: prep a zip file
|
2015-01-22 01:16:30 +01:00
|
|
|
shell: zip test-unarchive.zip foo-unarchive.txt chdir={{output_dir}}
|
2014-02-20 19:59:46 +01:00
|
|
|
|
2015-04-15 14:09:09 +02: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 19:59:46 +01:00
|
|
|
- name: create our tar unarchive destination
|
|
|
|
file: path={{output_dir}}/test-unarchive-tar state=directory
|
|
|
|
|
|
|
|
- name: unarchive a tar file
|
|
|
|
unarchive: src={{output_dir}}/test-unarchive.tar dest="{{output_dir | expanduser}}/test-unarchive-tar" copy=no
|
|
|
|
register: unarchive01
|
|
|
|
|
|
|
|
- name: verify that the file was marked as changed
|
2014-02-20 20:25:42 +01:00
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "unarchive01.changed == true"
|
2014-02-20 19:59:46 +01: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
|
|
|
|
unarchive: src={{output_dir}}/test-unarchive.tar.gz dest={{output_dir | expanduser}}/test-unarchive-tar-gz copy=no
|
|
|
|
register: unarchive02
|
|
|
|
|
|
|
|
- name: verify that the file was marked as changed
|
2014-02-20 20:25:42 +01:00
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "unarchive02.changed == true"
|
2014-02-20 19:59:46 +01: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 01:19:46 +01: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
|
|
|
|
unarchive: src={{output_dir}}/test-unarchive.tar.gz dest={{output_dir | expanduser}}/test-unarchive-tar-gz copy=no creates={{output_dir}}/test-unarchive-tar-gz/foo-unarchive.txt
|
|
|
|
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
|
|
|
|
unarchive: src={{output_dir}}/test-unarchive.tar.gz dest={{output_dir | expanduser}}/test-unarchive-tar-gz copy=no creates={{output_dir}}/test-unarchive-tar-gz/foo-unarchive.txt
|
|
|
|
register: unarchive02c
|
|
|
|
|
|
|
|
- name: verify that the file was not marked as changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "unarchive02c.changed == false"
|
|
|
|
|
2015-01-14 22:03:21 +01: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"
|
|
|
|
copy: no
|
|
|
|
creates: "{{output_dir}}/test-unarchive-tar-gz/foo-unarchive.txt"
|
2015-01-15 04:23:12 +01:00
|
|
|
register: unarchive02d
|
2015-01-14 22:03:21 +01:00
|
|
|
|
|
|
|
- name: verify that the file was not marked as changed
|
|
|
|
assert:
|
|
|
|
that:
|
2015-01-15 04:23:12 +01:00
|
|
|
- "unarchive02d.changed == false"
|
2015-01-14 22:03:21 +01:00
|
|
|
|
2014-03-08 01:19:46 +01:00
|
|
|
- name: remove our tar.gz unarchive destination
|
|
|
|
file: path={{output_dir}}/test-unarchive-tar-gz state=absent
|
|
|
|
|
2014-02-20 19:59:46 +01:00
|
|
|
- name: create our zip unarchive destination
|
|
|
|
file: path={{output_dir}}/test-unarchive-zip state=directory
|
|
|
|
|
|
|
|
- name: unarchive a zip file
|
|
|
|
unarchive: src={{output_dir}}/test-unarchive.zip dest={{output_dir | expanduser}}/test-unarchive-zip copy=no
|
|
|
|
register: unarchive03
|
|
|
|
|
|
|
|
- name: verify that the file was marked as changed
|
2014-02-20 20:25:42 +01:00
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "unarchive03.changed == true"
|
2014-02-20 19:59:46 +01:00
|
|
|
|
|
|
|
- name: verify that the file was unarchived
|
|
|
|
file: path={{output_dir}}/test-unarchive-zip/foo-unarchive.txt state=file
|
|
|
|
|
2015-01-15 04:23:12 +01:00
|
|
|
- name: remove our zip unarchive destination
|
2014-02-20 19:59:46 +01:00
|
|
|
file: path={{output_dir}}/test-unarchive-zip state=absent
|
|
|
|
|
|
|
|
- name: remove our test file for the archive
|
2014-08-05 02:41:26 +02:00
|
|
|
file: path={{output_dir}}/foo-unarchive.txt state=absent
|
|
|
|
|
|
|
|
- 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
|
|
|
|
unarchive: src={{output_dir}}/test-unarchive.tar.gz dest=/tmp copy=no
|
|
|
|
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 04:23:12 +01:00
|
|
|
|
|
|
|
- name: create our unarchive destination
|
|
|
|
file: path={{output_dir}}/test-unarchive-tar-gz state=directory
|
|
|
|
|
2015-04-15 14:09:09 +02:00
|
|
|
- name: unarchive and set mode to 0600
|
2015-01-15 04:23:12 +01:00
|
|
|
unarchive:
|
|
|
|
src: "{{ output_dir }}/test-unarchive.tar.gz"
|
|
|
|
dest: "{{ output_dir | expanduser }}/test-unarchive-tar-gz"
|
|
|
|
copy: no
|
|
|
|
mode: "u+rwX,g-rwx,o-rwx"
|
|
|
|
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 14:09:09 +02: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 04:23:12 +01:00
|
|
|
unarchive:
|
|
|
|
src: "{{ output_dir }}/test-unarchive.tar.gz"
|
|
|
|
dest: "{{ output_dir | expanduser }}/test-unarchive-tar-gz"
|
|
|
|
copy: no
|
2015-04-15 14:09:09 +02: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"
|
|
|
|
copy: no
|
|
|
|
mode: "u+rwX,g-wx,o-wx,g+r,o+r"
|
2015-01-15 04:23:12 +01:00
|
|
|
register: unarchive07
|
|
|
|
|
|
|
|
- name: Test that the files were not changed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "unarchive07.changed == false"
|
|
|
|
|
|
|
|
- name: remove our tar.gz unarchive destination
|
2015-01-22 21:31:32 +01:00
|
|
|
file: path={{ output_dir }}/test-unarchive-tar-gz state=absent
|
|
|
|
|
2015-04-15 14:09:09 +02:00
|
|
|
|
|
|
|
- name: create our unarchive destination
|
|
|
|
file: path={{output_dir}}/test-unarchive-tar-gz state=directory
|
|
|
|
|
|
|
|
|
2015-01-22 21:31:32 +01: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"
|
|
|
|
copy: no
|
|
|
|
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"
|
|
|
|
copy: no
|
|
|
|
register: unarchive09
|
|
|
|
|
|
|
|
- name: Test that unarchive did nothing
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "unarchive09.changed == false"
|
2015-01-15 04:23:12 +01:00
|
|
|
|
2015-01-22 21:31:32 +01:00
|
|
|
- name: remove quotable chars test
|
|
|
|
file: path="{{ output_dir }}/test-quotes~root" state=absent
|
2015-04-15 14:09:09 +02: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"
|
|
|
|
copy: no
|
|
|
|
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"
|
|
|
|
copy: no
|
|
|
|
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
|