How to handle data common to a set of roles?

Guys,

Could you suggest a way to handle data common to a set of roles, e.g. the IP address of the DNS or the DHCP server on the network? These seem to be fixed for now but can change in future and I’d like to have a convenient way to do a change in one place and then have all roles working with the new setting.

What I can think of: a dedicated task-less role having these defined in its variables; then other roles should depend on it and thus get the above-mentioned stuff “for free”.

Let know how you do it and what would you recommend.
Thanks,
-Y.

You can place your common variables in group_vars/all/.
Did you read this http://docs.ansible.com/ansible/playbooks_variables.html ?

The task-less role is good because you can capture the dependency fully in the role (via meta/main.yml dependencies) without depending on some externally defined data. Further, your data would follow your roles if you want to use those roles in another project.

The group_vars/all could also work well in your design IF your roles that depend on those “shared variables” are designed such that they either (1) fail when those variables aren’t defined or (2) you assign sane defaults in the role for the “shared variables”. (1) is a common problem for me so I created a required-vars role that i reference in meta/main.yml dependencies to ensure per-role variables are defined and/or assigned.

Alexey,
Thanks for pointing me to the right direction. This seems to be “The Right Way” to do it :wink: I am reading that page right now.
Cheers,
-Y.

Chris, thanks; so then using task-less roles doesn’t look so bad… I’ll give a try to both approaches and see. Thanks again!
-Y.