Use Ansible command line tools inside Docker in CI or Local Environment.
- ansible: Define and run a single task ‘playbook’ against a set of hosts.
docker run -v $(pwd):/workspace/ -it gdiener/ansible ansible all -m ping
- ansible-playbook: Runs Ansible playbooks, executing the defined tasks on the targeted hosts.
docker run -v $(pwd):/workspace/ -it gdiener/ansible ansible-playbook site.yml
- ansible-vault: Encryption/decryption utility for Ansible data files.
docker run -v $(pwd):/workspace/ -it gdiener/ansible ansible-vault encrypt_string
- ansible-galaxy: Manage Ansible roles in shared repositories
docker run -v $(pwd):/workspace/ -it gdiener/ansible ansible-galaxy login
- ansible-console: A REPL that allows for running ad-hoc tasks against a chosen inventory.
docker run -v $(pwd):/workspace/ -it gdiener/ansible ansible-console
- ansible-config: Config command line class.
docker run -v $(pwd):/workspace/ -it gdiener/ansible ansible-config dump
- ansible-doc: Plugin documentation tool.
docker run -v $(pwd):/workspace/ -it gdiener/ansible ansible-doc file
- ansible-inventory: Display or dump the configured inventory as Ansible sees it.
docker run -v $(pwd):/workspace/ -it gdiener/ansible ansible-inventory --host localhost
- ansible-pull: Pulls playbooks from a VCS repo and executes them for the local host.
docker run -v $(pwd):/workspace/ -it gdiener/ansible ansible-pull -U [email protected]:gadiener/unknown-ansible-repository.git site.yml
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:
- Star the project!
- Answer questions that come through GitHub issues
- Report a bug that you find
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.