git repo - adean20csc/Files GitHub Wiki

git-repo

This Role will perform an idempotent 'git' of Git repositories defined in the roles/git-repo/defaults/main.yml file.

Requirements

This Role must be retrieved to the CAM and is done so by the ansible-slmcam-role/tasks/main.yml which is used to build out the CAM. It is then utilized to retrieve subsequent repos.

The Role consists of two Ansible playbooks found in roles/tasks. This was done in order to iterate the tasks with the string of variables.

Role Variables

The variables for this role can be found in the roles/git-repo/defaults/main.yml file.

Here is an example:

---
#-------------------------------------------------------
# Default var file for git-repo role
#-------------------------------------------------------

#-------------------------------------------------------
# The repos listed here should be the actual name of
# repo on git
#-------------------------------------------------------
repos:
# role_repos located in /etc/ansible/roles
  - { name: cam_connections_check, dest_dir: "{{ git_role_dir }}" }
  - { name: cam_backup_restore,    dest_dir: "{{ git_role_dir }}" }
  - { name: cam_post_automation,   dest_dir: "{{ git_role_dir }}" }
  - { name: cam-healthcheck,       dest_dir: "{{ git_role_dir }}" }

# project_repos located in /opt/csc/src
  - { name: docker-mediacascade,   dest_dir: "{{ git_repo_dir }}" }

The 'name' is the actual name of the github.dxc:Automation/'name'

The 'dest_dir' has two options:

  • git_role_dir: role repos used specifically by the CAM for management purposes
  • git_repo_dir: repos used for general purpose (CAM, Docker containers, etc)
#--------------------------------------------------------
# These vars should not be changed unless necessary.
#--------------------------------------------------------
# dir on cam for roles
git_role_dir: /etc/ansible/roles
git_repo_dir: /opt/csc/src

# deployment key src & dest dirs
key_dir: /etc
key_dest: /opt/csc

# dxc git repo site
git_site: [email protected]:Automation

Example Playbook

The Role can be initiated two ways:

A sample playbook (git-repo.yml)included with the role:

ansible-playbook git-repo.yml

git-repo.yml playbook:

- name: Clone a Git Repo
  hosts: localhost
  gather_facts: false

  roles:
    - git-repo

It can also be called by another role by using the include_role along with the other tasks:

- include_role:
    name: git-repo