path-archived

Example:

# Archive a folder.
- path-archived:
    path: /tmp/folder_to_archive/*
    mode: '0700'
    owner: freckles
    dest: /tmp/archive.tar.gz

Description

Archives a file or folder.

Resources

Variables

Name Type Default Description

dest

string --

The file name of the destination archive. Required

path

string --

Remote absolute path or glob of the file or files to compress or archive. Required

become

boolean False

Whether to use root permissions to archive the path.

exclude_path

string --

Path or glob to exclude from the archive.

format

string gz

The type of compression to use.

group

string --

The group of the archive file.

mode

string --

The permissions of the archive file.

owner

string --

The owner of the archive file.

parent_dir_mode

string --

The permissions of the archive parent directory.

Examples

Example 1

Archive a folder.

Code
- path-archived:
    path: /tmp/folder_to_archive/*
    mode: '0700'
    owner: freckles
    dest: /tmp/archive.tar.gz
Description

Archive the contents of folder '/tmp/folder_to_archive' into the archive '/tmp/archive.tar.gz'. Set the archive file mode to '0700' and its owner (which will be created if it doesn't exist yet) to 'freckles'.

Code

doc:
  short_help: Archives a file or folder.
  references:
    "'archive' Ansible module documentation": https://docs.ansible.com/ansible/latest/modules/archive_module.html
  examples:
  - title: Archive a folder.
    desc: |
      Archive the contents of folder '/tmp/folder_to_archive' into the archive '/tmp/archive.tar.gz'. Set the archive file mode
      to '0700' and its owner (which will be created if it doesn't exist yet) to 'freckles'.
    vars:
      path: /tmp/folder_to_archive/*
      mode: '0700'
      owner: freckles
      dest: /tmp/archive.tar.gz

args:
  path:
    doc:
      short_help: Remote absolute path or glob of the file or files to compress or
        archive.
    type: string
    required: true
  dest:
    doc:
      short_help: The file name of the destination archive.
    type: string
    required: true
  exclude_path:
    doc:
      short_help: Path or glob to exclude from the archive.
    type: string
    required: false
  format:
    doc:
      short_help: The type of compression to use.
    type: string
    required: false
    default: gz
    allowed:
    - bz2
    - gz
    - tar
    - xz
    - zip
  owner:
    doc:
      short_help: The owner of the archive file.
    type: string
    required: false
    cli:
      metavar: USER
  group:
    doc:
      short_help: The group of the archive file.
    type: string
    required: false
    cli:
      metavar: GROUP
  mode:
    doc:
      short_help: The permissions of the archive file.
    type: string
    required: false
    cli:
      metavar: MODE
  parent_dir_mode:
    doc:
      short_help: The permissions of the archive parent directory.
    type: string
    required: false
    cli:
      metavar: MODE
  become:
    doc:
      short_help: Whether to use root permissions to archive the path.
    type: boolean
    required: false
    default: false


frecklets:
- user-exists:
    frecklet::skip: "{{:: owner | true_if_empty_or('root') ::}}"
    name: '{{:: owner ::}}'
    group: '{{:: group ::}}'
#      system_user: "{{:: system_user ::}}"
- parent-folder-exists:
    path: '{{:: dest ::}}'
    owner: '{{:: owner  ::}}'
    group: '{{:: group ::}}'
    mode: '{{:: parent_dir_mode ::}}'
- frecklet:
    name: archive
    type: ansible-module
    desc:
      short: 'archive path: {{:: path ::}} -> {{:: dest ::}}'
      long: |
        Create archive '{{:: dest ::}}' (archive format: {{:: format ::}}) from contents of file/folder/glob '{{:: path ::}}'. {%:: if exclude_path ::%}Exclude paths that match '{{:: exclude_path ::}}' from archive.{%:: endif ::%}

        {%:: if group ::%}Set the group of the archive to be '{{:: group ::}}'. {%:: endif ::%}{%:: if owner ::%}Set the owner of the archive to be '{{:: owner ::}}'.{%:: endif ::%} {%:: if mode ::%}Set the mode of the archive to: '{{:: mode ::}}'.{%:: endif ::%}
      references:
        "'archive' Ansible module": https://docs.ansible.com/ansible/latest/modules/archive_module.html
    properties:
      idempotent: true
      elevated: '{{:: become ::}}'
      internet: false
  task:
    become: '{{:: become ::}}'
  vars:
    dest: '{{:: dest ::}}'
    path: '{{:: path ::}}'
    exclude_path: '{{:: exclude_path ::}}'
    format: '{{:: format ::}}'
    owner: '{{:: owner ::}}'
    group: '{{:: group ::}}'
    mode: '{{:: mode ::}}'
frecklecute path-archived --help

Usage: frecklecute path-archived [OPTIONS]

  Archives a file or folder.

Options:
  --dest DEST                  The file name of the destination archive.
                               [required]
  --path PATH                  Remote absolute path or glob of the file or
                               files to compress or archive.  [required]
  --become / --no-become       Whether to use root permissions to archive the
                               path.
  --exclude-path EXCLUDE_PATH  Path or glob to exclude from the archive.
  --format FORMAT              The type of compression to use.
  --group GROUP                The group of the archive file.
  --mode MODE                  The permissions of the archive file.
  --owner USER                 The owner of the archive file.
  --parent-dir-mode MODE       The permissions of the archive parent
                               directory.
  --help                       Show this message and exit.
# -*- coding: utf-8 -*-


#
# module path: pycklets.path_archived.PathArchived
#


from dataclasses import dataclass
from pyckles import AutoPycklet
from typing import *    # noqa

@dataclass
class PathArchived(AutoPycklet):
    """Archives a file or folder.

       Args:
         become: Whether to use root permissions to archive the path.
         dest: The file name of the destination archive.
         exclude_path: Path or glob to exclude from the archive.
         format: The type of compression to use.
         group: The group of the archive file.
         mode: The permissions of the archive file.
         owner: The owner of the archive file.
         parent_dir_mode: The permissions of the archive parent directory.
         path: Remote absolute path or glob of the file or files to compress or archive.

    """

    FRECKLET_ID = "path-archived"

    become: bool = None
    dest: str = None
    exclude_path: str = None
    format: str = None
    group: str = None
    mode: str = None
    owner: str = None
    parent_dir_mode: str = None
    path: str = None


    def __post_init__(self):
        super(PathArchived, self).__init__(var_names=["become", "dest", "exclude_path", "format", "group", "mode", "owner", "parent_dir_mode", "path"])


frecklet_class = PathArchived
# -*- coding: utf-8 -*-


#
# module path: pycklets.path_archived.PathArchived
#


from pyckles import AutoPycklet

class PathArchived(AutoPycklet):
    """Archives a file or folder.

       Args:
         become: Whether to use root permissions to archive the path.
         dest: The file name of the destination archive.
         exclude_path: Path or glob to exclude from the archive.
         format: The type of compression to use.
         group: The group of the archive file.
         mode: The permissions of the archive file.
         owner: The owner of the archive file.
         parent_dir_mode: The permissions of the archive parent directory.
         path: Remote absolute path or glob of the file or files to compress or archive.

    """

    FRECKLET_ID = "path-archived"

    def __init__(self, become=None, dest=None, exclude_path=None, format="gz", group=None, mode=None, owner=None, parent_dir_mode=None, path=None):

        super(PathArchived, self).__init__(var_names=["become", "dest", "exclude_path", "format", "group", "mode", "owner", "parent_dir_mode", "path"])
        self._become = become
        self._dest = dest
        self._exclude_path = exclude_path
        self._format = format
        self._group = group
        self._mode = mode
        self._owner = owner
        self._parent_dir_mode = parent_dir_mode
        self._path = path

    @property
    def become(self):
        return self._become

    @become.setter
    def become(self, become):
        self._become = become

    @property
    def dest(self):
        return self._dest

    @dest.setter
    def dest(self, dest):
        self._dest = dest

    @property
    def exclude_path(self):
        return self._exclude_path

    @exclude_path.setter
    def exclude_path(self, exclude_path):
        self._exclude_path = exclude_path

    @property
    def format(self):
        return self._format

    @format.setter
    def format(self, format):
        self._format = format

    @property
    def group(self):
        return self._group

    @group.setter
    def group(self, group):
        self._group = group

    @property
    def mode(self):
        return self._mode

    @mode.setter
    def mode(self, mode):
        self._mode = mode

    @property
    def owner(self):
        return self._owner

    @owner.setter
    def owner(self, owner):
        self._owner = owner

    @property
    def parent_dir_mode(self):
        return self._parent_dir_mode

    @parent_dir_mode.setter
    def parent_dir_mode(self, parent_dir_mode):
        self._parent_dir_mode = parent_dir_mode

    @property
    def path(self):
        return self._path

    @path.setter
    def path(self, path):
        self._path = path



frecklet_class = PathArchived