On Saturday, December 7, 2013 11:22:16 AM UTC-8, Michael DeHaan wrote: > > "Say I want to put basic config variables in roles/*/vars/main.yml for > use when the role's tasks run, but also want to access them in a play that > doesn't include that role" > > Assuming you are already running 1.4, and you should be, since it's > released (just waiting on EPEL to roll over). you can do this from any > task file: > > - include_vars: ../roles/foo/vars/main.yml > > Though it seems like it might be better to just have the role depend on a > common role, and set the variables there. >
I have a similar need to re-use variables related to a role without running the tasks associated with that role. At this point, I'm putting them all in group_vars/all, but it's getting a bit challenging to manage. With the include_vars approach, would we lose the ability to override them in group_vars and host_vars? Before settling on group_vars/all, my previous approach was to not have a main.yml and to include a tasks file from the role explicitly in my playbook, although with this approach I lost the ability to see which role was currently being executed and it felt kind of clunky (so I abandoned it). I think a really slick interface to address this workflow would be to allow specifying specific task files for a role in the roles declaration. Something like: roles: some_role:some_tasks In that example, some_tasks would be referring to roles/some_role/tasks/some_tasks.yml. This would accommodate re-using role variables by simply not having a tasks/main.yml and explictly specifying the task list in the playbooks that need them. With that setup, my random auxillary playbooks would all have "roles: [my_app]", while my main deployment playbook would have "roles: [my_app:deploy]". -- 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]. For more options, visit https://groups.google.com/groups/opt_out.
