git-repo-synced

Example:

# Clone the 'freckles' git repo into $HOME.
- git-repo-synced:
    repo: https://gitlab.com/freckles-io/freckles.git
    dest: ~/freckles

Description

Clones or pulls a git repository.

Create the group/owner if not available on the system. This does not put the owner into the group if both are specified, so do that before-hand if you need that much control.

This does not install 'git' if it isn't already available and will fail if that's the case.

Variables

Name Type Default Description

dest

string --

The destination path. Required

repo

string --

The source repository. Required

ensure_git

boolean False

Ensure git is installed.

group

string --

The group of the target folder.

owner

string --

The owner of the target folder.

version

string master

The version (tag, branch, hash, ..) to use.

Examples

Example 1

Clone the 'freckles' git repo into $HOME.

Code
- git-repo-synced:
    repo: https://gitlab.com/freckles-io/freckles.git
    dest: ~/freckles

Example 2

Clone the 'freckles' git repo, create users if not exist already.

Code
- git-repo-synced:
    repo: https://gitlab.com/freckles-io/freckles.git
    dest: /var/lib/parent/freckles
    owner: freckles
    group: freckles
Description

This creates the group/user 'freckles' as well as the parent directory /var/lib/parent (if necessary), then checks out the 'freckles' git repo into it, and changes the owner and group to be 'freckles'.

Code

doc:
  short_help: Check out or pulls a git repo.
  help: |
    Clones or pulls a git repository.

    Create the group/owner if not available on the system. This does not put the owner into the group if both are specified,
    so do that before-hand if you need that much control.

    This does not install 'git' if it isn't already available and will fail if that's the case.
  examples:
  - title: Clone the 'freckles' git repo into $HOME.
    vars:
      repo: https://gitlab.com/freckles-io/freckles.git
      dest: ~/freckles
  - title: Clone the 'freckles' git repo, create users if not exist already.
    desc: |
      This creates the group/user 'freckles' as well as the parent directory ``/var/lib/parent`` (if necessary),
      then checks out the 'freckles' git repo into it, and changes the owner and group to be 'freckles'.
    vars:
      repo: https://gitlab.com/freckles-io/freckles.git
      dest: /var/lib/parent/freckles
      owner: freckles
      group: freckles

args:
  repo:
    doc:
      short_help: The source repository.
    type: string
    required: true
    cli:
      metavar: URL
  dest:
    doc:
      short_help: The destination path.
    type: string
    required: true
    cli:
      metavar: PATH
  version:
    doc:
      short_help: The version (tag, branch, hash, ..) to use.
    type: string
    required: true
    default: master
#  become:
#    doc:
#      short_help: "Whether to use elevated privileges."
#    type: boolean
#    required: false
#    default: false
  owner:
    doc:
      short_help: The owner of the target folder.
    type: string
    required: false
  group:
    doc:
      short_help: The group of the target folder.
    type: string
    required: false
  ensure_git:
    doc:
      short_help: Ensure git is installed.
    type: boolean
    default: false
    required: false
    cli:
      param_decls:
      - --ensure-git

meta:
  tags:
  - git
  - version control

frecklets:
- git-installed:
    frecklet::skip: '{{:: ensure_git | negate ::}}'
- group-exists:
    frecklet::skip: '{{:: group | true_if_empty ::}}'
    group: '{{:: group ::}}'
- user-exists:
    frecklet::skip: '{{:: owner | true_if_empty ::}}'
    name: '{{:: owner ::}}'
- parent-folder-exists:
    frecklet::skip: '{{:: owner | true_if_all_empty(group) ::}}'
    path: '{{:: dest ::}}'
    owner: '{{:: owner ::}}'
    group: '{{:: group ::}}'
