netbox-community / ansible_modules

NetBox modules for Ansible using Ansible Collections
GNU General Public License v3.0
330 stars 213 forks source link

[Bug]: unable to redefine Ansible host with IP address of other VM interface #1132

Open dschemp opened 10 months ago

dschemp commented 10 months ago

Ansible NetBox Collection version

v3.16.0

Ansible version

ansible [core 2.15.0]
  config file = None
  configured module search path = ['/home/dschemp/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/dschemp/.local/lib/python3.10/site-packages/ansible
  ansible collection location = /home/dschemp/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/dschemp/.local/bin/ansible
  python version = 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True

NetBox version

v3.6.6

Python version

3.10

Steps to Reproduce

interfaces: true compose: ansible_host: ((interfaces | selectattr('tags', 'contains', 'management') | list)[0].ip_addresses[0].address) | split('/') | first strict: true

- call `ansible-inventory -i netbox_inventory.yml --graph --vars`

### Expected Behavior

Return the following output:

@all: |--@ungrouped: | |--grafana01 | | |--{ansible_host = 99.99.99.99} | | |--{interfaces = [...]} | | |--[...]

I expect the variable `ansible_host` to be the IP address as defined in the interface with the tag `management` attached to it.

### Observed Behavior

[WARNING]: Failed to parse /home/dschemp/Projects/ansible-netbox/netbox_inventory.yml with auto plugin: Could not set ansible_host for host grafana01: 'interfaces' is undefined. 'interfaces' is undefined [WARNING]: Failed to parse /home/dschemp/Projects/ansible-netbox/netbox_inventory.yml with yaml plugin: Plugin configuration YAML file, not YAML inventory [WARNING]: * Failed to parse /home/dschemp/Projects/ansible-netbox/netbox_inventory.yml with ini plugin: Invalid host pattern '---' supplied, '---' is normally a sign this is a YAML file. [WARNING]: Unable to parse /home/dschemp/Projects/ansible-netbox/netbox_inventory.yml as an inventory source [WARNING]: No inventory was parsed, only implicit localhost is available @all: |--@ungrouped:

dschemp commented 10 months ago

For clarification: we have virtual machines with different interfaces, one of which being a management interface over which we can use Ansible. This does not have to be the primary IP for the VM. For reasons I cannot explain we are unable to set the management interface / IP as the primary IP.