Example
An (empty) example Ansible role complete with working tests out of the box. For more information read the blog post.
Requirements
See meta/main.yml
, requirements.yml
and assertions at top of
tasks/main.yml
.
Adding the role as a dependency
Add the following to your meta/main.yml
:
dependencies:
- src: https://www.shore.co.il/git/ansible-role-example
scm: git
name: example
When :code: ansible-galaxy downloads your role it will also download its dependencies, ensuring this role will be present and run everytime your role runs.
Adding the role to your playbooks
Add the following to your requirements.yml
:
- src: https://www.shore.co.il/git/ansible-role-example
scm: git
name: example
and update your roles by running :code: ansible-galaxy install -r requirements.yml.
Role Variables
See defaults/main.yml
.
Dependencies
See meta/main.yml
.
Example Playbook
See tests/playbook.yml
.
Testing
Testing requires Virtualbox and Vagrant (out of scope for this documentation). Install the Python dependencies, add pre-commit hooks by running:
pip install -r tests/requirements.txt
pre-commit install
To run the full test suite:
ansible-galaxy install git+file://$(pwd),$(git rev-parse --abbrev-ref HEAD) -p .molecule/roles
pre-commit run --all-files
molecule test --platform all
License
This software is licensed under the MIT license (see the LICENSE.txt
file).
Author Information
Nimrod Adar, contact me or visit my website. Patches are welcome via git send-email. The repository is located at: https://www.shore.co.il/git/.