# wildcard pattern for group membership

**URL:** <https://forum.ansible.com/t/wildcard-pattern-for-group-membership/12760>\
**Category:** Ansible Project\
**Created:** [May 2, 2013, 8:07pm UTC](https://forum.ansible.com/t/wildcard-pattern-for-group-membership/12760 "2013-05-02T20:07:22Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [May 2, 2013, 8:07pm UTC](https://forum.ansible.com/t/wildcard-pattern-for-group-membership/12760/1 "2013-05-02T20:07:22Z")

</div>

Michael,

would you consider a patch to the ini inventory to allow putting certain hosts or groups in a particular group?

e.g. something like

[development]  
_-dev-_

[applicationservers: children]  
app-\*

Before you tell me to use group\_by, the reason I’m looking for this functionality in the Inventory, is to be able to use it in patterns, and to the --limit option.

Serge

---

<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:** [May 2, 2013, 8:52pm UTC](https://forum.ansible.com/t/wildcard-pattern-for-group-membership/12760/2 "2013-05-02T20:52:31Z")

</div>

Doesn’t make any sense, because inventory defines what the names of the host actually are.

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [May 2, 2013, 9:07pm UTC](https://forum.ansible.com/t/wildcard-pattern-for-group-membership/12760/3 "2013-05-02T21:07:35Z")

</div>

I understood what you mean. That would be a more than trivial patch, with code that implements that after the inventory is build whilst remembering the patterns it encountered, but I don’t see why it would be impossible?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [May 2, 2013, 9:13pm UTC](https://forum.ansible.com/t/wildcard-pattern-for-group-membership/12760/4 "2013-05-02T21:13:14Z")

</div>

It is unfortunately logically confusing.

Inventory names hosts, this would not specify what hosts were real out of an infinite number.

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [May 2, 2013, 9:16pm UTC](https://forum.ansible.com/t/wildcard-pattern-for-group-membership/12760/5 "2013-05-02T21:16:18Z")

</div>

This is about a pattern matching the hosts already in the inventory, and add them to a specific group, not about generating an undefined set of hosts.

mvg,  
Serge van Ginderachter

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [May 3, 2013, 12:37am UTC](https://forum.ansible.com/t/wildcard-pattern-for-group-membership/12760/6 "2013-05-03T00:37:29Z")

</div>

Right, but you’re doing it in the inventory file.

If you want to pattern match specific hosts, there is already

hosts:_foo_

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [May 3, 2013, 1:54am UTC](https://forum.ansible.com/t/wildcard-pattern-for-group-membership/12760/7 "2013-05-03T01:54:58Z")

</div>

But that doesn’t allow me to configure variables for the group I want to generatein a group vars file.

Either way I’m going to switch to inventory scripts to do my thing.

mvg,  
Serge van Ginderachter

---

<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:** [May 3, 2013, 2:32am UTC](https://forum.ansible.com/t/wildcard-pattern-for-group-membership/12760/8 "2013-05-03T02:32:18Z")

</div>

Yes, inventory scripts were defined to allow people to build systems for when they disagreed with the default.

Please do.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [May 3, 2013, 2:13pm UTC](https://forum.ansible.com/t/wildcard-pattern-for-group-membership/12760/9 "2013-05-03T14:13:51Z")

</div>

I just did this with group\_by (define groups in inventory but assign them dynamically)

- hosts: “_web_”  
connection: local  
gather\_facts: false  
sudo: False  
tasks:
- name: Add hosts to web group  
group\_by: key=‘web’

but this gets clunky and you have to be careful with order (group/server pattern overlaps). I was about to start my own inventory plugin, but I’m happy if you beat me to it.

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [May 3, 2013, 2:33pm UTC](https://forum.ansible.com/t/wildcard-pattern-for-group-membership/12760/10 "2013-05-03T14:33:43Z")

</div>

> I just did this with group\_by (define groups in inventory but assign them  
> dynamically)

I know, but then you can't use that with the --limit option to target a  
part of your infra​​

but this gets clunky and you have to be careful with order (group/server

> pattern overlaps). I was about to start my own inventory plugin, but I'm  
> happy if you beat me to it.

Don't hold your breath, that plugin will be very specific to my  
environment, I don't expect it ​​to be very usefull for general use. I'll  
try to make it as generic as possible though.

The idea is to partametrize the environment as this:

- organise in group, parent child, as in the current ini  
- define a set of nodes (a list eg [1,2] bit could be anything  
- define a set of environments (dev, test, prod, optionally eg loadtest for  
particular applications)  
- define a series of applications within a particular group

I could go an define a template for hostname creation, eg  
{app}-{env}-{node}, yielding  
tomcat-test-1  
tomcat-test-2  
tomcat-prod-1  
..etc..

Right now I'm still thinking about how to organise this, and which config  
format to use.

(BTW: what was the reason in 0.6 to switch from yaml to ini?)

Serge

---

<div class="post-metadata">

**Author:** ![Dag\_Wieers](https://avatars.discourse-cdn.com/v4/letter/d/45deac/32.png) [@Dag\_Wieers](https://forum.ansible.com/u/Dag_Wieers)\
**Post date:** [May 3, 2013, 2:41pm UTC](https://forum.ansible.com/t/wildcard-pattern-for-group-membership/12760/11 "2013-05-03T14:41:44Z")

</div>

There wasn't really a switch from Yaml to INI, there was the decision to not support more than one inventory-file out-of-the-box, and the decision was to use the INI format because it is easier to use for new users.

The most important reason is that keeping two default formats feature-complete was more of a hassle than it was worth having the two formats around.

The rational was also that more advanced users would probably write their own inventory scripts anyway, so they might as well use the yaml inventory script which is an in-place replacement of what used to work before.

Not everyone agreed with using INI as the default (especially those that already were using yaml as a backend) but because of the yaml inventory script the impact is also not worth complaining about 😉
