ansible_modules
ansible_modules copied to clipboard
[Bug]: unable to redefine Ansible host with IP address of other VM interface
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
- Create a virtual machine
- Assign two interfaces with a single IP address to that VM each (
1.1.1.1/28
and99.99.99.99/32
) - Assign the first interface as the primary IP of the VM
- Assign the second interface of the VM the tag called
management
- Create a dynamic inventory called
netbox_inventory.yml
with the following configuration:
---
plugin: "netbox.netbox.nb_inventory"
api_endpoint: "[...]"
token: "[...]"
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: