2

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:

  • Having an earlier block in the same playbook that runs my install_datadog role.
  • Using an 'include' statement earlier in the playbook that includes the install_datadog role's main.yml.
  • Creating a pre_task statement in the above playbook.

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?

techraf
  • 64,883
  • 27
  • 193
  • 198
maxn
  • 21
  • 4
  • Why are you needing to install the role every time? Are you operating Ansible in pull mode? – ydaetskcoR Apr 04 '16 at 06:51
  • I don't need to install the role every time, but whenever this playbook runs (it's essentially the "configure/reconfigure the whole environment" playbook), it should ensure that the role is there. And it's idempotent, so the "install_" in its title is perhaps slightly misleading. – maxn Apr 04 '16 at 11:56
  • I'm confused by your workflow. I don't use Galaxy at all so not sure how it affects your workflow but typically you would store all of your Ansible plays and roles in source control and the pulled Galaxy role should be no different to this. Once you pull the role the first time it's stored in your source control repository and then you run your other plays against that copy. – ydaetskcoR Apr 04 '16 at 12:37
  • @ydaetskcoR Hm, that was a very helpful comment. I may be going about this the wrong way by trying to dynamically install the role; just plopping the Datadog.datadog roles in the config repo may well be the best way to address this. – maxn Apr 04 '16 at 14:48

1 Answers1

0

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

tkdkop
  • 119
  • 1
  • 6