2020-11-19 20:51:16 +01:00
|
|
|
---
|
|
|
|
- name: archive using gz and remove src files
|
|
|
|
archive:
|
2021-09-09 08:10:26 +02:00
|
|
|
path: "{{ remote_tmp_dir }}/*.txt"
|
|
|
|
dest: "{{ remote_tmp_dir }}/archive_remove_01.gz"
|
2020-11-19 20:51:16 +01:00
|
|
|
format: gz
|
|
|
|
remove: yes
|
|
|
|
register: archive_remove_result_01
|
|
|
|
|
|
|
|
- debug: msg="{{ archive_remove_result_01 }}"
|
|
|
|
|
|
|
|
- name: verify that the files archived
|
2021-09-09 08:10:26 +02:00
|
|
|
file: path={{ remote_tmp_dir }}/archive_remove_01.gz state=file
|
2020-11-19 20:51:16 +01:00
|
|
|
|
|
|
|
- name: check if gz file exists and includes all text files and src files has been removed
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "{{ archive_remove_result_01.changed }}"
|
|
|
|
- "{{ 'archived' in archive_remove_result_01 }}"
|
|
|
|
- "{{ archive_remove_result_01['archived'] | length }} == 3"
|
|
|
|
|
|
|
|
- name: remove our gz
|
2021-09-09 08:10:26 +02:00
|
|
|
file: path="{{ remote_tmp_dir }}/archive_remove_01.gz" state=absent
|
2020-11-19 20:51:16 +01:00
|
|
|
|
|
|
|
- name: check if src files has been removed
|
|
|
|
assert:
|
|
|
|
that:
|
2021-09-09 08:10:26 +02:00
|
|
|
- "'{{ remote_tmp_dir }}/{{ item }}' is not exists"
|
2020-11-19 20:51:16 +01:00
|
|
|
with_items:
|
|
|
|
- foo.txt
|
|
|
|
- bar.txt
|
|
|
|
- empty.txt
|
|
|
|
|
|
|
|
- name: prep our files again
|
2021-09-09 08:10:26 +02:00
|
|
|
copy: src={{ item }} dest={{ remote_tmp_dir }}/{{ item }}
|
2020-11-19 20:51:16 +01:00
|
|
|
with_items:
|
|
|
|
- foo.txt
|
|
|
|
- bar.txt
|
|
|
|
- empty.txt
|
|
|
|
|
|
|
|
- name: create a temporary directory to be check if it will be removed
|
|
|
|
file:
|
2021-09-09 08:10:26 +02:00
|
|
|
path: "{{ remote_tmp_dir }}/tmpdir"
|
2020-11-19 20:51:16 +01:00
|
|
|
state: directory
|
|
|
|
|
|
|
|
- name: prep our files in tmpdir
|
2021-09-09 08:10:26 +02:00
|
|
|
copy: src={{ item }} dest={{ remote_tmp_dir }}/tmpdir/{{ item }}
|
2020-11-19 20:51:16 +01:00
|
|
|
with_items:
|
|
|
|
- foo.txt
|
|
|
|
- bar.txt
|
|
|
|
- empty.txt
|
|
|
|
|
|
|
|
- name: archive using gz and remove src directory
|
|
|
|
archive:
|
2021-09-09 08:10:26 +02:00
|
|
|
path: "{{ remote_tmp_dir }}/tmpdir"
|
|
|
|
dest: "{{ remote_tmp_dir }}/archive_remove_02.gz"
|
2020-11-19 20:51:16 +01:00
|
|
|
format: gz
|
|
|
|
remove: yes
|
|
|
|
register: archive_remove_result_02
|
|
|
|
|
|
|
|
- debug: msg="{{ archive_remove_result_02 }}"
|
|
|
|
|
|
|
|
- name: verify that the files archived
|
2021-09-09 08:10:26 +02:00
|
|
|
file: path={{ remote_tmp_dir }}/archive_remove_02.gz state=file
|
2020-11-19 20:51:16 +01:00
|
|
|
|
|
|
|
- name: check if gz file exists and includes all text files
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "{{ archive_remove_result_02.changed }}"
|
|
|
|
- "{{ 'archived' in archive_remove_result_02 }}"
|
|
|
|
- "{{ archive_remove_result_02['archived'] | length }} == 3"
|
|
|
|
|
|
|
|
- name: remove our gz
|
2021-09-09 08:10:26 +02:00
|
|
|
file: path="{{ remote_tmp_dir }}/archive_remove_02.gz" state=absent
|
2020-11-19 20:51:16 +01:00
|
|
|
|
|
|
|
- name: check if src folder has been removed
|
|
|
|
assert:
|
|
|
|
that:
|
2021-09-09 08:10:26 +02:00
|
|
|
- "'{{ remote_tmp_dir }}/tmpdir' is not exists"
|
2020-11-19 20:51:16 +01:00
|
|
|
|
|
|
|
- name: create temporary directory again
|
|
|
|
file:
|
2021-09-09 08:10:26 +02:00
|
|
|
path: "{{ remote_tmp_dir }}/tmpdir"
|
2020-11-19 20:51:16 +01:00
|
|
|
state: directory
|
|
|
|
|
|
|
|
- name: prep our files in tmpdir again
|
2021-09-09 08:10:26 +02:00
|
|
|
copy: src={{ item }} dest={{ remote_tmp_dir }}/tmpdir/{{ item }}
|
2020-11-19 20:51:16 +01:00
|
|
|
with_items:
|
|
|
|
- foo.txt
|
|
|
|
- bar.txt
|
|
|
|
- empty.txt
|
|
|
|
|
|
|
|
- name: archive using gz and remove src directory excluding one file
|
|
|
|
archive:
|
2021-09-09 08:10:26 +02:00
|
|
|
path: "{{ remote_tmp_dir }}/tmpdir/*"
|
|
|
|
dest: "{{ remote_tmp_dir }}/archive_remove_03.gz"
|
2020-11-19 20:51:16 +01:00
|
|
|
format: gz
|
|
|
|
remove: yes
|
2021-09-09 08:10:26 +02:00
|
|
|
exclude_path: "{{ remote_tmp_dir }}/tmpdir/empty.txt"
|
2020-11-19 20:51:16 +01:00
|
|
|
register: archive_remove_result_03
|
|
|
|
|
|
|
|
- debug: msg="{{ archive_remove_result_03 }}"
|
|
|
|
|
|
|
|
- name: verify that the files archived
|
2021-09-09 08:10:26 +02:00
|
|
|
file: path={{ remote_tmp_dir }}/archive_remove_03.gz state=file
|
2020-11-19 20:51:16 +01:00
|
|
|
|
|
|
|
- name: check if gz file exists and includes all text files
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "{{ archive_remove_result_03.changed }}"
|
|
|
|
- "{{ 'archived' in archive_remove_result_03 }}"
|
|
|
|
- "{{ archive_remove_result_03['archived'] | length }} == 2"
|
|
|
|
|
|
|
|
- name: remove our gz
|
2021-09-09 08:10:26 +02:00
|
|
|
file: path="{{ remote_tmp_dir }}/archive_remove_03.gz" state=absent
|
2020-11-19 20:51:16 +01:00
|
|
|
|
|
|
|
- name: verify that excluded file is still present
|
2021-09-09 08:10:26 +02:00
|
|
|
file: path={{ remote_tmp_dir }}/tmpdir/empty.txt state=file
|
2020-11-19 20:51:16 +01:00
|
|
|
|
2021-07-01 07:46:33 +02:00
|
|
|
- name: prep our files in tmpdir again
|
2021-09-09 08:10:26 +02:00
|
|
|
copy: src={{ item }} dest={{ remote_tmp_dir }}/tmpdir/{{ item }}
|
2021-07-01 07:46:33 +02:00
|
|
|
with_items:
|
|
|
|
- foo.txt
|
|
|
|
- bar.txt
|
|
|
|
- empty.txt
|
|
|
|
- sub
|
|
|
|
- sub/subfile.txt
|
|
|
|
|
|
|
|
- name: archive using gz and remove src directory
|
|
|
|
archive:
|
|
|
|
path:
|
2021-09-09 08:10:26 +02:00
|
|
|
- "{{ remote_tmp_dir }}/tmpdir/*.txt"
|
|
|
|
- "{{ remote_tmp_dir }}/tmpdir/sub/*"
|
|
|
|
dest: "{{ remote_tmp_dir }}/archive_remove_04.gz"
|
2021-07-01 07:46:33 +02:00
|
|
|
format: gz
|
|
|
|
remove: yes
|
2021-09-09 08:10:26 +02:00
|
|
|
exclude_path: "{{ remote_tmp_dir }}/tmpdir/sub/subfile.txt"
|
2021-07-01 07:46:33 +02:00
|
|
|
register: archive_remove_result_04
|
|
|
|
|
|
|
|
- debug: msg="{{ archive_remove_result_04 }}"
|
|
|
|
|
|
|
|
- name: verify that the files archived
|
2021-09-09 08:10:26 +02:00
|
|
|
file: path={{ remote_tmp_dir }}/archive_remove_04.gz state=file
|
2021-07-01 07:46:33 +02:00
|
|
|
|
|
|
|
- name: remove our gz
|
2021-09-09 08:10:26 +02:00
|
|
|
file: path="{{ remote_tmp_dir }}/archive_remove_04.gz" state=absent
|
2021-07-01 07:46:33 +02:00
|
|
|
|
|
|
|
- name: verify that excluded sub file is still present
|
2021-09-09 08:10:26 +02:00
|
|
|
file: path={{ remote_tmp_dir }}/tmpdir/sub/subfile.txt state=file
|
2021-07-01 07:46:33 +02:00
|
|
|
|
2021-07-02 21:43:25 +02:00
|
|
|
- name: prep our files in tmpdir again
|
2021-09-09 08:10:26 +02:00
|
|
|
copy: src={{ item }} dest={{ remote_tmp_dir }}/tmpdir/{{ item }}
|
2021-07-02 21:43:25 +02:00
|
|
|
with_items:
|
|
|
|
- foo.txt
|
|
|
|
- bar.txt
|
|
|
|
- empty.txt
|
|
|
|
- sub
|
|
|
|
- sub/subfile.txt
|
|
|
|
|
|
|
|
- name: archive using gz and remove src directory
|
|
|
|
archive:
|
|
|
|
path:
|
2021-09-09 08:10:26 +02:00
|
|
|
- "{{ remote_tmp_dir }}/tmpdir/"
|
|
|
|
dest: "{{ remote_tmp_dir }}/archive_remove_05.gz"
|
2021-07-02 21:43:25 +02:00
|
|
|
format: gz
|
|
|
|
remove: yes
|
2021-09-09 08:10:26 +02:00
|
|
|
exclude_path: "{{ remote_tmp_dir }}/tmpdir/sub/subfile.txt"
|
2021-07-02 21:43:25 +02:00
|
|
|
register: archive_remove_result_05
|
|
|
|
|
|
|
|
- name: verify that the files archived
|
2021-09-09 08:10:26 +02:00
|
|
|
file: path={{ remote_tmp_dir }}/archive_remove_05.gz state=file
|
2021-07-02 21:43:25 +02:00
|
|
|
|
|
|
|
- name: Verify source files were removed
|
2020-11-19 20:51:16 +01:00
|
|
|
file:
|
2021-09-09 08:10:26 +02:00
|
|
|
path: "{{ remote_tmp_dir }}/tmpdir"
|
2020-11-19 20:51:16 +01:00
|
|
|
state: absent
|
2021-07-02 21:43:25 +02:00
|
|
|
register: archive_source_file_removal_05
|
|
|
|
|
|
|
|
- name: Verify that task status is success
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- archive_remove_result_05 is success
|
|
|
|
- archive_source_file_removal_05 is not changed
|
|
|
|
|
|
|
|
- name: remove our gz
|
2021-09-09 08:10:26 +02:00
|
|
|
file: path="{{ remote_tmp_dir }}/archive_remove_05.gz" state=absent
|