ansible #15

Supports: bionic xenial trusty
Add to new model

Description

This subordinate Charm fetches an ansible playbook from a git repository
and then executes it in the context of the main charm.


Overview

This subordinate charm runs an Ansible playbook, in a git repository, against localhost.

The charm performs the following operations, in the context of the main charm:

  • clone a git repository, which should contain an Ansible playbook (git_* configuration options)

  • prepare an Ansible inventory and execute the cloned playbook (ansible_* configuration options)

  • check at regular intervals if the playbook needs to be executed again (check_* configuration options)

The rationale behind this charm is that:

  • the idempotency provided by Ansible seems to match the idempotency required by Juju charm hook implementations

  • there are several ready to go Ansible playbooks available online (and inside organizations)

  • DevOps which prefer Ansible over scripting are facilitated.

Ansible charm users should be aware that race conditions may arise if the main charm and the subordinate Ansible charm modify the same resources.

Usage

Usage example:

juju deploy cs:ubuntu
juju deploy cs:ansible simpleansible
juju config simpleansible git_repo="https://git.garr.it/clauz/simpleansible.git"
juju config simpleansible ansible_playbook_yaml="main.yaml" 
juju add-relation ubuntu ansible

Contact Information

Consortium GARR

cloud-support@garr.it


Configuration

ansible_inventory_dir
(string) Inventory directory, relative to the git repository root. In this way, inventory directories such as group_vars and host_vars can be made available to Ansible.
ansible_inventory_hostgroup
(string) Optional host group to which localhost is added.
ansible_playbook_become
(boolean) Set the -b flag in the ansible-playbook command.
True
ansible_playbook_tags
(string) Only run plays and tasks tagged with these values (-t option of the ansible-playbook command).
ansible_playbook_yaml
(string) The filename of the main YAML in the playbook to be executed.
playbook.yaml
check_update_eval
(string) Optional bash expression to be evaluated at the update hook (every 5 minutes). The expression should check for a condition to hold (e.g. the presence of a specific parameter in a configuration file). Thus, if the expression returns 0 (true), the playbook is NOT executed. Else, the playbook is executed. Please note that the playbook is executed unconditionally in all the other cases, i.e. when the configuration changes, a relation is joined, etc.
/bin/true
git_branch
(string) git branch to check out after cloning the git repository.
master
git_deploy_key
(string) Optional SSH private key that can be used to clone the git repository over SSH.
git_repo
(string) URL of the git repository to be cloned. It should contain a playbook. The URL can be any of the URLs supported by the git client. Thus, URLs such as http://username:password@mydomain.org/myplaybook.git can also be provided.