Use Ansible command line tools inside Docker in CI or Local Environment.
Dockerfile linksdocker run -v $(pwd):/workspace/ -it gdiener/ansible ansible all -m ping
docker run -v $(pwd):/workspace/ -it gdiener/ansible ansible-playbook site.yml
docker run -v $(pwd):/workspace/ -it gdiener/ansible ansible-vault encrypt_string
docker run -v $(pwd):/workspace/ -it gdiener/ansible ansible-galaxy login
docker run -v $(pwd):/workspace/ -it gdiener/ansible ansible-console
docker run -v $(pwd):/workspace/ -it gdiener/ansible ansible-config dump
docker run -v $(pwd):/workspace/ -it gdiener/ansible ansible-doc file
docker run -v $(pwd):/workspace/ -it gdiener/ansible ansible-inventory --host localhost
docker run -v $(pwd):/workspace/ -it gdiener/ansible ansible-pull -U [email protected]:gadiener/unknown-ansible-repository.git site.yml
⁉️ This command is useless in the Docker context but you can still do it 😄
To install the aliases script you can use the following commands:
curl -o /usr/local/bin/ansible-aliases https://raw.githubusercontent.com/gadiener/ansible/master/ansible-aliases.sh
chmod +x /usr/local/bin/ansible-aliases
Then you can use the script.
$ ansible-aliases -h
Usage: ansible-aliases [OPTIONS]
>> Install dockerized Ansible tools aliases
Options:
-k, --key string The path of the SSH key to use
-w, --workspace string The path of the workspace to use (default $(pwd))
-t, --tag string The Docker tag to use
-e, --env string Set environment variables
--remove Uninstall Ansible aliases
ansible-aliases -k $SSH_KEY_PATH -e 'ANSIBLE_HOST_KEY_CHECKING=False'
After installing the aliases, the shell must be restarted.
To remove aliases you can use the following commands:
ansible-aliases --remove
rm /usr/local/bin/ansible-aliases
The SSH_KEY variable must contains che SSH key used by Ansible to connect to the cluster.
SSH_KEY=$(cat ~/.ssh/id_rsa)
To share your tasks or playbook's files you can bind a volume to /workspace.
You can bind a volume to /etc/ansible to share your local conficuration with Ansible in docker.
⛔️ WARNING: Do not add a volume in ~/.ssh/:/home/ansible/.ssh/ without the read-only flag. With the environment variable SSH_KEY set you'll lose your private key!
@todo: I'm waiting for your pull request 😉
How to get involved:
This project follows the GitFlow branching model. The master branch always reflects a production-ready state while the latest development is taking place in the develop branch.
Each time you want to work on a fix or a new feature, create a new branch based on the develop branch: git checkout -b BRANCH_NAME develop. Only pull requests to the develop branch will be merged.
Pull requests are highly appreciated.
Solve a problem. Features are great, but even better is cleaning-up and fixing issues in the code that you discover.
This project is maintained by using the Semantic Versioning Specification (SemVer).
Gabriele Diener @gadiener
Flavio De Stefano @kopiro
Copyright 2018 Gabriele Diener under the MIT license.
Content type
Image
Digest
Size
32.9 MB
Last updated
almost 8 years ago
docker pull gdiener/ansible