path-is-synced

Example:

# Rsync a folder recursively.
- path-is-synced:
    src: /tmp/source
    dest: /tmp/dest
    delete_on_dest: true

Description

Make sure a file or folder is synced between two locations.

This does also create the remote owner/group if necessary.

For this frecklet, the “local host” is the host the synchronize task originates on, and the “destination host” is the host synchronize is connecting to.

Variables

Name Type Default Description

dest

string --

Path on the target host that will be synchronized to the destination.

Examples: - /tmp/freckles/dest - rsync://dev.frkl.io/tmp/freckles/dest Required

src

string --

Path on the source host that will be synchronized to the destination.

Examples: - /tmp/freckles/src - rsync://dev.frkl.io/tmp/freckles/src Required

become

boolean False

whether to use root permissions to do the download/chown of target

delete_on_dest

boolean False

Whether to delete the files on 'dest' that don't exist on the 'src'.

group

string --

the group of the dest folder/file

mode

string --

The permissions of the folder.

owner

string --

the owner of the dest folder/file

Examples

Example 1

Rsync a folder recursively.

Code
- path-is-synced:
    src: /tmp/source
    dest: /tmp/dest
    delete_on_dest: true
Description

Ensure folder /tmp/source is synced to /tmp/dest. Delete files on /tmp/dest if they don't exist in the source folder.

Code

doc:
  short_help: Make sure a file or folder is synced between two locations.
  help: |
    Make sure a file or folder is synced between two locations.

    This does also create the remote owner/group if necessary.

    For this frecklet, the “local host” is the host the synchronize task originates on, and the “destination host” is the host synchronize is connecting to.
  examples:
  - title: Rsync a folder recursively.
    desc: |
      Ensure folder ``/tmp/source`` is synced to ``/tmp/dest``. Delete files on ``/tmp/dest`` if they don't exist in the source folder.
    vars:
      src: /tmp/source
      dest: /tmp/dest
      delete_on_dest: true

args:
  src:
    doc:
      short_help: the host and path of the source
      help: |
        Path on the source host that will be synchronized to the destination.

        Examples:
          - /tmp/freckles/src
          - rsync://dev.frkl.io/tmp/freckles/src

    type: string
    empty: false
    required: true
    cli:
      metavar: PATH
  dest:
    doc:
      short_help: the host and path of the target
      help: |
        Path on the target host that will be synchronized to the destination.

        Examples:
          - /tmp/freckles/dest
          - rsync://dev.frkl.io/tmp/freckles/dest
    type: string
    empty: false
    required: true
    cli:
      metavar: PATH
  owner:
    doc:
      short_help: the owner of the dest folder/file
    type: string
    required: false
    cli:
      metavar: USER
  group:
    doc:
      short_help: the group of the dest folder/file
    type: string
    required: false
    cli:
      metavar: GROUP
  become:
    doc:
      short_help: whether to use root permissions to do the download/chown of target
    type: boolean
    required: false
    default: false
    cli:
      is_flag: true
  mode:
    doc:
      short_help: The permissions of the folder.
    type: string
    required: false
    cli:
      metavar: MODE
  delete_on_dest:
    doc:
      short_help: Whether to delete the files on 'dest' that don't exist on the 'src'.
    type: boolean
    required: false
    default: false
    cli:
      metavar: PATH
      show_default: true

meta:
  requirements:
  - rsync installed on both source and target host
  tags:
  - filesystem
  - file
  - sync
  - featured-frecklecutable

frecklets:
- task:
    become: '{{:: become ::}}'
  frecklet:
    name: synchronize
    type: ansible-module
    properties:
      idempotent: true
      elevated: '{{:: become ::}}'
    desc:
      short: "synchronize '{{:: src ::}}' -> '{{:: dest ::}}'"
      long: |
        Synchronize path '{{:: src ::}}' to '{{:: dest ::}}' (recursively if the source is a folder).

        {%:: if delete_on_dest ::%}Delete files on '{{:: dest ::}}' that don't exist in the source folder.{%:: endif ::%}
      references:
        "'synchronize' Ansible module": https://docs.ansible.com/ansible/latest/modules/synchronize_module.html
  vars:
    src: '{{:: src ::}}'
    dest: '{{:: dest ::}}'
    delete: '{{:: delete_on_dest ::}}'
    recursive: true

