# How to handle data common to a set of roles?

**URL:** <https://forum.ansible.com/t/how-to-handle-data-common-to-a-set-of-roles/20100>\
**Category:** Ansible Project\
**Created:** [December 30, 2015, 11:48am UTC](https://forum.ansible.com/t/how-to-handle-data-common-to-a-set-of-roles/20100 "2015-12-30T11:48:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yassen\_Damyanov](https://avatars.discourse-cdn.com/v4/letter/y/9fc29f/32.png) [@Yassen\_Damyanov](https://forum.ansible.com/u/Yassen_Damyanov)\
**Post date:** [December 30, 2015, 11:48am UTC](https://forum.ansible.com/t/how-to-handle-data-common-to-a-set-of-roles/20100/1 "2015-12-30T11:48:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![alexey.vazhnov](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@alexey.vazhnov](https://forum.ansible.com/u/alexey.vazhnov)\
**Post date:** [December 30, 2015, 1:27pm UTC](https://forum.ansible.com/t/how-to-handle-data-common-to-a-set-of-roles/20100/2 "2015-12-30T13:27:21Z")

</div>

You can place your common variables in group\_vars/all/.  
Did you read this [http://docs.ansible.com/ansible/playbooks\_variables.html](http://docs.ansible.com/ansible/playbooks_variables.html) ?

---

<div class="post-metadata">

**Author:** ![chrismeyersfsu](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chrismeyersfsu/32/1016_2.png) [@chrismeyersfsu](https://forum.ansible.com/u/chrismeyersfsu)\
**Post date:** [December 30, 2015, 1:56pm UTC](https://forum.ansible.com/t/how-to-handle-data-common-to-a-set-of-roles/20100/3 "2015-12-30T13:56:05Z")

</div>

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](https://galaxy.ansible.com/detail#/role/6324) role that i reference in meta/main.yml dependencies to ensure per-role variables are defined and/or assigned.

---

<div class="post-metadata">

**Author:** ![Yassen\_Damyanov](https://avatars.discourse-cdn.com/v4/letter/y/9fc29f/32.png) [@Yassen\_Damyanov](https://forum.ansible.com/u/Yassen_Damyanov)\
**Post date:** [December 30, 2015, 5:08pm UTC](https://forum.ansible.com/t/how-to-handle-data-common-to-a-set-of-roles/20100/4 "2015-12-30T17:08:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Yassen\_Damyanov](https://avatars.discourse-cdn.com/v4/letter/y/9fc29f/32.png) [@Yassen\_Damyanov](https://forum.ansible.com/u/Yassen_Damyanov)\
**Post date:** [January 18, 2016, 9:32am UTC](https://forum.ansible.com/t/how-to-handle-data-common-to-a-set-of-roles/20100/5 "2016-01-18T09:32:36Z")

</div>

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.
