hi,
i would like to organize my inventory (which is set up and maintained manually):
one inventory file per os (currently linux and windows) with one group in each file (e.g. alllinux and allwindows)
put group-information into each host (in the inventory file or in host-vars-directory)
my goal: i want to configure information per host to control if a playbook may or may not work on a host. but i don’t want to have different inventory files. i think it would be easier to have it “my way” (kind of tags per host).
The problem was posed with setting variables per host in inventory,
you can use the constructed inventory to use those variables to create
groups, the plays can filter only for the groups they are known to
work with or not, i.e hosts: valid_groups or hosts:
normalgropus:!invalid_for_this_play.
if you are getting teh variables dynamically, you can do same/similar
with group_by, but then you need 3 plays, 1 to gather the info, 2 to
use the group_by 3 the original play that processes the 'valid
group(s)'
... put group-information into each host ... per host to
control if a playbook may or may not work on a host
The playbook name is not available to the inventory
plugins. The below solution provides the inventory plugin
with the playbook name in the extra variable. The allowed
hosts are listed in a dictionary in group_vars.
* Create a dictionary with the lists of the allowed hosts
* Unfortunately, the name of the playbook is not available
in the inventory plugins. Therefor, you have to provide
it explicitly. For example, in the extra vars *my_play*