- task:
    become: '{{:: owner | true_if_not_empty ::}}'
  frecklet:
    name: git
    type: ansible-module
    properties:
      idempotent: false
      internet: true
      elevated: '{{:: owner | true_if_not_empty ::}}'
    desc:
      references:
        "'git' Ansible module": https://docs.ansible.com/ansible/latest/modules/git_module.html
      short: "check out git repo '{{:: repo ::}}'"
      long: |
        Clone (if destination is empty) or pull the git repo '{{:: repo ::}}' to '{{:: dest ::}}'{%:: if version ::%}, using branch/tag/version '{{:: version ::}}'{%:: endif ::%}.
  vars:
    dest: '{{:: dest ::}}'
    repo: '{{:: repo ::}}'
    version: '{{:: version ::}}'
- path-is-owned-by:
    frecklet::skip: '{{:: owner | true_if_all_empty(group) ::}}'
    path: '{{:: dest ::}}'
    owner: '{{:: owner ::}}'
    group: '{{:: group ::}}'
frecklecute git-repo-synced --help

Usage: frecklecute git-repo-synced [OPTIONS]

  Clones or pulls a git repository.

  Create the group/owner if not available on the system. This does not put
  the owner into the group if both are specified, so do that before-hand if
  you need that much control.

  This does not install 'git' if it isn't already available and will fail if
  that's the case.

Options:
  --dest PATH        The destination path.  [required]
  --repo URL         The source repository.  [required]
  --ensure-git       Ensure git is installed.
  --group GROUP      The group of the target folder.
  --owner OWNER      The owner of the target folder.
  --version VERSION  The version (tag, branch, hash, ..) to use.
  --help             Show this message and exit.
# -*- coding: utf-8 -*-


#
# module path: pycklets.git_repo_synced.GitRepoSynced
#


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

@dataclass
class GitRepoSynced(AutoPycklet):
    """Clones or pulls a git repository.

     Create the group/owner if not available on the system. This does not put the owner into the group if both are specified,
     so do that before-hand if you need that much control.

     This does not install 'git' if it isn't already available and will fail if that's the case.

       Args:
         dest: The destination path.
         ensure_git: Ensure git is installed.
         group: The group of the target folder.
         owner: The owner of the target folder.
         repo: The source repository.
         version: The version (tag, branch, hash, ..) to use.

    """

    FRECKLET_ID = "git-repo-synced"

    dest: str = None
    ensure_git: bool = None
    group: str = None
    owner: str = None
    repo: str = None
    version: str = None


    def __post_init__(self):
        super(GitRepoSynced, self).__init__(var_names=["dest", "ensure_git", "group", "owner", "repo", "version"])


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


#
# module path: pycklets.git_repo_synced.GitRepoSynced
#


from pyckles import AutoPycklet

class GitRepoSynced(AutoPycklet):
    """Clones or pulls a git repository.

     Create the group/owner if not available on the system. This does not put the owner into the group if both are specified,
     so do that before-hand if you need that much control.

     This does not install 'git' if it isn't already available and will fail if that's the case.

       Args:
         dest: The destination path.
         ensure_git: Ensure git is installed.
         group: The group of the target folder.
         owner: The owner of the target folder.
         repo: The source repository.
         version: The version (tag, branch, hash, ..) to use.

    """

    FRECKLET_ID = "git-repo-synced"

    def __init__(self, dest=None, ensure_git=None, group=None, owner=None, repo=None, version="master"):

        super(GitRepoSynced, self).__init__(var_names=["dest", "ensure_git", "group", "owner", "repo", "version"])
        self._dest = dest
        self._ensure_git = ensure_git
        self._group = group
        self._owner = owner
        self._repo = repo
        self._version = version

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

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

    @property
    def ensure_git(self):
        return self._ensure_git

    @ensure_git.setter
    def ensure_git(self, ensure_git):
        self._ensure_git = ensure_git

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

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

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

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

    @property
    def repo(self):
        return self._repo

    @repo.setter
    def repo(self, repo):
        self._repo = repo

    @property
    def version(self):
        return self._version

    @version.setter
    def version(self, version):
        self._version = version



frecklet_class = GitRepoSynced