Hello all:
   I've been Googling for a couple hours trying to find a way to pass tags 
to a role from within a playbook. The goal is to build a utility role with 
common tasks (mount a filesystem, add specific users, etc.). So far it's 
not working.

I've tried:



Inside my utility role main.yml:

- name: "Task 1"
  include: task1.yml
  tags: utility_task1

- name: "Task 2"
  include: task2.yml
  tags: utility_task2
  
- name: "Task 3"
  include: task3.yml
  tags: utility_task3
 

This works fine if I pass the tag from the command line:  ansible-playbook 
playbooks/foo.yml -t "utility_task2"

However, it does not work when called from a playbook like this:

  roles:
  - { role: utility, tags: "utility_task2" }

Google searches show there is an ansible.cfg setting for "gathering=smart" 
or "gathering=implicit" that can change the behaviour but so far neither 
seems to make a difference. 

My workaround is currently to set an extra variable (e.g., --extra-vars 
"utility_task=task1" ) then use a when: on each separate task. This works 
but the output is very messy: I.e., it prints a "skipping:" message for 
every other task in the role. As the number of separate tasks in a role 
grow, these skips will rise exponentially. 

Is there a cleaner, Ansible way to do this?  

Thanks in advance.

Kwan

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/8cacc39d-a7be-4add-b62a-a23a2d18dcb1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to