VMWare based source gets wrong ansible_host

I have two nics on my vm. One for normal network operations, another dedicated to our SAN. When my VMWare source adds the vm to the inventory, the ansible_host value is set to the ip of the SAN nic. As is ansible_ssh_host.

DNS is configured to use the normal network nic’s ip address.

Is there a way to fix that?

Thanks!

We return what is emitted by the core ansible vmware inventory script (we call it behind the scenes):

https://github.com/ansible/ansible/blob/devel/contrib/inventory/vmware_inventory.py

It looks like you can control this:

https://github.com/ansible/ansible/blob/devel/contrib/inventory/vmware_inventory.ini#L59-L61

We take some free-form configuration in the source_vars section of the inventory source so if you can figure out what specific value is needed for host_pattern to resolve what you want then you can put that in the “Source Vars” section of the Inventory Source when you are defining it.

Unfortunately I don’t use a lot of vmware so I can’t help you figure out exactly what you need but the ini file I linked to should provide a good starting place. The ansible vmware inventory module uses pyvmomi behind the scenes which is a python interface to the vmware soap interface.

We take some free-form configuration in the source_vars section of the inventory source so if you can figure out what specific value is needed for host_pattern to resolve what you want then you can put that in the “Source Vars” section of the Inventory Source when you are defining it.

Ah, I hadn’t seen the host_pattern key. Thanks.

Now, to figure out what to put there…

The correct ip isn’t even listed in the hosts variables section when I view that in the inventory. So, I somehow need to figure out a way to get info from both network cards into a place I can use it…

Is that even something that’s possible without modifying https://github.com/ansible/ansible/blob/devel/contrib/inventory/vmware_inventory.py ?

It’s possible, I’m not sure though :confused:

If you find it needs to be pushed into vmware_inventory.py we can pull it in and then contribute it upstream to ansible.