= Galaxy and external roles
|
|
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`
|
[source,yaml]
|
----
|
---
|
- src: geerlingguy.docker
|
name: docker
|
version: '2.5.1'
|
----
|
. Use the role in the playbooks
|
+
|
.`ansible/configs/{{env_type}}/pre_software.yml`
|
[source,yaml]
|
----
|
- 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 `include_role` which is *dynamic*. If you try to use the role with `role` or `import_role` it will fail because the role is dynamically downloaded at runtime.
|
====
|
|
[IMPORTANT]
|
====
|
Please use a pinned `version` in the `requirements.yml` file so the success of the deployment of your config does not depend on the stability of upstream galaxy roles.
|
|
[source,yaml]
|
.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.
|
|
== Non-Galaxy external roles
|
|
Roles in `requirements.yml` don't have to be in Galaxy, you can use any git repo.
|
|
[source,yaml]
|
.Another example of `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
|
----
|
|
== Development workflow
|
|
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 link:../.gitignore[`.gitignore`] to ignore those dynamic roles:
|
|
.gitignore
|
----
|
ansible/configs/*/roles
|
----
|
The convention is:
|
|
> the "static" roles, those versioned in this repository, must live in link:../ansible/roles[`ansible/roles`] and the "dynamic" roles in your config directory `ansible/configs/{{env_type}}/roles`.
|
|
NOTE: Dynamic roles are not pushed in git, only the `requirements.yml` file is versioned.
|
|
|
== Multiple requirement files
|
|
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:
|
|
[source, bash]
|
----
|
ansible-playbook main.yml -e requirements_path=ansible/configs/{{env_type}}/requirements-prod.yml [...]
|
----
|