My final question today, promise 
It seems that you can have the same machine in multiple groups. Is this frowned upon? For example:
[macmini]
s1
s2
s3
[dnsserver]
s1
s2
[dhcpserver]
s2
s3
This I can see as being useful. There are a number of orthogonal traits which might be applied to a machine based not only on what is function(s) are but what hardware it is.
On the other hand, this introduces a management headache: if I want to comment out a server (e.g. it’s gone away temporarily), I have to find all the places where that server is mentioned.
That wouldn’t be an issue if you could do group membership the other way round (y is a member of group x, rather than group x contains y):
s1 groups=macmini,dnsserver
s2 groups=macmini,dnsserver,dhcpserver
s3 groups=macmini,dhcpserver
However, that doesn’t seem to be supported. It might be possible to fake it up using variables and group_by I guess.
I realise that there are “roles”, but in the above example, to avoid the same host being in different groups I would have to synthesise groups for each combination of roles used, e.g.
[macmini_dnsserver]
s1
[macmini_dnsserver_dhcpserver]
s2
[macmini_dhcpserver]
s3
Then the playbook could have appropriate bindings between groups and roles.
Am I missing something obvious here? Is there a way to disable a host, without removing it from all groups?
Thanks,
Brian.
I don't think I have a machine in less than 4 groups and no, no shortcut,
you need to remove all instances of a host. unless you want to run all
commands with --limit 'all:!<host>'
machines can be in multiple groups, and groups can be in groups.
It’s a quite intentional feature.
Groups often describe geography or purpose or environment and all sorts of things.
OK that’s good, it means I’m not abusing things.
So my problem is: what’s the cleanest way to say “machine s2 is currently not present, don’t try to connect to it?”
If it’s in lots of groups, I need to comment it out of every one. And when it’s back, I need to remember to uncomment it from all.
Something like “ansible_connection=none” would do, I guess.
What I’d really like is to be able to say
s1 groups=g1,g2,g3
group_by: key={{groups}}
but there is little documentation for group_by, and whether there’s any way to give it a multi-valued item (either a list or a JSON object)
Regards,
Brian.
Of course I meant YAML not JSON 
What I’d really like is to be able to say
s1 groups=g1,g2,g3
Actually, it turns out that the “add_hosts” module supports exactly this syntax. It dynamically creates the groups if they don’t exist, then adds the host to them. It understands four special parameters - ‘name’, ‘hostname’, ‘groupname’, ‘groups’ - and anything else is considered to be setting a host variable.
So, how would people feel about adding the same to the main inventory file too?
Looks like it would be a small change to lib/ansible/inventory/ini.py
I don’t understand what you are asking.
I’m fine with adding a variable that says “ansible_skip: True” or something on the host or group though. Seems clearer.