# group\_by and group vars

**URL:** <https://forum.ansible.com/t/group-by-and-group-vars/14261>\
**Category:** Ansible Project\
**Created:** [January 3, 2014, 6:18pm UTC](https://forum.ansible.com/t/group-by-and-group-vars/14261 "2014-01-03T18:18:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Coddington](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Matt\_Coddington](https://forum.ansible.com/u/Matt_Coddington)\
**Post date:** [January 3, 2014, 6:18pm UTC](https://forum.ansible.com/t/group-by-and-group-vars/14261/1 "2014-01-03T18:18:53Z")

</div>

I use group\_by to set up some groups in a play, but it looks like this doesn’t automatically load anything i have in group\_vars for those new groups. I suspect group\_vars are getting picked up only at the beginning of a play.

If you know the set of groups you’re creating with group\_by, you can add an include\_vars just after the grouping, which is how i’m working with things for now. How are other folks dealing with this? I was at first thinking it might be nice for group\_by to implicitly load group\_vars when it sets up groups, but then realized this could break variable precedence. Is it a valid feature request, maybe one that could be configurable, or should I look to work around things (via include\_vars and/or by making sure anything that needs group\_vars exists in my inventory as opposed to trying to set it up in group\_by)?

thanks,  
matt

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [January 3, 2014, 11:37pm UTC](https://forum.ansible.com/t/group-by-and-group-vars/14261/2 "2014-01-03T23:37:44Z")

</div>

“but it looks like this doesn’t automatically load anything i have in group\_vars for those new groups”

When you say “new groups”, do you mean the group is not defined in inventory or is defined and does not have hosts?

In either case, I would like this would work, yes.

This seems like (if reproducible on devel) there should be a ticket opened.

I don’t think it would break precedence and could be done in a reasonably sane way, but I haven’t really dug in yet.

---

<div class="post-metadata">

**Author:** ![Matt\_Coddington](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Matt\_Coddington](https://forum.ansible.com/u/Matt_Coddington)\
**Post date:** [January 4, 2014, 1:29am UTC](https://forum.ansible.com/t/group-by-and-group-vars/14261/3 "2014-01-04T01:29:10Z")

</div>

Hadn’t considered defining the group without hosts in inventory, but tried that and it doesn’t work that way either. Had been trying on 1.4.3, but just tried as well on devel and it shows the same behavior. I’ve submitted issue #5499.

thanks!  
matt

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [January 4, 2014, 1:56am UTC](https://forum.ansible.com/t/group-by-and-group-vars/14261/4 "2014-01-04T01:56:00Z")

</div>

Thanks, there was a report about something about dynamic hosts and host\_vars (uncommon) recently so I think the fix is likely generic.

It’s keeping track of whether we’ve scanned group\_vars or host\_vars when adding a new group or host, and then adding them at that time, etc, or something related.

I’m marking both of these for the priority queue (note: the priority queue is ~30 tickets).

---

<div class="post-metadata">

**Author:** ![Matt\_Coddington](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Matt\_Coddington](https://forum.ansible.com/u/Matt_Coddington)\
**Post date:** [January 4, 2014, 4:28am UTC](https://forum.ansible.com/t/group-by-and-group-vars/14261/5 "2014-01-04T04:28:04Z")

</div>

thanks! i’ll keep an eye on the issue and test it out when it’s resolved.

matt
