# Wildcard in group of hosts

**URL:** <https://forum.ansible.com/t/wildcard-in-group-of-hosts/17062>\
**Category:** Ansible Project\
**Created:** [December 15, 2014, 3:13pm UTC](https://forum.ansible.com/t/wildcard-in-group-of-hosts/17062 "2014-12-15T15:13:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guillaume\_Subiron](https://avatars.discourse-cdn.com/v4/letter/g/c77e96/32.png) [@Guillaume\_Subiron](https://forum.ansible.com/u/Guillaume_Subiron)\
**Post date:** [December 15, 2014, 3:13pm UTC](https://forum.ansible.com/t/wildcard-in-group-of-hosts/17062/1 "2014-12-15T15:13:03Z")

</div>

Hi,

I manage multiple clients, and my servers are named using the following  
pattern:  
- foo-db01  
- foo-www01  
- bar-db01  
- bar-mail01  
- …

I would like to make one group by client, using a wildcard for example:

[foo-server]  
foo-\*

[bar-server]  
bar-\*

Is it possible to do something like that ? I tried to combine numeric  
and alphabetic ranges, but I can't find a way to do what I want.

Thanks.

---

<div class="post-metadata">

**Author:** ![vaida.dan](https://avatars.discourse-cdn.com/v4/letter/v/5daacb/32.png) [@vaida.dan](https://forum.ansible.com/u/vaida.dan)\
**Post date:** [January 4, 2015, 2:47pm UTC](https://forum.ansible.com/t/wildcard-in-group-of-hosts/17062/2 "2015-01-04T14:47:04Z")

</div>

Have a look at: [http://docs.ansible.com/intro\_patterns.html#patterns](http://docs.ansible.com/intro_patterns.html#patterns)

---

<div class="post-metadata">

**Author:** ![Francisco\_Reyes](https://avatars.discourse-cdn.com/v4/letter/f/b77776/32.png) [@Francisco\_Reyes](https://forum.ansible.com/u/Francisco_Reyes)\
**Post date:** [January 4, 2015, 8:34pm UTC](https://forum.ansible.com/t/wildcard-in-group-of-hosts/17062/3 "2015-01-04T20:34:15Z")

</div>

In addition to the suggestion of using patterns, which sounds like what you were looking for, perhaps another option may be to use different host files.

I also use ansible for clients, but my clients requirements are so different that other than some common roles the hosts are too different.

Are your client machines all similar? Is it something like the same type of setup for multiple clients?

---

<div class="post-metadata">

**Author:** ![Guillaume\_Subiron](https://avatars.discourse-cdn.com/v4/letter/g/c77e96/32.png) [@Guillaume\_Subiron](https://forum.ansible.com/u/Guillaume_Subiron)\
**Post date:** [January 4, 2015, 9:18pm UTC](https://forum.ansible.com/t/wildcard-in-group-of-hosts/17062/4 "2015-01-04T21:18:10Z")

</div>

Le 15/01/04 12:34, Francisco Reyes claviotta :

> \>  
> \> I manage multiple clients, and my servers are named using the following  
> \>  
> \>

Nope. Patterns can only be used when calling ansible. It would be  
awesome to use the same syntax in host definition, but we can't.

> In addition to the suggestion of using patterns, which sounds like what you  
> were looking for, perhaps another option may be to use different host files.
> 
> I also use ansible for clients, but my clients requirements are so  
> different that other than some common roles the hosts are too different.
> 
> Are your client machines all similar? Is it something like the same type of  
> setup for multiple clients?

Yes, all my clients have the same needs. Of course I have some  
specific playbooks that can only be used on one client (like deploying  
an app), but the majority is common.

The typical example is the playbook which creates Unix accounts. It is  
using a list "admins" in the inventory. This list is declared in  
group\_vars/ for all my clients (group\_vars/foo, group\_vars/bar…).

So what I'm looking for is to include foo-\* servers in the "foo"  
group, without having to list them one by one.

But I have read all the source code of the inventory, and my  
conclusion is that it's not possible. This is not the first time I  
feel disappointed by the inventory of Ansible. I really love  
everything else, but the inventory becomes completely unusable when it  
grows.

So I wrote a new inventory parser. I will submit it on Github soon.

Thanks for your answers.

---

<div class="post-metadata">

**Author:** ![Tom\_Bamford](https://avatars.discourse-cdn.com/v4/letter/t/c2a13f/32.png) [@Tom\_Bamford](https://forum.ansible.com/u/Tom_Bamford)\
**Post date:** [January 4, 2015, 11:46pm UTC](https://forum.ansible.com/t/wildcard-in-group-of-hosts/17062/5 "2015-01-04T23:46:25Z")

</div>

The default inventory has its limitations, but that’s exactly why Ansible supports dynamic inventory plugins, which are straightforward to write.

That said, you can use a form of patterns in static inventory, though I don’t know if it expands beyond simple numeric and character ranges.
