Shortcuts

Docker setup

Move into the folder:

$ cd ansible-sc_pack-public

Build

$ docker build -t shimmercat-python-ansible-alpine .

Test

$ docker run --name ansible-playbook --rm shimmercat-python-ansible-alpine --version

which should return something like this:

ansible-playbook 2.8.0
  config file = None
  configured module search path = ['/ansible/library']
  ansible python module location = /usr/local/lib/python3.7/site-packages/ansible
  executable location = /usr/local/bin/ansible-playbook
  python version = 3.7.3 (default, May 11 2019, 02:00:41) [GCC 8.3.0]

Running Ansible Playbook

$ docker run --rm -it -v <PATH_TO_LOCAL_PLAYBOOKS_DIR>:/ansible/playbooks shimmercat-python-ansible-alpine <PLAYBOOK_FILE>

For example, the command to run the ansible-playbook 1-all-in-one.yml, in production, from the top-level directory using the pwd command:

$ docker run --rm -it  -v $(pwd):/ansible/playbooks shimmercat-python-ansible-alpine -i inventories/production 1-all-in-one.yml

As Ansible is interacting with the external machines, you’ll need to mount a SSH key pair for the duration of the play:

$ docker run --rm -it \
    -v ~/.ssh/id_rsa:/root/.ssh/id_rsa \
    -v ~/.ssh/id_rsa.pub:/root/.ssh/id_rsa.pub \
    -v $(pwd):/ansible/playbooks \
    shimmercat-python-ansible-alpine -i inventories/production <PLAYBOOK_FILE>

Ansible helper wrapper

Shell script named ansible_helper.sh that wraps a Docker image containing Ansible:

$ ./ansible_helper.sh -i inventories/production <PLAYBOOK_FILE>