Skip to content

[Bug]: nb_inventory.py not working with Netbox 3.2.x #775

@HardTy

Description

@HardTy

Ansible NetBox Collection version

v3.7.0

Ansible version

ansible [core 2.12.4]
  config file = /Users/rene/github/riege/ansible-localdns/ansible.cfg
  configured module search path = ['/Users/rene/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/rene/Library/Python/3.9/lib/python/site-packages/ansible
  ansible collection location = /Users/rene/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.12 (main, Mar 26 2022, 15:51:15) [Clang 13.1.6 (clang-1316.0.21.2)]
  jinja version = 3.0.1
  libyaml = True

NetBox version

v3.2.1

Python version

3.9

Steps to Reproduce

Try to get a inventory from Netbox like with ansible-inventory command.

$ ansible-inventory --list -i netbox-inventory.yml
 -vvv
ansible-inventory [core 2.12.4]
  config file = /Users/rene/github/riege/ansible-localdns/ansible.cfg
  configured module search path = ['/Users/rene/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/rene/Library/Python/3.9/lib/python/site-packages/ansible
  ansible collection location = /Users/rene/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible-inventory
  python version = 3.9.12 (main, Mar 26 2022, 15:51:15) [Clang 13.1.6 (clang-1316.0.21.2)]
  jinja version = 3.0.1
  libyaml = True
Using /Users/rene/github/riege/ansible-localdns/ansible.cfg as config file
host_list declined parsing /Users/rene/github/riege/ansible-localdns/netbox-inventory.yml as it did not pass its verify_file() method
script declined parsing /Users/rene/github/riege/ansible-localdns/netbox-inventory.yml as it did not pass its verify_file() method
Fetching: https://netbox.infraops.dev.riege.cloud/api/status
Fetching: https://netbox.infraops.dev.riege.cloud/api/docs/?format=openapi
toml declined parsing /Users/rene/github/riege/ansible-localdns/netbox-inventory.yml as it did not pass its verify_file() method
[WARNING]:  * Failed to parse /Users/rene/github/riege/ansible-localdns/netbox-inventory.yml with auto
plugin: Incorrect JSON payload:  <!DOCTYPE html> <html> <head>     <meta charset="utf-8"/>
<title>NetBox API</title>                                            <link rel="icon" type="image/png"
href="/static/drf-yasg/swagger-ui-dist/favicon-32x32.png"/>                    <link rel="stylesheet"
type="text/css" href="/static/drf-yasg/style.css"/>         <link rel="stylesheet" type="text/css"
href="/static/drf-yasg/swagger-ui-dist/swagger-ui.css">                         </head>  <body
class="swagger-body">          <div id="swagger-ui"></div>          <script id="swagger-settings"
type="application/json">{"docExpansion": "list", "deepLinking": false, "showExtensions": true,
"defaultModelRendering": "model", "defaultModelExpandDepth": 1, "defaultModelsExpandDepth": 1,
"showCommonExtensions": true, "supportedSubmitMethods": ["get", "put", "post", "delete", "options",
"head", "patch", "trace"], "displayOperationId": true, "persistAuth": false, "refetchWithAuth": false,
"refetchOnLogout": false, "fetchSchemaWithQuery": true, "validatorUrl": null}</script> <script
id="oauth2-config" type="application/json">{}</script>       <script src="/static/drf-yasg/swagger-ui-
dist/swagger-ui-bundle.js"></script>     <script src="/static/drf-yasg/swagger-ui-dist/swagger-ui-
standalone-preset.js"></script>     <script src="/static/drf-yasg/insQ.min.js"></script>     <script
src="/static/drf-yasg/immutable.min.js"></script>     <script src="/static/drf-yasg/url-
polyfill.min.js"></script>     <script src="/static/drf-yasg/swagger-ui-init.js"></script>          <a
id="oauth2-redirect-url" href="/static/drf-yasg/swagger-ui-dist/oauth2-redirect.html"
class="hidden"></a>       <div id="django-session-auth" class="hidden">                      <input
type="hidden" name="csrfmiddlewaretoken"
value="*****">
<div class='btn authorize'>                     <a id="auth" class="header__btn"
href="/login/?next=/api/docs/" data-sw-translate>
Django Login                                              </a>                 </div>
</div>  </body>  </html>
  File "/Users/rene/Library/Python/3.9/lib/python/site-packages/ansible/inventory/manager.py", line 290, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/Users/rene/Library/Python/3.9/lib/python/site-packages/ansible/plugins/inventory/auto.py", line 58, in parse
    plugin.parse(inventory, loader, path, cache=cache)
  File "/Users/rene/.ansible/collections/ansible_collections/netbox/netbox/plugins/inventory/nb_inventory.py", line 1887, in parse
    self.main()
  File "/Users/rene/.ansible/collections/ansible_collections/netbox/netbox/plugins/inventory/nb_inventory.py", line 1759, in main
    self.fetch_api_docs()
  File "/Users/rene/.ansible/collections/ansible_collections/netbox/netbox/plugins/inventory/nb_inventory.py", line 1387, in fetch_api_docs
    openapi = self._fetch_information(
  File "/Users/rene/.ansible/collections/ansible_collections/netbox/netbox/plugins/inventory/nb_inventory.py", line 392, in _fetch_information
    raise AnsibleError("Incorrect JSON payload: %s" % raw_data)
[WARNING]:  * Failed to parse /Users/rene/github/riege/ansible-localdns/netbox-inventory.yml with yaml
plugin: Plugin configuration YAML file, not YAML inventory
  File "/Users/rene/Library/Python/3.9/lib/python/site-packages/ansible/inventory/manager.py", line 290, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/Users/rene/Library/Python/3.9/lib/python/site-packages/ansible/plugins/inventory/yaml.py", line 112, in parse
    raise AnsibleParserError('Plugin configuration YAML file, not YAML inventory')
[WARNING]:  * Failed to parse /Users/rene/github/riege/ansible-localdns/netbox-inventory.yml with ini
plugin: Invalid host pattern '---' supplied, '---' is normally a sign this is a YAML file.
  File "/Users/rene/Library/Python/3.9/lib/python/site-packages/ansible/inventory/manager.py", line 290, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/Users/rene/Library/Python/3.9/lib/python/site-packages/ansible/plugins/inventory/ini.py", line 136, in parse
    raise AnsibleParserError(e)
[WARNING]: Unable to parse /Users/rene/github/riege/ansible-localdns/netbox-inventory.yml as an
inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
{
    "_meta": {
        "hostvars": {}
    },
    "all": {
        "children": [
            "ungrouped"
        ]
    }
}

It is the same behavior with ansible-playbook command.

Expected Behavior

Get a working Ansible inventory.

Observed Behavior

See "Steps to Reproduce".

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions