Skip to content

Latest commit

 

History

History
91 lines (70 loc) · 2.56 KB

How_to_use_galaxy_roles_in_your_config.adoc

File metadata and controls

91 lines (70 loc) · 2.56 KB

Galaxy and external roles

To use galaxy roles in your config, just do the following:

  1. 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'
  2. 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 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.

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.

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 .gitignore to ignore those dynamic roles:

gitignore
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 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:

ansible-playbook main.yml -e requirements_path=ansible/configs/{{env_type}}/requirements-prod.yml [...]