Merge multiple inventories?

463 views
Skip to first unread message

Tony Coffman

unread,
Oct 23, 2017, 1:11:58 PM10/23/17
to AWX Project
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?




Alan Rominger

unread,
Oct 23, 2017, 2:52:42 PM10/23/17
to Tony Coffman, AWX Project
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

On Mon, Oct 23, 2017 at 1:11 PM, Tony Coffman <to...@emitony.com> wrote:
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?




--
You received this message because you are subscribed to the Google Groups "AWX Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to awx-project+unsubscribe@googlegroups.com.
To post to this group, send email to awx-p...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/awx-project/7a12e3b4-123e-44b1-93e3-2c4023140533%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Alan
github: AlanCoding

Matthew Jones

unread,
Oct 23, 2017, 9:16:38 PM10/23/17
to Alan Rominger, Tony Coffman, AWX Project
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. 


For more options, visit https://groups.google.com/d/optout.



--
Matt Jones
Principal Software Engineer
Ansible Tower
Reply all
Reply to author
Forward
0 new messages