maxn
maxn

Reputation: 21

Always run ansible role before other role

I'm trying to find my way out of a dependency thicket. I'm using Ansible 1.9.2.

In a single playbook, I want to be able to install a Galaxy role (in the event, the Datadog.datadog role) and configure it. But Ansible always barfs; since the Datadog.datadog role doesn't exist until another role that I wrote installs the Galaxy role, it won't execute. This is how I'd really like it to be, cutting out the other roles that my playbook uses:

- hosts: all
  roles: 
  - install_datadog
  - (some other roles...)
  - { role: Datadog.datadog, sudo: true }
  vars:
    datadog_api_key: "somekey"

I have tried all of the following, and none of them work for installing the Ansible Galaxy Datadog.datadog role first:

Defining a role dependency doesn't make sense, because Datadog.datadog doesn't exist yet, so I can't define any dependencies in it. There is always an error akin to this:

ERROR: cannot find role in /etc/ansible/roles/Datadog.datadog

The only thing I can get to work is executing the install_datadog role in a prior run. This is not a great solution, as previously one playbook that had many execution blocks and role invocations configured our whole environment; this would require the execution of two playbooks in a specific order, which is highly inelegant.

So in a single run, how do I resolve a Galaxy role that won't exist until an earlier role has run to install it?

Upvotes: 2

Views: 1560

Answers (1)

tkdkop
tkdkop

Reputation: 129

Make sure that your roles_path is correct. The roles_path variable in ansible.cfg specifies where ansible will look for roles, and the --roles-path option to ansible-galaxy will specify where the datadog role gets installed.

For example, my install task looks like this:

ansible-galaxy install Datadog.datadog --roles-path=/usr/home/vagrant

and in my ansible.cfg file I have this line:

roles_path = /vagrant/ansible/roles:/usr/home/vagrant

Upvotes: 0

Related Questions