Tags and Groups - nsg/ansible-inventory GitHub Wiki
It is important that you understand the difference between tag groups and normal groups and how they are assigned.
Normal groups
These are simple in the sense that they works exactly like normal Ansible groups like [group]
and so on. Let me explain with a example.
[mygroup:children]
webserver
database
[webserver]
www1.example.com
www2.example.com
[database]
db1.example.com
To define the same thing in YAML use something like this:
---
mygroup:
webserver:
- www1.example.com
- www2.example.com
database:
- db1.example.com
Automatic tag groups
The example above actually creates four more groups, the group www
, db
, example
and com
. Basically the host and domain name is split on [^0-9a-z]
and the hosts are also put in these groups. It is important to remember that tag groups are not children under any other group.
The example above resolved to this layout:
mygroup www db example com
/ \ | | | |
webserver db www1 db1 www1 www1
| | www2 www2 www2
www1 db1 db1 db1
www2
Yes, the host are defines several times, this is a hack but it works. You just need to remember a few things.
- Never define the same variable to a "normal group" and "a tag group" at the same time, the behavior for this is undefined and the code may eat your kittens and servers. Well, not really, the groups are parsed alphabetical... but really this is confusing keep them separated is the only sane way.
- If possible only use the tag groups to assign variables and to control/limit the flow.
You can also create your own rules, for that see [matcher groups](Matcher Groups).