DevOps General

Ansible Galaxy dependency usage

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).


Shared roles using gitlab repositories

Define the role dependencies in the corresponding section of the role’s meta/main.yml.

  - src:
    scm: git
    version: master
    name: nginx

  - src:
    scm: git
    version: master
    name: postfix


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+,master" --force

# apply the playbook (using the defined and installed dependencies)
ansible-playbook -i localhost, /root/.ansible/roles/product/product/playbook.yml