Ansible Role: serdigital64.backup.bkp_archive

Purpose

Simplify the extraction of content from file archives.

Supported features in the current version:

  • Uncompress single file archive. (e.g.: installer.xz -> installer)
  • Uncompress single directory archive. (e.g.: application_content.tar.xz -> application_content/)

Archive formats:

  • zip
  • bzip2
  • xz
  • compress
  • tar
  • compressed tar

The bkp_archive Ansible-Role is part of the A:Platform64 project and is available in the backup Ansible-Collection.

Usage

The following example is an Ansible Playbook that includes all the supported features:

use this link if viewing the doc on github

---
- name: "Backup / Archive / Usage example"
  hosts: "localhost"
  gather_facts: true
  vars:
    test_file: "terraform_1.1.2_linux_amd64.zip"
    test_path_download: "/tmp/test_path_download64"
    test_path_open: "/tmp/test_path_open64"

  pre_tasks:
    - name: "Create test paths"
      ansible.builtin.file:
        state: "directory"
        mode: "0700"
        path: "{{ item }}"
      loop:
        - "{{ test_path_download }}"
        - "{{ test_path_open }}"

    - name: "Download test file"
      ansible.builtin.get_url:
        url: "https://releases.hashicorp.com/terraform/1.1.2/{{ test_file }}"
        dest: "{{ test_path_download }}"

  tasks:
    - name: "Example: Extract the terraform CLI from the compressed file archive"
      vars:
        bkp_archive:
          resolve_prereq: true
          deploy: true
          provision: true
        bkp_archive_files:
          - archive:
              path: "{{ test_path_download }}"
              file: "{{ test_file }}"
              keep: false
            content:
              path: "{{ test_path_open }}"
              name: "terraform-cli"
      ansible.builtin.include_role:
        name: "serdigital64.backup.bkp_archive"
...

The playbook can be run by executing:

# Set ANSIBLE_COLLECTIONS_PATHS to the default location. Change as needed.
ANSIBLE_COLLECTIONS_PATHS="${HOME}/.ansible/collections"
ansible-playbook "${ANSIBLE_COLLECTIONS_PATHS}/ansible_collections/serdigital64/backup/playbooks/bkp_archive.yml"

Role Parameters

Actions

  • Use action-parameters to control what tasks are enabled for the role to execute.
  • Parameters should be declared as task level vars as they are intented to be dynamic.
bkp_archive:
  resolve_prereq:
  deploy:
  provision:
bkp_archive_files:
  - archive:
      path:
      file:
      keep:
    content:
      path:
      name:
      access:
        mode:
          file:
          dir:
          setype:
        owner:
        group:
Parameter Required? Type Default Purpose / Value
bkp_archive.resolve_prereq no boolean false Enable automatic resolution of prequisites
bkp_archive.deploy no boolean false Enable installation of required operating system packages
bkp_archive.provision no boolean false Enable processing of archive
bkp_archive_files yes list List of archive files
bkp_archive_files.0.archive yes dictionary File archive definition
bkp_archive_files.0.archive.path yes string Full path to the archive file
bkp_archive_files.0.archive.file yes string File archive name
bkp_archive_files.0.archive.keep no boolean false Keep the archive after opening it?. If not the file is removed
bkp_archive_files.0.content no dictionary Archive content definition
bkp_archive_files.0.content.path yes string Full path where the content is located when not stored in the archive
bkp_archive_files.0.content.name yes string Target name
bkp_archive_files.0.content.access no dictionary Archive content permissions and ownership definition
bkp_archive_files.0.content.access.mode.file no string File permissions (octal) when content is file
bkp_archive_files.0.content.access.mode.dir no string Directory permissions (octal) when content is directory
bkp_archive_files.0.content.access.mode.setype no string SELinux file type
bkp_archive_files.0.content.access.owner no string File owner: user
bkp_archive_files.0.content.access.group no string File owner: group

End State

  • Use end-state parameters to define the target state after role execution.
  • Parameters should be declared in host_vars or group_vars as they are intended to be permanent.
bkp_archive_packages_installed:
Parameter Required? Type Default Purpose / Value
bkp_archive_packages_installed no boolean true Set the package end state

Deployment

OS Compatibility

The operating system compatibility list is defined in the variable: bkp_archive_platforms

Dependencies

  • Ansible Collections:
    • serdigital64.system
      • sys_repository

Prerequisites

The Ansible engine must be already installed and configured for privileged access and remote execution.

In addition the following prerequisites can be automatically solved when running the playbook by setting the role action: resolve_prereq: true

  • Package managers for the target application are installed and enabled.

Installation Procedure

Manually install Ansible Collections from the Ansible Galaxy repository:

ansible-galaxy collection install --upgrade serdigital64.backup

Automatic installation is also available by deploying A:Platform64

Contributing

Help on implementing new features and maintaining the code base is welcomed.

Please see the guidelines for further details.

Author

License

GPL-3.0-or-later