To use galaxy roles in your config, just do the following:
-
Create
requirements.yml
file in the config directory, for example:ansible/configs/{{env_type}}/requirements.yml
--- - src: geerlingguy.docker name: docker version: '2.5.1'
-
Use the role in the playbooks
ansible/configs/{{env_type}}/pre_software.yml
- name: Some play hosts: - myhosts become: true gather_facts: False tasks: - name: install docker include_role: name: docker
Note
|
Note that in the previous example, we use |
Important
|
Please use a pinned Make sure you use version pinning in
requirements.yml - src: geerlingguy.docker
name: docker
version: '2.5.1' |
When you run Ansible Agnostic Deployer, it will automatically fetch and create the role in your config directory: ansible/configs/{{env_type}}/roles/docker
for example.
Roles in requirements.yml
don’t have to be in Galaxy, you can use any git repo.
requirements.yml
with git repo---
# External role to setup grader host virtualenv and FTL grading infra
- src: https://github.com/redhat-gpte-devopsautomation/ftl-injector
name: ftl-injector
version: v0.7
During development, the roles will be deployed and get in your way git-wise. To avoid that, there is a rule in the top-level .gitignore
to ignore those dynamic roles:
ansible/configs/*/roles
The convention is:
the "static" roles, those versioned in this repository, must live in
ansible/roles
and the "dynamic" roles in your config directoryansible/configs/{{env_type}}/roles
.
Note
|
Dynamic roles are not pushed in git, only the requirements.yml file is versioned.
|
Sometimes, for the same config, we need several requirements.yml
. For example, one for PROD, one for DEV, etc.
You can create as many files as you want. When calling the playbook just override the requirements_path
variable:
ansible-playbook main.yml -e requirements_path=ansible/configs/{{env_type}}/requirements-prod.yml [...]