Wildcard in group of hosts

744 views
Skip to first unread message

Guillaume Subiron

unread,
Dec 15, 2014, 10:13:18 AM12/15/14
to ansible...@googlegroups.com
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.

--
Guillaume Subiron
Mail - mae...@subiron.org
GPG - 5BC2 EADB
Jabber - mae...@im.subiron.org
IRC - maethor@(freenode|geeknode)

Dan Vaida

unread,
Jan 4, 2015, 9:47:04 AM1/4/15
to ansible...@googlegroups.com, mae...@subiron.org

Francisco Reyes

unread,
Jan 4, 2015, 3:34:15 PM1/4/15
to ansible...@googlegroups.com, mae...@subiron.org
On Monday, December 15, 2014 10:13:18 AM UTC-5, Guillaume Subiron wrote:
I manage multiple clients, and my servers are named using the following


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?
 

Guillaume Subiron

unread,
Jan 4, 2015, 4:18:59 PM1/4/15
to ansible...@googlegroups.com
Le 15/01/04 12:34, Francisco Reyes claviotta :
> On Monday, December 15, 2014 10:13:18 AM UTC-5, Guillaume Subiron wrote:
> >
> > 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.

Tom Bamford

unread,
Jan 4, 2015, 6:46:48 PM1/4/15
to ansible...@googlegroups.com
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.


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/20150104211810.GA16870%40subiron.org.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages