networktocode.nautobot.gql_inventory inventory – Nautobot inventory source using GraphQL capability

Note

This inventory plugin is part of the networktocode.nautobot collection (version 3.4.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install networktocode.nautobot.

To use it in a playbook, specify: networktocode.nautobot.gql_inventory.

Synopsis

  • Get inventory hosts from Nautobot using GraphQL queries

Requirements

The below requirements are needed on the local controller node that executes this inventory.

  • netutils

Parameters

Parameter

Comments

additional_variables

list / elements=string

Variable types and values to use while making the call

Default: []

api_endpoint

string / required

Endpoint of the Nautobot API

Configuration:

  • Environment variable: NAUTOBOT_URL

filters

dictionary

Granular device search query

Default: {}

follow_redirects

string

Determine how redirects are followed.

By default, follow_redirects is set to uses urllib2 default behavior.

Choices:

  • urllib2 ← (default)

  • all

  • yes

  • safe

  • none

group_by

list / elements=string

List of dot-sparated paths to index graphql query results (e.g. platform.slug)

The final value returned by each path is used to derive group names and then group the devices into these groups.

Valid group names must be string, so indexing the dotted path should return a string (i.e. platform.slug instead of platform)

If value returned by the defined path is a dictionary, an attempt will first be made to access the name field, and then the slug field. (i.e. platform would attempt to lookup platform.name, and if that data was not returned, it would then try platform.slug)

Default: []

plugin

string / required

Setting that ensures this is a source file for the ‘networktocode.nautobot’ plugin.

Choices:

  • networktocode.nautobot.gql_inventory

query

dictionary

GraphQL query to send to Nautobot to obtain desired data

Default: {}

timeout

integer

Timeout for Nautobot requests in seconds

Default: 60

token

string / required

Nautobot API token to be able to read against Nautobot.

This may not be required depending on the Nautobot setup.

Configuration:

  • Environment variable: NAUTOBOT_TOKEN

validate_certs

boolean

Allows connection when SSL certificates are not valid. Set to false when certificates are not trusted.

Choices:

  • no

  • yes ← (default)

Examples

# inventory.yml file in YAML format
# Example command line: ansible-inventory -v --list -i inventory.yml

# Add additional query parameter with query key and use filters
plugin: networktocode.nautobot.gql_inventory
api_endpoint: http://localhost:8000
validate_certs: True
query:
  tags: name
  serial:
  site:
    filters:
      tenant: "den"
    name:
    description:
    contact_name:
    description:
    region:
        name:

# To group by use group_by key
# Specify the full path to the data you would like to use to group by.
plugin: networktocode.nautobot.gql_inventory
api_endpoint: http://localhost:8000
validate_certs: True
group_by:
  - tenant.name
  - status.slug

# Add additional variables
plugin: networktocode.nautobot.gql_inventory
api_endpoint: http://localhost:8000
validate_certs: True
additional_variables:
  - device_role

# Add additional variables combined with additional query
plugin: networktocode.nautobot.gql_inventory
api_endpoint: http://localhost:8000
validate_certs: True
query:
  interfaces: name
additional_variables:
  - interfaces

# Filter output using any supported parameters
# To get supported parameters check the api/docs page for devices
plugin: networktocode.nautobot.gql_inventory
api_endpoint: http://localhost:8000
validate_certs: True
filters:
  name__ic: nym01-leaf-01
  site: nym01

Authors

  • Armen Martirosyan

Hint

Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.