# group\_vars and ansible's patterns - suggestions please!

**URL:** <https://forum.ansible.com/t/group-vars-and-ansibles-patterns-suggestions-please/22895>\
**Category:** Ansible Project\
**Created:** [October 26, 2016, 8:39pm UTC](https://forum.ansible.com/t/group-vars-and-ansibles-patterns-suggestions-please/22895 "2016-10-26T20:39:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dan\_Rough](https://avatars.discourse-cdn.com/v4/letter/d/48db29/32.png) [@Dan\_Rough](https://forum.ansible.com/u/Dan_Rough)\
**Post date:** [October 26, 2016, 8:39pm UTC](https://forum.ansible.com/t/group-vars-and-ansibles-patterns-suggestions-please/22895/1 "2016-10-26T20:39:21Z")

</div>

Hi,

I’d like to know how others are dealing with keeping their group\_vars files granular. Ours have become a little unwieldily and we’re considering approaches to breaking them apart.

When we provision a server, we assign it to a number of groups. Among those groups, each server is added to at least three groups. Firstly, we add it to a group which defines its role, for example app\_server. Another group represents the location of the DC that the server is in, which might be LON, for example. Thirdly, we also add it to a group which denotes whether it is a production server or a test server, prod, for example. That allows us to use ansible’s patterns when we’re configuring the server to do something like this: - hosts: “prod:&LON:&app\_server” or - hosts: “prod:&ORD:&app\_server”.

We have a variables which need to be defined based on these three variables, Environment, Region and Role. Our current thinking is to create a group\_vars file for each of the possible combinations, prod\_LON\_app\_server, for example. The affect of this decision will mean that we’re going to see an explosion in the number of groups a server is added to, and the number of group\_vars files we maintain.

Before we take this route, can anyone tell me if we’re missing a trick? Is there a technique that we’re missing?

Thanks!

Dan.

---

<div class="post-metadata">

**Author:** ![Alexander\_H\_Laughlin](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@Alexander\_H\_Laughlin](https://forum.ansible.com/u/Alexander_H_Laughlin)\
**Post date:** [October 26, 2016, 9:01pm UTC](https://forum.ansible.com/t/group-vars-and-ansibles-patterns-suggestions-please/22895/2 "2016-10-26T21:01:53Z")

</div>

Hi Dan,

Why not store the values in a dictionary and just pull the values you need for any given server based on its key?

Alex

---

<div class="post-metadata">

**Author:** ![Dan\_Rough](https://avatars.discourse-cdn.com/v4/letter/d/48db29/32.png) [@Dan\_Rough](https://forum.ansible.com/u/Dan_Rough)\
**Post date:** [October 26, 2016, 9:14pm UTC](https://forum.ansible.com/t/group-vars-and-ansibles-patterns-suggestions-please/22895/3 "2016-10-26T21:14:00Z")

</div>

That’s a good idea. Thanks! I hadn’t thought of that. That will simplify things in one or two locations.

---

<div class="post-metadata">

**Author:** ![Alexander\_H\_Laughlin](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@Alexander\_H\_Laughlin](https://forum.ansible.com/u/Alexander_H_Laughlin)\
**Post date:** [October 26, 2016, 9:15pm UTC](https://forum.ansible.com/t/group-vars-and-ansibles-patterns-suggestions-please/22895/4 "2016-10-26T21:15:19Z")

</div>

You’re quite welcome. I’m happy to help.

---

<div class="post-metadata">

**Author:** ![Allen\_Sanabria1](https://avatars.discourse-cdn.com/v4/letter/a/85e7bf/32.png) [@Allen\_Sanabria1](https://forum.ansible.com/u/Allen_Sanabria1)\
**Post date:** [October 26, 2016, 9:50pm UTC](https://forum.ansible.com/t/group-vars-and-ansibles-patterns-suggestions-please/22895/5 "2016-10-26T21:50:21Z")

</div>

I use to use group\_vars/. Instead I use vars/ now. Since include\_vars plugin now supports directories and you can limit the depth of the include. Here is an example on how I manage vars/ today [https://github.com/linuxdynasty/ansible-examples/tree/master/playbooks](https://github.com/linuxdynasty/ansible-examples/tree/master/playbooks)

---

<div class="post-metadata">

**Author:** ![Dan\_Rough](https://avatars.discourse-cdn.com/v4/letter/d/48db29/32.png) [@Dan\_Rough](https://forum.ansible.com/u/Dan_Rough)\
**Post date:** [October 27, 2016, 6:12am UTC](https://forum.ansible.com/t/group-vars-and-ansibles-patterns-suggestions-please/22895/6 "2016-10-27T06:12:53Z")

</div>

This is really useful Allen. Thanks!

Dynamically including vars files was another option we’d considered. We had discounted it though as we were going to have to litter the include statement throughout our play books and roles which we didn’t like. Your dynamic\_vars playbook is a neat solution to the problem.

Dan
