Tags are confusing

30 views
Skip to first unread message

Mark Faine

unread,
May 17, 2021, 9:55:13 AM5/17/21
to Ansible Development

My goal is to use a single tag to run specific roles independently but have dependent roles run as well with only the single tag.

My roles are in a playbook:

playbook.yml
roles:
  role:  roleA
  tags: roleA <- for lack of a better name
  role: roleB
  tags: roleB
  ...

roles/roleA/meta/main.yml
...
dependencies:
  -  { role: roleA, roleB }

What I want to do is run ansible-playbook ... --tags roleA and have roleB run as a dependency every time before roleA runs.

How can I do this?

Thanks,
-Mark


Mark Faine

unread,
May 17, 2021, 10:14:14 AM5/17/21
to Ansible Development
Looks like I can't edit posts here for some reason. 

Correction:

dependencies:
  -  { role: roleA, tags: roleA, roleB }

or at least that's the way I want it to work.

The only purpose for this is to ensure that dependent roles for any of the tags I run also run.   The only other option I can see is to add every single dependency as a tag to my dependent roles.  Like this:

playbook.yml:
roles:
  role:  roleA
  tags: roleA <- for lack of a better name
  role: roleB
  tags: 
    - roleA
    - roleC
    - roleD
    ... potentially very long list of tags

So I can then run any of the roles and know that roleB will always run.  This however is very unwieldy and seems very unintuitive.  There must be a better way.
Reply all
Reply to author
Forward
0 new messages