5

I have a playbook like that, with one role per client.

- hosts: hosting
  roles:
    - { role: client1, tags: ['client1'] }
    - { role: client2, tags: ['client2'] }

And on each role, I have a dependency on nginx for example.

/roles/client1/meta/main.yml
dependencies:
  - nginx

I would like to not launch the nginx role when it is not necessary. So I have added the nginx tag to the dependency.

/roles/client1/meta/main.yml
dependencies:
  - { role: nginx, tags: ['system'] }

But when I launch the playbook with the tag client1, the nginx role is executed. Is there a solution to avoid that ?

I know a can "export" the dependency on the playbook, it works good, but it's not a nice solution I think.

- hosts: hosting
  roles:
    - { role: nginx, tags: ['system'] }
    - { role: client1, tags: ['client1'] }
    - { role: client2, tags: ['client2'] }
udondan
  • 57,263
  • 20
  • 190
  • 175
elhostis
  • 1,067
  • 14
  • 32

1 Answers1

7

Tags do not override each other but are cummulative. Your dependency now has the tags client1 and system.

But that already is enough. Just tell Ansible to skip the system tag when calling your playbook:

ansible-playbook ... --tags client1 --skip-tags system
udondan
  • 57,263
  • 20
  • 190
  • 175