Vmware_vm_inventory : Select a specific IP address for use by ansible

romgo
Fri, 18 Oct 2024 14:37:42 +0000
Get Help

Hello,

I am trying to use vmware_vm_inventory plugin, this is working but in my environment I need to select a specific IP for ansible inventory. Indeed my VM has several IPs, only one can be used by ansible.

Hopefully there is an exemple in the documentation for this particular need
https://docs.ansible.com/ansible/latest/collections/community/vmware/vmware_vm_inventory_inventory.html#examples

Here is my config :

plugin: vmware_vm_inventory
strict: False
hostname: vcsa.domain.local
username: administrator@vsphere.local
password: PASSWORD
validate_certs: False
with_tags: False
hostnames:
    - 'guest.hostName'
    - 'config.name'
groups:
  VMs: True
compose:
      # Set the IP address used by ansible to one that starts by 10.207.
      ansible_host: >-
        guest.net
        | selectattr('ipAddress')
        | map(attribute='ipAddress')
        | flatten
        | select('match', '^10.207.*')
        | list
        | first
      properties:
        - guest.net

The issue is that the test VM return the following

{
    "config.cpuHotAddEnabled": false,
    "config.cpuHotRemoveEnabled": false,
    "config.guestId": "debian9_64Guest",
    "config.hardware.numCPU": 2,
    "config.instanceUuid": "50211c6c-6947-555-dade0e-56c3a1adc846",
    "config.name": "glpi",
    "config.template": false,
    "config.uuid": "42471-8c7c-a6e8-b360-f021f533b782",
    "guest.guestId": "debian9_64Guest",
    "guest.guestState": "running",
    "guest.hostName": "glpi",
    "guest.ipAddress": "10.206.200.56",
    "name": "glpi",
    "properties": [
        "guest.net"
    ],
    "runtime.connectionState": "connected",
    "runtime.maxMemoryUsage": 2048,
    "summary.runtime.powerState": "poweredOn"
}

guest.ipAddress still return 10.206 interface instead of 10.207. interface IP.
Is there any way to debug this “compose” section ?

thank you for your help

1 post - 1 participant