mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-05 18:20:30 -07:00
* adds simple implementation of `decompress` module * adds simple test, fixes src and dest arg types * minor refactoring * adds support for common file operations adds integration test for gz decompressing * makes tests parametrized to test all supported compression formats * checks that target file exists * writes to decompressed file now uses atomic_move * adds idempotency for decompression * refactoring, removed classes * adds support for check mode * adds check for destination file. If it exists and it is a directory, the module returns error * refactoring, moves code to a class. Also, simplifies tests (now only tests related to the module core functionality run as parametrized, tests for idempotency and check mode run only for one format) * adds 'remove' parameter that deletes original compressed file after decompression * adds documentation * fixes bug with 'remove' parameter in check mode * makes dest argument not required. Dest filename now can be produced from the src filename * adds dest to output * updates the documentation, adds "RETURN" block * fixes test * adds support for python2 * removes some of the test files that can be generated during testing. Adds copyright header to test files * adds maintainer * apply minor suggestions from code review Co-authored-by: Felix Fontein <felix@fontein.de> * fixes code review comments (idempotency issue with non existing src, existing dest and remove=true; fixes the issue and adds test) * refactors the module to use ModuleHelper * refactors lzma dependency manual check to use 'deps.validate' * minor fix * removes registered handlers check * minor refactoring * adds aliases * changes setup for tests * tests: ignores macos and fixes tests for FreeBSD * tests: reverts ignore for macos and fixes issue with centos7 * tests: adds liblzma dependency for python2 * tests: adds backports.lzma * fixes bz2 decompression for python2 * tests: install xz for osx * tests: install xz for osx (2) * fixes code review comments --------- Co-authored-by: Felix Fontein <felix@fontein.de>
115 lines
3 KiB
YAML
115 lines
3 KiB
YAML
---
|
|
# 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: Copy test files
|
|
copy:
|
|
src: "files/"
|
|
dest: "{{ remote_tmp_dir }}"
|
|
|
|
- name: Get original file stat
|
|
stat:
|
|
path: "{{ remote_tmp_dir }}/file.txt"
|
|
register: orig_file_stat
|
|
|
|
- name: Set supported formats
|
|
set_fact:
|
|
formats:
|
|
- bz2
|
|
- gz
|
|
- xz
|
|
|
|
- name: Ensure xz is present to create compressed files (not Debian)
|
|
package:
|
|
name:
|
|
- xz
|
|
- bzip2
|
|
state: latest
|
|
when:
|
|
- ansible_system != 'FreeBSD'
|
|
- ansible_os_family != 'Darwin'
|
|
- ansible_os_family != 'Debian'
|
|
|
|
- name: Ensure xz is present to create compressed files (Debian)
|
|
package:
|
|
name: xz-utils
|
|
state: latest
|
|
when: ansible_os_family == 'Debian'
|
|
|
|
- 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: false
|
|
become: true
|
|
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_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'
|
|
notify:
|
|
- delete backports.lzma
|
|
|
|
- name: Generate compressed files
|
|
shell: |
|
|
gzip < {{ item }} > {{ item }}.gz
|
|
bzip2 < {{ item }} > {{ item }}.bz2
|
|
xz < {{ item }} > {{ item }}.xz
|
|
loop:
|
|
- "{{ remote_tmp_dir }}/file.txt"
|
|
- "{{ remote_tmp_dir }}/second_file.txt"
|
|
|
|
# Run tests
|
|
- name: Run core tests
|
|
block:
|
|
- include_tasks: core.yml
|
|
loop: "{{ formats }}"
|
|
loop_control:
|
|
loop_var: format
|
|
- import_tasks: cleanup.yml
|
|
|
|
|
|
- name: Run idempotency and check mode tests
|
|
block:
|
|
- import_tasks: misc.yml
|
|
- import_tasks: cleanup.yml
|
|
|
|
- name: Run tests for destination file
|
|
block:
|
|
- import_tasks: dest.yml
|
|
- import_tasks: cleanup.yml
|