add collections
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
azp/posix/2
|
||||
needs/root
|
||||
destructive
|
||||
skip/aix
|
||||
skip/osx # FIXME
|
||||
@@ -0,0 +1,5 @@
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
bar.txt
|
||||
@@ -0,0 +1,5 @@
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
foo.txt
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
dependencies:
|
||||
- setup_pkg_mgr
|
||||
- setup_remote_tmp_dir
|
||||
@@ -0,0 +1,145 @@
|
||||
---
|
||||
####################################################################
|
||||
# WARNING: These are designed specifically for Ansible tests #
|
||||
# and should not be used as examples of how to write Ansible roles #
|
||||
####################################################################
|
||||
|
||||
# Test code for the archive module.
|
||||
# Copyright (c) 2017, Abhijeet Kasurde <akasurde@redhat.com>
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
# Make sure we start fresh
|
||||
|
||||
# Test setup
|
||||
- name: prep our files
|
||||
copy: src={{ item }} dest={{remote_tmp_dir}}/{{ item }}
|
||||
with_items:
|
||||
- foo.txt
|
||||
- bar.txt
|
||||
- empty.txt
|
||||
- sub
|
||||
- sub/subfile.txt
|
||||
|
||||
# Run twice without lzma backport installed, to make sure it does not crash
|
||||
- name: Archive - pre-test - first run
|
||||
archive:
|
||||
path: "{{ remote_tmp_dir }}/*.txt"
|
||||
dest: "{{ remote_tmp_dir }}/archive_pretest_1.tar"
|
||||
format: "tar"
|
||||
register: pretest_1
|
||||
|
||||
- name: Archive - pre-test - second run
|
||||
archive:
|
||||
path: "{{ remote_tmp_dir }}/*.txt"
|
||||
dest: "{{ remote_tmp_dir }}/archive_pretest_1.tar"
|
||||
format: "tar"
|
||||
register: pretest_2
|
||||
|
||||
- name: Archive - validate pre-test
|
||||
assert:
|
||||
that:
|
||||
- pretest_1 is changed
|
||||
- pretest_2 is not changed
|
||||
|
||||
# Install dependencies
|
||||
- name: Ensure zip is present to create test archive (yum)
|
||||
yum: name=zip state=latest
|
||||
when: ansible_facts.pkg_mgr == 'yum'
|
||||
|
||||
- name: Ensure zip is present to create test archive (apt)
|
||||
apt: name=zip state=latest
|
||||
when: ansible_facts.pkg_mgr == 'apt'
|
||||
|
||||
- name: Install prerequisites for backports.lzma when using python2 (non OSX)
|
||||
block:
|
||||
- name: Set liblzma package name depending on the OS
|
||||
set_fact:
|
||||
liblzma_dev_package:
|
||||
Debian: liblzma-dev
|
||||
RedHat: xz-devel
|
||||
Suse: xz-devel
|
||||
- name: Ensure liblzma-dev is present to install backports-lzma
|
||||
package: name={{ liblzma_dev_package[ansible_os_family] }} state=latest
|
||||
when: ansible_os_family in liblzma_dev_package.keys()
|
||||
when:
|
||||
- ansible_python_version.split('.')[0] == '2'
|
||||
- ansible_os_family != 'Darwin'
|
||||
|
||||
- name: Install prerequisites for backports.lzma when using python2 (OSX)
|
||||
block:
|
||||
- name: Find brew binary
|
||||
command: which brew
|
||||
register: brew_which
|
||||
- name: Get owner of brew binary
|
||||
stat: path="{{ brew_which.stdout }}"
|
||||
register: brew_stat
|
||||
- name: "Install package"
|
||||
homebrew:
|
||||
name: xz
|
||||
state: present
|
||||
update_homebrew: no
|
||||
become: yes
|
||||
become_user: "{{ brew_stat.stat.pw_name }}"
|
||||
# Newer versions of brew want to compile a package which takes a long time. Do not upgrade homebrew until a
|
||||
# proper solution can be found
|
||||
environment:
|
||||
HOMEBREW_NO_AUTO_UPDATE: True
|
||||
when:
|
||||
- ansible_python_version.split('.')[0] == '2'
|
||||
- ansible_os_family == 'Darwin'
|
||||
|
||||
- name: Ensure backports.lzma is present to create test archive (pip)
|
||||
pip: name=backports.lzma state=latest
|
||||
when: ansible_python_version.split('.')[0] == '2'
|
||||
register: backports_lzma_pip
|
||||
|
||||
- name: Define formats to test
|
||||
set_fact:
|
||||
formats:
|
||||
- tar
|
||||
- zip
|
||||
- gz
|
||||
- bz2
|
||||
- xz
|
||||
|
||||
# Run tests
|
||||
- name: Run core tests
|
||||
include_tasks:
|
||||
file: ../tests/core.yml
|
||||
loop: "{{ formats }}"
|
||||
loop_control:
|
||||
loop_var: format
|
||||
|
||||
- name: Run exclusions tests
|
||||
include_tasks:
|
||||
file: ../tests/exclusions.yml
|
||||
loop: "{{ formats }}"
|
||||
loop_control:
|
||||
loop_var: format
|
||||
|
||||
- name: Run remove tests
|
||||
include_tasks:
|
||||
file: ../tests/remove.yml
|
||||
loop: "{{ formats }}"
|
||||
loop_control:
|
||||
loop_var: format
|
||||
|
||||
- name: Run broken link tests
|
||||
include_tasks:
|
||||
file: ../tests/broken-link.yml
|
||||
loop: "{{ formats }}"
|
||||
loop_control:
|
||||
loop_var: format
|
||||
|
||||
- name: Run Idempotency tests
|
||||
include_tasks:
|
||||
file: ../tests/idempotency.yml
|
||||
loop: "{{ formats }}"
|
||||
loop_control:
|
||||
loop_var: format
|
||||
|
||||
# Test cleanup
|
||||
- name: Remove backports.lzma if previously installed (pip)
|
||||
pip: name=backports.lzma state=absent
|
||||
when: backports_lzma_pip is changed
|
||||
@@ -0,0 +1,35 @@
|
||||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
- block:
|
||||
- name: Create link - broken link ({{ format }})
|
||||
file:
|
||||
src: /nowhere
|
||||
dest: "{{ remote_tmp_dir }}/nowhere.txt"
|
||||
state: link
|
||||
force: yes
|
||||
|
||||
- name: Archive - broken link ({{ format }})
|
||||
archive:
|
||||
path: "{{ remote_tmp_dir }}/*.txt"
|
||||
dest: "{{ remote_tmp_dir }}/archive_broken_link.{{ format }}"
|
||||
format: "{{ format }}"
|
||||
|
||||
- name: Verify archive exists - broken link ({{ format }})
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/archive_broken_link.{{ format }}"
|
||||
state: file
|
||||
|
||||
- name: Remove archive - broken link ({{ format }})
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/archive_broken_link.{{ format }}"
|
||||
state: absent
|
||||
|
||||
- name: Remove link - broken link ({{ format }})
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/nowhere.txt"
|
||||
state: absent
|
||||
# 'zip' does not support symlink's
|
||||
when: format != 'zip'
|
||||
@@ -0,0 +1,177 @@
|
||||
---
|
||||
####################################################################
|
||||
# WARNING: These are designed specifically for Ansible tests #
|
||||
# and should not be used as examples of how to write Ansible roles #
|
||||
####################################################################
|
||||
|
||||
# Test code for the archive module.
|
||||
# Copyright (c) 2017, Abhijeet Kasurde <akasurde@redhat.com>
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
# Make sure we start fresh
|
||||
|
||||
# Core functionality tests
|
||||
- name: Archive - no options ({{ format }})
|
||||
archive:
|
||||
path: "{{ remote_tmp_dir }}/*.txt"
|
||||
dest: "{{ remote_tmp_dir }}/archive_no_opts.{{ format }}"
|
||||
format: "{{ format }}"
|
||||
register: archive_no_options
|
||||
|
||||
- name: Verify that archive exists - no options ({{ format }})
|
||||
file:
|
||||
path: "{{remote_tmp_dir}}/archive_no_opts.{{ format }}"
|
||||
state: file
|
||||
|
||||
- name: Verify that archive result is changed and includes all files - no options ({{ format }})
|
||||
assert:
|
||||
that:
|
||||
- archive_no_options is changed
|
||||
- "archive_no_options.dest_state == 'archive'"
|
||||
- "{{ archive_no_options.archived | length }} == 3"
|
||||
|
||||
- name: Remove the archive - no options ({{ format }})
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/archive_no_options.{{ format }}"
|
||||
state: absent
|
||||
|
||||
- name: Archive - file options ({{ format }})
|
||||
archive:
|
||||
path: "{{ remote_tmp_dir }}/*.txt"
|
||||
dest: "{{ remote_tmp_dir }}/archive_file_options.{{ format }}"
|
||||
format: "{{ format }}"
|
||||
mode: "u+rwX,g-rwx,o-rwx"
|
||||
register: archive_file_options
|
||||
|
||||
- name: Retrieve archive file information - file options ({{ format }})
|
||||
stat:
|
||||
path: "{{ remote_tmp_dir }}/archive_file_options.{{ format }}"
|
||||
register: archive_file_options_stat
|
||||
|
||||
- name: Test that the file modes were changed
|
||||
assert:
|
||||
that:
|
||||
- archive_file_options_stat is not changed
|
||||
- "archive_file_options.mode == '0600'"
|
||||
- "{{ archive_file_options.archived | length }} == 3"
|
||||
|
||||
- name: Remove the archive - file options ({{ format }})
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/archive_file_options.{{ format }}"
|
||||
state: absent
|
||||
|
||||
- name: Archive - non-ascii ({{ format }})
|
||||
archive:
|
||||
path: "{{ remote_tmp_dir }}/*.txt"
|
||||
dest: "{{ remote_tmp_dir }}/archive_nonascii_くらとみ.{{ format }}"
|
||||
format: "{{ format }}"
|
||||
register: archive_nonascii
|
||||
|
||||
- name: Retrieve archive file information - non-ascii ({{ format }})
|
||||
stat:
|
||||
path: "{{ remote_tmp_dir }}/archive_nonascii_くらとみ.{{ format }}"
|
||||
register: archive_nonascii_stat
|
||||
|
||||
- name: Test that archive exists - non-ascii ({{ format }})
|
||||
assert:
|
||||
that:
|
||||
- archive_nonascii is changed
|
||||
- archive_nonascii_stat.stat.exists == true
|
||||
|
||||
- name: Remove the archive - non-ascii ({{ format }})
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/archive_nonascii_くらとみ.{{ format }}"
|
||||
state: absent
|
||||
|
||||
- name: Archive - single target ({{ format }})
|
||||
archive:
|
||||
path: "{{ remote_tmp_dir }}/foo.txt"
|
||||
dest: "{{ remote_tmp_dir }}/archive_single_target.{{ format }}"
|
||||
format: "{{ format }}"
|
||||
register: archive_single_target
|
||||
|
||||
- name: Assert archive has correct state - single target ({{ format }})
|
||||
assert:
|
||||
that:
|
||||
- archive_single_target.dest_state == state_map[format]
|
||||
vars:
|
||||
state_map:
|
||||
tar: archive
|
||||
zip: archive
|
||||
gz: compress
|
||||
bz2: compress
|
||||
xz: compress
|
||||
|
||||
- block:
|
||||
- name: Retrieve contents of archive - single target ({{ format }})
|
||||
ansible.builtin.unarchive:
|
||||
src: "{{ remote_tmp_dir }}/archive_single_target.{{ format }}"
|
||||
dest: .
|
||||
list_files: true
|
||||
check_mode: true
|
||||
ignore_errors: true
|
||||
register: archive_single_target_contents
|
||||
|
||||
- name: Assert that file names are preserved - single target ({{ format }})
|
||||
assert:
|
||||
that:
|
||||
- "'oo.txt' not in archive_single_target_contents.files"
|
||||
- "'foo.txt' in archive_single_target_contents.files"
|
||||
# ``unarchive`` fails for RHEL and FreeBSD on ansible 2.x
|
||||
when: archive_single_target_contents is success and archive_single_target_contents is not skipped
|
||||
when: "format == 'zip'"
|
||||
|
||||
- name: Remove archive - single target ({{ format }})
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/archive_single_target.{{ format }}"
|
||||
state: absent
|
||||
|
||||
- name: Archive - path list ({{ format }})
|
||||
archive:
|
||||
path:
|
||||
- "{{ remote_tmp_dir }}/empty.txt"
|
||||
- "{{ remote_tmp_dir }}/foo.txt"
|
||||
- "{{ remote_tmp_dir }}/bar.txt"
|
||||
dest: "{{ remote_tmp_dir }}/archive_path_list.{{ format }}"
|
||||
format: "{{ format }}"
|
||||
register: archive_path_list
|
||||
|
||||
- name: Verify that archive exists - path list ({{ format }})
|
||||
file:
|
||||
path: "{{remote_tmp_dir}}/archive_path_list.{{ format }}"
|
||||
state: file
|
||||
|
||||
- name: Assert that archive contains all files - path list ({{ format }})
|
||||
assert:
|
||||
that:
|
||||
- archive_path_list is changed
|
||||
- "{{ archive_path_list.archived | length }} == 3"
|
||||
|
||||
- name: Remove archive - path list ({{ format }})
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/archive_path_list.{{ format }}"
|
||||
state: absent
|
||||
|
||||
- name: Archive - missing paths ({{ format }})
|
||||
archive:
|
||||
path:
|
||||
- "{{ remote_tmp_dir }}/*.txt"
|
||||
- "{{ remote_tmp_dir }}/dne.txt"
|
||||
exclude_path: "{{ remote_tmp_dir }}/foo.txt"
|
||||
dest: "{{ remote_tmp_dir }}/archive_missing_paths.{{ format }}"
|
||||
format: "{{ format }}"
|
||||
register: archive_missing_paths
|
||||
|
||||
- name: Assert that incomplete archive has incomplete state - missing paths ({{ format }})
|
||||
assert:
|
||||
that:
|
||||
- archive_missing_paths is changed
|
||||
- "archive_missing_paths.dest_state == 'incomplete'"
|
||||
- "'{{ remote_tmp_dir }}/dne.txt' in archive_missing_paths.missing"
|
||||
- "'{{ remote_tmp_dir }}/foo.txt' not in archive_missing_paths.missing"
|
||||
|
||||
- name: Remove archive - missing paths ({{ format }})
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/archive_missing_paths.{{ format }}"
|
||||
state: absent
|
||||
@@ -0,0 +1,44 @@
|
||||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
- name: Archive - exclusion patterns ({{ format }})
|
||||
archive:
|
||||
path: "{{ remote_tmp_dir }}/*.txt"
|
||||
dest: "{{ remote_tmp_dir }}/archive_exclusion_patterns.{{ format }}"
|
||||
format: "{{ format }}"
|
||||
exclusion_patterns: b?r.*
|
||||
register: archive_exclusion_patterns
|
||||
|
||||
- name: Assert that only included files are archived - exclusion patterns ({{ format }})
|
||||
assert:
|
||||
that:
|
||||
- archive_exclusion_patterns is changed
|
||||
- "'bar.txt' not in archive_exclusion_patterns.archived"
|
||||
|
||||
- name: Remove archive - exclusion patterns ({{ format }})
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/archive_exclusion_patterns.{{ format }}"
|
||||
state: absent
|
||||
|
||||
- name: Archive - exclude path ({{ format }})
|
||||
archive:
|
||||
path:
|
||||
- "{{ remote_tmp_dir }}/sub/subfile.txt"
|
||||
- "{{ remote_tmp_dir }}"
|
||||
exclude_path:
|
||||
- "{{ remote_tmp_dir }}"
|
||||
dest: "{{ remote_tmp_dir }}/archive_exclude_paths.{{ format }}"
|
||||
format: "{{ format }}"
|
||||
register: archive_excluded_paths
|
||||
|
||||
- name: Assert that excluded paths do not influence archive root - exclude path ({{ format }})
|
||||
assert:
|
||||
that:
|
||||
- archive_excluded_paths.arcroot != remote_tmp_dir
|
||||
|
||||
- name: Remove archive - exclude path ({{ format }})
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/archive_exclude_paths.{{ format }}"
|
||||
state: absent
|
||||
@@ -0,0 +1,144 @@
|
||||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
- name: Archive - file content idempotency ({{ format }})
|
||||
archive:
|
||||
path: "{{ remote_tmp_dir }}/*.txt"
|
||||
dest: "{{ remote_tmp_dir }}/archive_file_content_idempotency.{{ format }}"
|
||||
format: "{{ format }}"
|
||||
register: file_content_idempotency_before
|
||||
|
||||
- name: Modify file - file content idempotency ({{ format }})
|
||||
lineinfile:
|
||||
line: bar.txt
|
||||
regexp: "^foo.txt$"
|
||||
path: "{{ remote_tmp_dir }}/foo.txt"
|
||||
|
||||
- name: Archive second time - file content idempotency ({{ format }})
|
||||
archive:
|
||||
path: "{{ remote_tmp_dir }}/*.txt"
|
||||
dest: "{{ remote_tmp_dir }}/archive_file_content_idempotency.{{ format }}"
|
||||
format: "{{ format }}"
|
||||
register: file_content_idempotency_after
|
||||
|
||||
- name: Assert task status is changed - file content idempotency ({{ format }})
|
||||
assert:
|
||||
that:
|
||||
- file_content_idempotency_after is changed
|
||||
# Only ``zip`` archives are guaranteed to compare file content checksums rather than header checksums
|
||||
when: "format == 'zip'"
|
||||
|
||||
- name: Remove archive - file content idempotency ({{ format }})
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/archive_file_content_idempotency.{{ format }}"
|
||||
state: absent
|
||||
|
||||
- name: Modify file back - file content idempotency ({{ format }})
|
||||
lineinfile:
|
||||
line: foo.txt
|
||||
regexp: "^bar.txt$"
|
||||
path: "{{ remote_tmp_dir }}/foo.txt"
|
||||
|
||||
- name: Archive - file name idempotency ({{ format }})
|
||||
archive:
|
||||
path: "{{ remote_tmp_dir }}/*.txt"
|
||||
dest: "{{ remote_tmp_dir }}/archive_file_name_idempotency.{{ format }}"
|
||||
format: "{{ format }}"
|
||||
register: file_name_idempotency_before
|
||||
|
||||
- name: Rename file - file name idempotency ({{ format }})
|
||||
command: "mv {{ remote_tmp_dir }}/foo.txt {{ remote_tmp_dir }}/fii.txt"
|
||||
|
||||
- name: Archive again - file name idempotency ({{ format }})
|
||||
archive:
|
||||
path: "{{ remote_tmp_dir }}/*.txt"
|
||||
dest: "{{ remote_tmp_dir }}/archive_file_name_idempotency.{{ format }}"
|
||||
format: "{{ format }}"
|
||||
register: file_name_idempotency_after
|
||||
|
||||
- name: Check task status - file name idempotency ({{ format }})
|
||||
assert:
|
||||
that:
|
||||
- file_name_idempotency_after is changed
|
||||
|
||||
- name: Remove archive - file name idempotency ({{ format }})
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/archive_file_name_idempotency.{{ format }}"
|
||||
state: absent
|
||||
|
||||
- name: Rename file back - file name idempotency ({{ format }})
|
||||
command: "mv {{ remote_tmp_dir }}/fii.txt {{ remote_tmp_dir }}/foo.txt"
|
||||
|
||||
- name: Archive - single file content idempotency ({{ format }})
|
||||
archive:
|
||||
path: "{{ remote_tmp_dir }}/foo.txt"
|
||||
dest: "{{ remote_tmp_dir }}/archive_single_file_content_idempotency.{{ format }}"
|
||||
format: "{{ format }}"
|
||||
register: single_file_content_idempotency_before
|
||||
|
||||
- name: Modify file - single file content idempotency ({{ format }})
|
||||
lineinfile:
|
||||
line: bar.txt
|
||||
regexp: "^foo.txt$"
|
||||
path: "{{ remote_tmp_dir }}/foo.txt"
|
||||
|
||||
- name: Archive second time - single file content idempotency ({{ format }})
|
||||
archive:
|
||||
path: "{{ remote_tmp_dir }}/foo.txt"
|
||||
dest: "{{ remote_tmp_dir }}/archive_single_file_content_idempotency.{{ format }}"
|
||||
format: "{{ format }}"
|
||||
register: single_file_content_idempotency_after
|
||||
|
||||
- name: Assert task status is changed - single file content idempotency ({{ format }})
|
||||
assert:
|
||||
that:
|
||||
- single_file_content_idempotency_after is changed
|
||||
# ``tar`` archives are not guaranteed to identify changes to file content if the file meta properties are unchanged.
|
||||
when: "format != 'tar'"
|
||||
|
||||
- name: Remove archive - single file content idempotency ({{ format }})
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/archive_single_file_content_idempotency.{{ format }}"
|
||||
state: absent
|
||||
|
||||
- name: Modify file back - single file content idempotency ({{ format }})
|
||||
lineinfile:
|
||||
line: foo.txt
|
||||
regexp: "^bar.txt$"
|
||||
path: "{{ remote_tmp_dir }}/foo.txt"
|
||||
|
||||
- name: Archive - single file name idempotency ({{ format }})
|
||||
archive:
|
||||
path: "{{ remote_tmp_dir }}/foo.txt"
|
||||
dest: "{{ remote_tmp_dir }}/archive_single_file_name_idempotency.{{ format }}"
|
||||
format: "{{ format }}"
|
||||
register: single_file_name_idempotency_before
|
||||
|
||||
- name: Rename file - single file name idempotency ({{ format }})
|
||||
command: "mv {{ remote_tmp_dir }}/foo.txt {{ remote_tmp_dir }}/fii.txt"
|
||||
|
||||
- name: Archive again - single file name idempotency ({{ format }})
|
||||
archive:
|
||||
path: "{{ remote_tmp_dir }}/fii.txt"
|
||||
dest: "{{ remote_tmp_dir }}/archive_single_file_name_idempotency.{{ format }}"
|
||||
format: "{{ format }}"
|
||||
register: single_file_name_idempotency_after
|
||||
|
||||
|
||||
# The gz, bz2, and xz formats do not store the original file name
|
||||
# so it is not possible to identify a change in this scenario.
|
||||
- name: Check task status - single file name idempotency ({{ format }})
|
||||
assert:
|
||||
that:
|
||||
- single_file_name_idempotency_after is changed
|
||||
when: "format in ('tar', 'zip')"
|
||||
|
||||
- name: Remove archive - single file name idempotency ({{ format }})
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/archive_single_file_name_idempotency.{{ format }}"
|
||||
state: absent
|
||||
|
||||
- name: Rename file back - single file name idempotency ({{ format }})
|
||||
command: "mv {{ remote_tmp_dir }}/fii.txt {{ remote_tmp_dir }}/foo.txt"
|
||||
@@ -0,0 +1,211 @@
|
||||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
- name: Archive - remove source files ({{ format }})
|
||||
archive:
|
||||
path: "{{ remote_tmp_dir }}/*.txt"
|
||||
dest: "{{ remote_tmp_dir }}/archive_remove_source_files.{{ format }}"
|
||||
format: "{{ format }}"
|
||||
remove: yes
|
||||
register: archive_remove_source_files
|
||||
|
||||
- name: Verify archive exists - remove source files ({{ format }})
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/archive_remove_source_files.{{ format }}"
|
||||
state: file
|
||||
|
||||
- name: Verify all files were archived - remove source files ({{ format }})
|
||||
assert:
|
||||
that:
|
||||
- archive_remove_source_files is changed
|
||||
- "{{ archive_remove_source_files.archived | length }} == 3"
|
||||
|
||||
- name: Remove Archive - remove source files ({{ format }})
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/archive_remove_source_files.{{ format }}"
|
||||
state: absent
|
||||
|
||||
- name: Assert that source files were removed - remove source files ({{ format }})
|
||||
assert:
|
||||
that:
|
||||
- "'{{ remote_tmp_dir }}/{{ item }}' is not exists"
|
||||
with_items:
|
||||
- foo.txt
|
||||
- bar.txt
|
||||
- empty.txt
|
||||
|
||||
- name: Copy source files - remove source directory ({{ format }})
|
||||
copy:
|
||||
src: "{{ item }}"
|
||||
dest: "{{ remote_tmp_dir }}/{{ item }}"
|
||||
with_items:
|
||||
- foo.txt
|
||||
- bar.txt
|
||||
- empty.txt
|
||||
|
||||
- name: Create temporary directory - remove source directory ({{ format }})
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/tmpdir"
|
||||
state: directory
|
||||
|
||||
- name: Copy source files to temporary directory - remove source directory ({{ format }})
|
||||
copy:
|
||||
src: "{{ item }}"
|
||||
dest: "{{ remote_tmp_dir }}/tmpdir/{{ item }}"
|
||||
with_items:
|
||||
- foo.txt
|
||||
- bar.txt
|
||||
- empty.txt
|
||||
|
||||
- name: Archive - remove source directory ({{ format }})
|
||||
archive:
|
||||
path: "{{ remote_tmp_dir }}/tmpdir"
|
||||
dest: "{{ remote_tmp_dir }}/archive_remove_source_directory.{{ format }}"
|
||||
format: "{{ format }}"
|
||||
remove: yes
|
||||
register: archive_remove_source_directory
|
||||
|
||||
- name: Verify archive exists - remove source directory ({{ format }})
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/archive_remove_source_directory.{{ format }}"
|
||||
state: file
|
||||
|
||||
- name: Verify archive contains all files - remove source directory ({{ format }})
|
||||
assert:
|
||||
that:
|
||||
- archive_remove_source_directory is changed
|
||||
- "{{ archive_remove_source_directory.archived | length }} == 3"
|
||||
|
||||
- name: Remove archive - remove source directory ({{ format }})
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/archive_remove_source_directory.{{ format }}"
|
||||
state: absent
|
||||
|
||||
- name: Verify source directory was removed - remove source directory ({{ format }})
|
||||
assert:
|
||||
that:
|
||||
- "'{{ remote_tmp_dir }}/tmpdir' is not exists"
|
||||
|
||||
- name: Create temporary directory - remove source excluding path ({{ format }})
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/tmpdir"
|
||||
state: directory
|
||||
|
||||
- name: Copy source files to temporary directory - remove source excluding path ({{ format }})
|
||||
copy:
|
||||
src: "{{ item }}"
|
||||
dest: "{{ remote_tmp_dir }}/tmpdir/{{ item }}"
|
||||
with_items:
|
||||
- foo.txt
|
||||
- bar.txt
|
||||
- empty.txt
|
||||
|
||||
- name: Archive - remove source excluding path ({{ format }})
|
||||
archive:
|
||||
path: "{{ remote_tmp_dir }}/tmpdir/*"
|
||||
dest: "{{ remote_tmp_dir }}/archive_remove_source_excluding_path.{{ format }}"
|
||||
format: "{{ format }}"
|
||||
remove: yes
|
||||
exclude_path: "{{ remote_tmp_dir }}/tmpdir/empty.txt"
|
||||
register: archive_remove_source_excluding_path
|
||||
|
||||
- name: Verify archive exists - remove source excluding path ({{ format }})
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/archive_remove_source_excluding_path.{{ format }}"
|
||||
state: file
|
||||
|
||||
- name: Verify all files except excluded are archived - remove source excluding path ({{ format }})
|
||||
assert:
|
||||
that:
|
||||
- archive_remove_source_excluding_path is changed
|
||||
- "{{ archive_remove_source_excluding_path.archived | length }} == 2"
|
||||
|
||||
- name: Remove archive - remove source excluding path ({{ format }})
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/archive_remove_source_excluding_path.{{ format }}"
|
||||
state: absent
|
||||
|
||||
- name: Verify that excluded file still exists - remove source excluding path ({{ format }})
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/tmpdir/empty.txt"
|
||||
state: file
|
||||
|
||||
- name: Copy source files to temporary directory - remove source excluding sub path ({{ format }})
|
||||
copy:
|
||||
src: "{{ item }}"
|
||||
dest: "{{ remote_tmp_dir }}/tmpdir/{{ item }}"
|
||||
with_items:
|
||||
- foo.txt
|
||||
- bar.txt
|
||||
- empty.txt
|
||||
- sub
|
||||
- sub/subfile.txt
|
||||
|
||||
- name: Archive - remove source excluding sub path ({{ format }})
|
||||
archive:
|
||||
path:
|
||||
- "{{ remote_tmp_dir }}/tmpdir/*.txt"
|
||||
- "{{ remote_tmp_dir }}/tmpdir/sub/*"
|
||||
dest: "{{ remote_tmp_dir }}/archive_remove_source_excluding_sub_path.{{ format }}"
|
||||
format: "{{ format }}"
|
||||
remove: yes
|
||||
exclude_path: "{{ remote_tmp_dir }}/tmpdir/sub/subfile.txt"
|
||||
register: archive_remove_source_excluding_sub_path
|
||||
|
||||
- name: Verify archive exists - remove source excluding sub path ({{ format }})
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/archive_remove_source_excluding_sub_path.{{ format }}"
|
||||
state: file
|
||||
|
||||
- name: Remove archive - remove source excluding sub path ({{ format }})
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/archive_remove_source_excluding_sub_path.{{ format }}"
|
||||
state: absent
|
||||
|
||||
- name: Verify that sub path still exists - remove source excluding sub path ({{ format }})
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/tmpdir/sub/subfile.txt"
|
||||
state: file
|
||||
|
||||
- name: Copy source files to temporary directory - remove source with nested paths ({{ format }})
|
||||
copy:
|
||||
src: "{{ item }}"
|
||||
dest: "{{ remote_tmp_dir }}/tmpdir/{{ item }}"
|
||||
with_items:
|
||||
- foo.txt
|
||||
- bar.txt
|
||||
- empty.txt
|
||||
- sub
|
||||
- sub/subfile.txt
|
||||
|
||||
- name: Archive - remove source with nested paths ({{ format }})
|
||||
archive:
|
||||
path: "{{ remote_tmp_dir }}/tmpdir/"
|
||||
dest: "{{ remote_tmp_dir }}/archive_remove_source_nested_paths.{{ format }}"
|
||||
format: "{{ format }}"
|
||||
remove: yes
|
||||
register: archive_remove_nested_paths
|
||||
|
||||
- name: Verify archive exists - remove source with nested paths ({{ format }})
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/archive_remove_source_nested_paths.{{ format }}"
|
||||
state: file
|
||||
|
||||
- name: Verify source files were removed - remove source with nested paths ({{ format }})
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/tmpdir"
|
||||
state: absent
|
||||
register: archive_remove_nested_paths_status
|
||||
|
||||
- name: Assert tasks status - remove source with nested paths ({{ format }})
|
||||
assert:
|
||||
that:
|
||||
- archive_remove_nested_paths is success
|
||||
- archive_remove_nested_paths_status is not changed
|
||||
|
||||
- name: Remove archive - remove source with nested paths ({{ format }})
|
||||
file:
|
||||
path: "{{ remote_tmp_dir }}/archive_remove_source_nested_paths.{{ format }}"
|
||||
state: absent
|
||||
Reference in New Issue
Block a user