netbox-community / ansible_modules

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

[Bug]: nb_inventory not working anymore with NetBox > 3.5 #1087

Closed david-sieg closed 11 months ago

david-sieg commented 11 months ago

Ansible NetBox Collection version

v3.14.0

Ansible version

ansible [core 2.15.5]
  config file = /home/user/ansible/ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/user/.venvs/ansible_2_15/lib64/python3.9/site-packages/ansible
  ansible collection location = /home/user/ansible/collections
  executable location = /home/user/.venvs/ansible_2_15/bin/ansible
  python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] (/home/user/.venvs/ansible_2_15/bin/python3.9)
  jinja version = 3.1.2
  libyaml = True

NetBox version

v3.6.3

Python version

3.9

Steps to Reproduce

I'll try to use updated NetBox as an inventory source with no success:

ansible-inventory -i netbox_inventory/netbox_test.yml --list

netbox.yml:


api_endpoint: 'https://netbox.domain.local'
token: 'TOKEN'
validate_certs: false```

### Expected Behavior

A usable inventory from NetBox.

### Observed Behavior

```ansible-inventory [core 2.15.5]
  config file = /home/user/ansible/ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/user/.venvs/ansible_2_15/lib64/python3.9/site-packages/ansible
  ansible collection location = /home/user/ansible/collections
  executable location = /home/user/.venvs/ansible_2_15/bin/ansible-inventory
  python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] (/home/user/.venvs/ansible_2_15/bin/python3.9)
  jinja version = 3.1.2
  libyaml = True
Using /home/user/ansible/ansible.cfg as config file
Using inventory plugin 'ansible_collections.netbox.netbox.plugins.inventory.nb_inventory' to process inventory source '/home/user/ansible/netbox_inventory/netbox_test.yml'
Fetching: https://netbox.domain.local/api/status
Fetching: https://netbox.domain.local/api/schema/?format=json
[WARNING]:  * Failed to parse /home/user/ansible/netbox_inventory/netbox_test.yml with auto plugin: {"error": "list.remove(x): x not in list", "exception": "ValueError", "netbox_version": "3.6.3", "python_version": "3.8.16"}
[WARNING]:  * Failed to parse /home/user/ansible/netbox_inventory/netbox_test.yml with yaml plugin: Plugin configuration YAML file, not YAML inventory
[WARNING]:  * Failed to parse /home/user/ansible/netbox_inventory/netbox_test.yml with ini plugin: Invalid host pattern 'plugin:' supplied, ending in ':' is not allowed, this character is reserved to provide a port.
[WARNING]: Unable to parse /home/user/ansible/netbox_inventory/netbox_test.yml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
{
    "_meta": {
        "hostvars": {}
    },
    "all": {
        "children": [
            "ungrouped"
        ]
    }
}```
aopdal commented 11 months ago

If I use a inventory file like the example below it works on my setup.

---
plugin: netbox.netbox.nb_inventory
#api_endpoint: unsing environment variable NETBOX_API
#token: using environment variable NETBOX_TOKEN
validate_certs: false
rnwolfe commented 11 months ago

This is discussed in #987.

You can do a ansible-galaxy collection install netbox.netbox --force to update the plugin for the new /api/docs -> /api/schema url change in v3.5.0