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.