Re: REST API endpoints and the ansible netbox plugin

678 views
Skip to first unread message
Message has been deleted
Message has been deleted

Brian Candler

unread,
Jul 5, 2021, 1:43:06 PM7/5/21
to NetBox
Whatever problem you have, it's not for the reason you describe.  I use the ansible netbox inventory (with Netbox v2.11.7), and it works fine.  It correctly accesses paths under `/api/`.

Perhaps if you post your ansible netbox configuration, someone can identify the problem with it.

I have in ansible.cfg:

[inventory]
enable_plugins = netbox, ini

And here is my netbox.yaml:

# Requires:
# ansible-galaxy collection install netbox.netbox
#
# To test:
# ansible-inventory -v --list -i netbox.yaml

plugin: netbox.netbox.nb_inventory
token: XXXXXXXX
validate_certs: True

# Do not use config_context unless patch has been applied to
# /usr/lib/python2.7/dist-packages/ansible/plugins/inventory/netbox.py
config_context: True
group_by:
  - sites
  - device_roles
  # Grouping by tags for Netbox 2.9 fixed by https://github.com/netbox-community/ansible_modules/pull/333
  - tags
query_filters:
  - tag: ansible

Start with a simpler configuration by removing the config_context, group_by and query_filters sections.

It *is* slow to start up though.  See https://github.com/netbox-community/netbox/issues/6423

On Monday, 5 July 2021 at 17:29:14 UTC+1 clement....@gmail.com wrote:
Hello, 

When I use the netbox plugin for ansible (nb_inventory) I got an error "KeyError: /dcim/devices/'"  because all my endpoints are prefixed with "/ api / <path>", my key is "/api/dcim/devices/". I looked for how to modify this parameter but without success. Does this speak to anyone?

thank you in advance for your help.

Message has been deleted

Brian Candler

unread,
Jul 6, 2021, 2:56:19 AM7/6/21
to NetBox
Have you modified Netbox in some way?  Or you are saying that the *identical* docker image running under docker-compose runs differently under kubernetes?  If it's the latter, then please show your kubernetes resources - did you write them yourself, or did you take them from somewhere else (if so where?)  Include your service and ingress definitions.  Also, how does your configuration.py differ between the two deployments?  Have you changed the BASE_PATH setting?  It should be BASE_PATH = ''
(unless you're using path-based routing on your Kubernetes ingress, in which case it will be some prefix like BASE_PATH='/netbox')

For comparison, here's what I get from my home, non-docker installation of Netbox:

{"swagger": "2.0", "info": {"title": "NetBox API", "description": "API to access NetBox", "termsOfService": "https://github.com/netbox-community/netbox", "license": {"name": "Apache v2 License"}, "version": "2.11"}, "host": "netbox.example.net", "schemes": ["https"], "basePath": "/api", "consumes": ["application/json"], "produces": ["application/json"], "securityDefinitions": {"Bearer": {"in": "header", "name": "Authorization", "type": "apiKey"}}, "security": [{"Bearer": []}], "paths": {"/circuits/circuit-terminations/": {"get": {"operationId": "circuits_circuit-terminations_list", "description": "", "parameters": [{"name": "id", "in": "query", "description": "", "required": false, "type": "string"}, ...

On Monday, 5 July 2021 at 21:11:33 UTC+1 clement....@gmail.com wrote:
Hello , 

Thanks for your reply Brian however my exact problem is that my endpoints in my devel  instance (which is running in a k8s cluster) are prefixed by /api  (see below) and my basePath is "/"
eg: "paths": { "/api/circuits/circuit-terminations/"

{ "swagger": "2.0", "info": { "title": "NetBox API", "description": "API to access NetBox", "termsOfService": "https://github.com/netbox-community/netbox", "license": { "name": "Apache v2 License" }, "version": "2.11" }, "host": "netbox-dev.obfuscated", "schemes": [ "https" ], "basePath": "/", "consumes": [ "application/json" ], "produces": [ "application/json" ], "securityDefinitions": { "Bearer": { "type": "apiKey", "name": "Authorization", "in": "header" } }, "security": [ { "Bearer": [ ] } ], "paths": { "/api/circuits/circuit-terminations/": { "get": { "operationId": "api_circuits_circuit-terminations_list", "description": "", "parameters": [ { "name": "id", "in": "query", "description": "", "required": false, "type": "string" },



Then with the same image but in a local environment (docker-compose) the things are not the same and my endpoints are not prefixed by  /api and the basePath is "/api" (which is what I would to have in my devel instance, and  that I am trying to configure without success)
eg : paths: { /circuits/circuit-terminations/:

{ swagger: "2.0", info: { title: "NetBox API", description: "API to access NetBox", termsOfService: "https://github.com/netbox-community/netbox", license: { name: "Apache v2 License" }, version: "2.11" }, host: "127.0.0.1:49154", schemes: [ "http" ], basePath: "/api", consumes: [ "application/json" ], produces: [ "application/json" ], securityDefinitions: { Bearer: { type: "apiKey", name: "Authorization", in: "header" } }, security: [ { Bearer: [ ] } ], paths: { /circuits/circuit-terminations/: { get: { operationId: "circuits_circuit-terminations_list", description: "", parameters: [ { name: "id", in: "query", description: "", required: false, type: "string" }, { name: "term_side", in: "query", description: "", required: false, type: "string"

With my local version on docker-compose the ansible plugin (nb_inventory) works perfectly. 
What I can't find is the way to act on this prefix. (eg remove the /api in /api/circuits/circuit-terminations/)
Reply all
Reply to author
Forward
0 new messages