version | 3.0.0 | MIT license | Copyright (c) 2020 Bart Lievers | blog | github | dockerhub |
---|
This repository contains my approach for building, maintaining an running an ansible docker container. This is based on this blog.
An Ansible-Helper container is a docker image containing al the bits & bytes to run ansible, to be used to run interactivly with docker.
Besides getting expierence with Ansible, Docker, git etc... using the docker interactive run features to run ansible in a box without installing it in the host OS.
In this way you can use a certian version of ansible, without having it installed in your host OS and having issues with dependancies when updating packages.
version | Ansible version |
History |
---|---|---|
3.0 | 3.0.0 | Updated to ansible 3.0.0 |
2.10 | 2.10.0 | following Ansible community version scheme |
0.4 | 2.10.0 | updated to Ansible 2.10.0 and alpine 3.12 |
0.3 | 2.9.0 | updated python to v3 |
0.2 | 2.9.0 | moved from ansible playbook, to scripts for building ansible image |
0.0.1 | 2.9.0 | start |
On the host the following needs to be installed.
- docker
- docker-py
To build the ansible-helper image execute the following
./install
This will build the docker image ansible:2.9.0 and copy bash scripts to /usr/local/bin The image is also available at dockerhub. The wrapper scripts are copied inside the image. See the readme.md inside the scripts folder.
To run ansible helper use the following commands
cmd | explenation |
---|---|
ah | ansible helper cmdlet, use the ansible cmdlets as arguments. |
ah-playbook | run ansible-playbook cmdlet. Alternative to 'ah ansible-playbook' |
Both ah and ah-playbook will run the following
docker_img="ansible:latest"
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 \
-v /var/log/ansible/ansible.log \
$docker_img "$@"
This will run a docker container interactively with the ansible:latest image. It will mount the id_rsa files, making it possible to connect to the local host. And mounts the local folder under /ansible/playbooks. ah-playbook command ends withansible-playbook "$@" instead of only "$@"
See the example folder for an example of an ansible structure you can use.