Kai:
  Thank you for your response.

On Wednesday, November 15, 2017 at 11:00:08 AM UTC-5, Kai Stian Olstad 
wrote:
>
> On Wednesday, 15 November 2017 15.58.47 CET DigitalHermit wrote: 
> > 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. 
>
> That's not possible. 
>

 I suspected as much...

>
> > 
> > However, it does not work when called from a playbook like this: 
> > 
> >   roles: 
> >   - { role: utility, tags: "utility_task2" } 
>
> What you do here is adding the tag utility_task2 to all task in the role 
> utility. 
>
> As the documentation[1] say 
> "Adding “tags:” in any part of a play (including roles) adds those tags to 
> the contained tasks."
>

OK, that clarifies things a bunch. 
 

> > Is there a cleaner, Ansible way to do this?   
>
> Maybe, there's always many ways to tackle a challenge. 
> Since you haven't shared the specifics it impossible to be specific. 
>
>
Let me elaborate on my goal:
I have a library of roles. Each of these roles has common tasks across the 
library. For example, both my install_nginx and install_elk roles have a 
common task to create a filesystem.

E.g.:
roles/install_nginx/tasks/create_webdir.yml
roles/install_elk/tasks/create_datadir.yml

To simplify filesystem creation I created an adhoc_fs role and call it from 
within the playbook with an include
 

- name: "Create datadir" 
  include_role: 
    name: adhoc_fs 
    vars: 
      adhoc_filesystems:
        { vol_group: 'data_vg', lv_mount: '/mnt/webdata1', lv_name: 
'webdata1_lv', lv_size: '40G', owner: apache }
        { vol_group: 'data_vg', lv_mount: '/mnt/webdata2', lv_name: 
'webdata2_lv', lv_size: '40G', owner: apache }

This works fine, but the problem is now that my library contains many of 
these utility roles. I would prefer to have them all in a single role, 
"utility" for example, and call them as needed.  Typical tasks would be 
user creation, iptables rules, etc..The point of this is to avoid 
copying/pasting from role to role which will ease maintenance. 


[1] https://docs.ansible.com/ansible/latest/playbooks_tags.html 
>
> -- 
> Kai Stian Olstad 
>

-- 
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/ed042ea6-88bb-4934-9c9a-6f6bbbbef5a6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to