Short note on ansible/ansible galaxy:
- ansible-galaxy takes care of install the roles. Regardless if defined via a requirements.yaml or defined via the “dependencies:” section in the meta/main.yaml of a role.
- ansible-playbook/ansible-pull doesn’t care about installation of roles, it just wants the defined dependencies (same meta/main.yaml) to be present. Here is the role_path important.
Knowing this it allows you to fulfill many usage- and development patterns. Like developing company wide reusable ansible roles with multiple teams (DevOps).
Example:
Shared roles using gitlab repositories
Define the role dependencies in the corresponding section of the role’s meta/main.yml.
dependencies:
- src: https://gitlab%2Bdeploy-token-13:xxx@gitlab.example.com/ansible/shared/nginx.git
scm: git
version: master
name: nginx
- src: https://gitlab%2Bdeploy-token-13:xxx@gitlab.example.com/ansible/shared/postfix.git
scm: git
version: master
name: postfix
Usage
The installation of roles (and their dependencies) and running the playbook becomes a simple two-liner:
# install roles and their dependencies
ansible-galaxy install "git+https://gitlab+deploy-token-19:xxx@gitlab.example.com/ansible/products/product.git,master" --force
# apply the playbook (using the defined and installed dependencies)
ansible-playbook -i localhost, /root/.ansible/roles/product/product/playbook.yml