- path-attributes:
    frecklet::skip: '{{:: owner | true_if_all_empty(group, mode) ::}}'
    path: '{{:: dest ::}}'
    owner: '{{:: owner ::}}'
    group: '{{:: group ::}}'
    mode: '{{:: mode ::}}'
frecklecute path-is-synced --help

Usage: frecklecute path-is-synced [OPTIONS]

  Make sure a file or folder is synced between two locations.

  This does also create the remote owner/group if necessary.

  For this frecklet, the “local host” is the host the synchronize task
  originates on, and the “destination host” is the host synchronize is
  connecting to.

Options:
  --dest PATH                     the host and path of the target  [required]
  --src PATH                      the host and path of the source  [required]
  --become / --no-become          whether to use root permissions to do the
                                  download/chown of target
  --delete-on-dest / --no-delete-on-dest
                                  Whether to delete the files on 'dest' that
                                  don't exist on the 'src'.
  --group GROUP                   the group of the dest folder/file
  --mode MODE                     The permissions of the folder.
  --owner USER                    the owner of the dest folder/file
  --help                          Show this message and exit.
# -*- coding: utf-8 -*-


#
# module path: pycklets.path_is_synced.PathIsSynced
#


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

@dataclass
class PathIsSynced(AutoPycklet):
    """Make sure a file or folder is synced between two locations.

     This does also create the remote owner/group if necessary.

     For this frecklet, the “local host” is the host the synchronize task originates on, and the “destination host” is the host synchronize is connecting to.

       Args:
         become: whether to use root permissions to do the download/chown of target
         delete_on_dest: Whether to delete the files on 'dest' that don't exist on the 'src'.
         dest: the host and path of the target
         group: the group of the dest folder/file
         mode: The permissions of the folder.
         owner: the owner of the dest folder/file
         src: the host and path of the source

    """

    FRECKLET_ID = "path-is-synced"

    become: bool = None
    delete_on_dest: bool = None
    dest: str = None
    group: str = None
    mode: str = None
    owner: str = None
    src: str = None


    def __post_init__(self):
        super(PathIsSynced, self).__init__(var_names=["become", "delete_on_dest", "dest", "group", "mode", "owner", "src"])


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


#
# module path: pycklets.path_is_synced.PathIsSynced
#


from pyckles import AutoPycklet

class PathIsSynced(AutoPycklet):
    """Make sure a file or folder is synced between two locations.

     This does also create the remote owner/group if necessary.

     For this frecklet, the “local host” is the host the synchronize task originates on, and the “destination host” is the host synchronize is connecting to.

       Args:
         become: whether to use root permissions to do the download/chown of target
         delete_on_dest: Whether to delete the files on 'dest' that don't exist on the 'src'.
         dest: the host and path of the target
         group: the group of the dest folder/file
         mode: The permissions of the folder.
         owner: the owner of the dest folder/file
         src: the host and path of the source

    """

    FRECKLET_ID = "path-is-synced"

    def __init__(self, become=None, delete_on_dest=None, dest=None, group=None, mode=None, owner=None, src=None):

        super(PathIsSynced, self).__init__(var_names=["become", "delete_on_dest", "dest", "group", "mode", "owner", "src"])
        self._become = become
        self._delete_on_dest = delete_on_dest
        self._dest = dest
        self._group = group
        self._mode = mode
        self._owner = owner
        self._src = src

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

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

    @property
    def delete_on_dest(self):
        return self._delete_on_dest

    @delete_on_dest.setter
    def delete_on_dest(self, delete_on_dest):
        self._delete_on_dest = delete_on_dest

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

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

    @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 src(self):
        return self._src

    @src.setter
    def src(self, src):
        self._src = src



frecklet_class = PathIsSynced