archive: Add support for xz (#34110)

* Add support for xz format on archive module

Fixes #34037
Fixes #34119

Signed-off-by: Alberto Murillo <albertomurillosilva@gmail.com>
This commit is contained in:
Alberto Murillo 2018-01-22 06:33:07 -06:00 committed by ansibot
commit 2018a61489
2 changed files with 143 additions and 6 deletions

View file

@ -25,6 +25,44 @@
apt: name=zip state=latest
when: ansible_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 }}"
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'
- name: prep our file
copy: src={{ item }} dest={{output_dir}}/{{ item }}
with_items:
@ -81,13 +119,32 @@
- name: verify that the files archived
file: path={{output_dir}}/archive_01.bz2 state=file
- name: check if zip file exists
- name: check if bzip file exists
assert:
that:
- "{{ archive_bz2_result_01.changed }}"
- "{{ 'archived' in archive_bz2_result_01 }}"
- "{{ archive_bz2_result_01['archived'] | length }} == 2"
- name: archive using xz
archive:
path: "{{ output_dir }}/*.txt"
dest: "{{ output_dir }}/archive_01.xz"
format: xz
register: archive_xz_result_01
- debug: msg="{{ archive_xz_result_01 }}"
- name: verify that the files archived
file: path={{output_dir}}/archive_01.xz state=file
- name: check if xz file exists
assert:
that:
- "{{ archive_xz_result_01.changed }}"
- "{{ 'archived' in archive_xz_result_01 }}"
- "{{ archive_xz_result_01['archived'] | length }} == 2"
- name: archive and set mode to 0600
archive:
path: "{{ output_dir }}/*.txt"
@ -164,6 +221,30 @@
- name: remove our bz2
file: path="{{ output_dir }}/archive_02.bz2" state=absent
- name: archive and set mode to 0600
archive:
path: "{{ output_dir }}/*.txt"
dest: "{{ output_dir }}/archive_02.xz"
format: xz
mode: "u+rwX,g-rwx,o-rwx"
register: archive_xz_result_02
- name: Test that the file modes were changed
stat:
path: "{{ output_dir }}/archive_02.xz"
register: archive_02_xz_stat
- name: Test that the file modes were changed
assert:
that:
- "archive_02_xz_stat.changed == False"
- "archive_02_xz_stat.stat.mode == '0600'"
- "'archived' in archive_xz_result_02"
- "{{ archive_xz_result_02['archived']| length}} == 2"
- name: remove our xz
file: path="{{ output_dir }}/archive_02.xz" state=absent
- name: test that gz archive that contains non-ascii filenames
archive:
path: "{{ output_dir }}/*.txt"
@ -206,6 +287,27 @@
- name: remove nonascii test
file: path="{{ output_dir }}/test-archive-nonascii-くらとみ.bz2" state=absent
- name: test that xz archive that contains non-ascii filenames
archive:
path: "{{ output_dir }}/*.txt"
dest: "{{ output_dir }}/test-archive-nonascii-くらとみ.xz"
format: xz
register: nonascii_result_1
- name: Check that file is really there
stat:
path: "{{ output_dir }}/test-archive-nonascii-くらとみ.xz"
register: nonascii_stat_1
- name: Assert that nonascii tests succeeded
assert:
that:
- "nonascii_result_1.changed == true"
- "nonascii_stat_1.stat.exists == true"
- name: remove nonascii test
file: path="{{ output_dir }}/test-archive-nonascii-くらとみ.xz" state=absent
- name: test that zip archive that contains non-ascii filenames
archive:
path: "{{ output_dir }}/*.txt"