ansible-role: Run an ansible role in an isolated disposable environment (a temporary vagrant virtual machine)
ansible-test-role: Test a single ansible role in a temporary virtual machine to verify it's correctness.
Default vagrant image is Debian 8 64 bit (debian/jessie64
).
- Reuse or prepare a temporary vagrant machine and start it
- Create a temporary ansible inventory based on the vagrant machine data
- Run
ansible-playbook
with a temporary playbook only containing the role passed to the script as a parameter - Optional: Tear down the vagrant machine and remove all temporary files
- ansible
- vagrant
- any compatible virtual machine environment, e.g.
virtualbox
libvirt
sudo curl -Lo "/usr/local/bin/ansible-role" "https://raw.githubusercontent.com/thomas-mc-work/ansible-test-role/master/ansible-role.sh"
sudo curl -Lo "/usr/local/bin/ansible-test-role" "https://raw.githubusercontent.com/thomas-mc-work/ansible-test-role/master/ansible-test-role.sh"
sudo chmod +x "/usr/local/bin/ansible-role" "/usr/local/bin/ansible-test-role"
The target folder /usr/local/bin
could also be replaced by your personal bin folder ($HOME/bin
).
ansible-role:
ansible-role <role-path> [ansible-playbook options]
ansible-test-role:
ansible-test-role <role-path> [ansible-playbook options]
ansible-playbook options
: These can be valid ansible-playbook
options which wil be passed through.
You can define several environment variables which are used by vagrant or ansible like these:
VAGRANT_DEFAULT_PROVIDER
: The latest version of vagrant (2.0 as of 2017-10-27) isn't able to work with virtualbox version ≥ 5.2 – so you can easily switch to e.g.libvirt
herewith
These are defined in the script and thus overridden:
ANSIBLE_ROLES_PATH
ANSIBLE_INVENTORY
VAGRANT_CWD
- Molecule: It seems to be a very more profound solution. One big drawback is the big footprint of configuration files that it creates in your project (and thus in your SCM).
- RoleSpec: focuses on Travis-CI integration
- ansible-test: (didn't work on my machine: Xubuntu 16.04.3)