Merge multiple inventories?

It seems like if I pull in hosts from two sources (VMware and Foreman), I’ll end up with duplicate hosts - therefore one set of hosts will have to have alternate names generated. Is there a way to pull in inventory from multiple sources and get them to generate one set of common hosts with groups from both sources using hostname or IP matching or some other reconciliation?

Tony,

The inventory import command has an option --instance-id-var, which allows you to give some key inside of the host variables which defines host uniqueness. These are also configurable in your settings via variables that follow the pattern %s_INSTANCE_ID_VAR. In your case, you would need to toggle these in both the VMware and Foreman sections in settings.

Alan

I don’t think this will get the uniqueness that is desired, Alan. If they are “named” the same from the ansible inventory perspective then one will overwrite the other (as we are keyed off the name of the host as its returned from the import). instance id var is there so that tower can track changes in things like name by having a non-changing key that we can always look up.

The problem is that within an inventory names have to be unique and it doesn’t matter where in the inventory or group structure that these hosts re-occur. Think about a normal inventory file structure

hostA avar=foo
hostB avar=bar

[group1]
hostA avar=far <--- ansible will think this is the same as hostA above

Unfortunately you are almost certainly going to need to find a way to uniquely name these hosts between inventory sources… unfortunately the inventory import scripts don’t usually provide much help in this department.