Wildcard in group of hosts

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.

Have a look at: http://docs.ansible.com/intro_patterns.html#patterns

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?

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.

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.