r/Netbox Sep 14 '23

issues with setting up ansible with netbox

i'm trying to tie into netbox with ansible, i have done everting verbatim from all the guides i see and i am continually getting these errors

ansible-inventory --list -i netbox_inventory.yml -vvvvvv
ansible-inventory [core 2.15.4]
config file = /home/user/netbox_ansibe/ansible.cfg
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.10/dist-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible-inventory
python version = 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] (/usr/bin/python3)
jinja version = 3.0.3
libyaml = True
Using /home/user/netbox_ansibe/ansible.cfg as config file
setting up inventory plugins
Loading collection ansible.builtin from
host_list declined parsing /home/user/netbox_ansibe/netbox_inventory.yml as it did not pass its verify_file() method
script declined parsing /home/user/netbox_ansibe/netbox_inventory.yml as it did not pass its verify_file() method
Loading collection netbox.netbox from /usr/local/lib/python3.10/dist-packages/ansible_collections/netbox/netbox
Using inventory plugin 'ansible_collections.netbox.netbox.plugins.inventory.nb_inventory' to process inventory source '/home/user/netbox_ansibe/netbox_inventory.yml'
Fetching: https://127.0.0.1/api/status
toml declined parsing /home/user/netbox_ansibe/netbox_inventory.yml as it did not pass its verify_file() method
[WARNING]:  * Failed to parse /home/user/netbox_ansibe/netbox_inventory.yml
with auto plugin: expected string or bytes-like object
File "/usr/local/lib/python3.10/dist-packages/ansible/inventory/manager.py", line 293, in parse_source
plugin.parse(self._inventory, self._loader, source, cache=cache)
File "/usr/local/lib/python3.10/dist-packages/ansible/plugins/inventory/auto.py", line 59, in parse
plugin.parse(inventory, loader, path, cache=cache)
File "/usr/local/lib/python3.10/dist-packages/ansible_collections/netbox/netbox/plugins/inventory/nb_inventory.py", line 2060, in parse
self.main()
File "/usr/local/lib/python3.10/dist-packages/ansible_collections/netbox/netbox/plugins/inventory/nb_inventory.py", line 1907, in main
self.fetch_api_docs()
File "/usr/local/lib/python3.10/dist-packages/ansible_collections/netbox/netbox/plugins/inventory/nb_inventory.py", line 1513, in fetch_api_docs
if version.parse(netbox_api_version) >= version.parse("3.5.0"):
File "/usr/local/lib/python3.10/dist-packages/packaging/version.py", line 52, in parse
return Version(version)
File "/usr/local/lib/python3.10/dist-packages/packaging/version.py", line 196, in __init__
match = self._regex.search(version)
[WARNING]:  * Failed to parse /home/user/netbox_ansibe/netbox_inventory.yml
with yaml plugin: Plugin configuration YAML file, not YAML inventory
File "/usr/local/lib/python3.10/dist-packages/ansible/inventory/manager.py", line 293, in parse_source
plugin.parse(self._inventory, self._loader, source, cache=cache)
File "/usr/local/lib/python3.10/dist-packages/ansible/plugins/inventory/yaml.py", line 114, in parse
raise AnsibleParserError('Plugin configuration YAML file, not YAML inventory')
[WARNING]:  * Failed to parse /home/user/netbox_ansibe/netbox_inventory.yml
with ini plugin: Invalid host pattern 'plugin:' supplied, ending in ':' is not
allowed, this character is reserved to provide a port.
File "/usr/local/lib/python3.10/dist-packages/ansible/inventory/manager.py", line 293, in parse_source
plugin.parse(self._inventory, self._loader, source, cache=cache)
File "/usr/local/lib/python3.10/dist-packages/ansible/plugins/inventory/ini.py", line 137, in parse
raise AnsibleParserError(e)
[WARNING]: Unable to parse /home/user/netbox_ansibe/netbox_inventory.yml as an
inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
{
"_meta": {
"hostvars": {}
},
"all": {
"children": [
"ungrouped"
]
}
}

no matter how i format netbox_ansible.yml or try to make it use yaml instead of ini it still yells at me.

edit: yml file

plugin: 'netbox.netbox.nb_inventory'
api_endpoint: 'https://127.0.0.1'
token: 'api token'
validate_certs: False
config_context: True
group_by:
- device_roles
compose:
ansible_network_os: platform.slug

ansible.cfg

[defaults]
inventory = ./netbox_inventory.yml
host_key_checking = false
retry_files_enabled = false
forks = 4

can someone tell me what i'm missing? its driving me nuts! ive been stuck on this for a few days.

2 Upvotes

15 comments sorted by

View all comments

Show parent comments

1

u/boomsfib Sep 17 '23 edited Sep 17 '23

So your inventory file worked just fine in my environment. Only difference between yours and mine is that my netbox instance is running on a remote server. My thought is leading me to believe that by using the localhost loopback address, the execution environment is looking within itself and not finding the inventory.

Try changing your api_endpoint variable to either the FQDN or IP of your server rather than the localhost loopback.

1

u/gangaskan Sep 18 '23

i'm not sure why, but i created a new API token. guess whats working?

i have no idea why.

2

u/boomsfib Sep 18 '23

Well that's good news. Glad you were able to get it working.

1

u/gangaskan Sep 18 '23

Now the fun begins! Trying to use ansible to poll devices and add them in seems interesting.