networktocode.nautobot.lookup_graphql lookup – Queries and returns elements from Nautobot GraphQL endpoint

Note

This lookup plugin is part of the networktocode.nautobot collection (version 5.1.1).

To install it, use: ansible-galaxy collection install networktocode.nautobot. You need further requirements to be able to use this lookup plugin, see Requirements for details.

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

New in networktocode.nautobot 1.1.0

Synopsis

  • Queries Nautobot via its GraphQL API through pynautobot

Requirements

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

  • pynautobot

Keyword parameters

This describes keyword parameters of the lookup. These are the values key1=value1, key2=value2 and so on in the following examples: lookup('networktocode.nautobot.lookup_graphql', key1=value1, key2=value2, ...) and query('networktocode.nautobot.lookup_graphql', key1=value1, key2=value2, ...)

Parameter

Comments

api_version

string

added in networktocode.nautobot 4.1.0

The Nautobot Rest API Version to use

graph_variables

string

Dictionary of keys/values to pass into the GraphQL query

See [pynautobot GraphQL documentation](https://pynautobot.readthedocs.io/en/latest/advanced/graphql.html) for more details

query

string / required

The GraphQL formatted query string, see [pynautobot GraphQL documentation](https://pynautobot.readthedocs.io/en/latest/advanced/graphql.html).

token

string

The API token created through Nautobot

Configuration:

  • Environment variable: NAUTOBOT_TOKEN

url

string / required

The URL to the Nautobot instance to query (http://nautobot.example.com:8000)

Configuration:

  • Environment variable: NAUTOBOT_URL

validate_certs

string

Whether or not to validate SSL of the Nautobot instance

Default: :ansible-option-default:`true`

Examples

# Make API Query without variables
- name: SET FACT OF STRING
  set_fact:
    query_string: |
      query {
        locations {
          id
          name
          parent {
            name
          }
        }
      }

# Make query to GraphQL Endpoint
- name: Obtain list of locations from Nautobot
  set_fact:
    query_response: "{{ query('networktocode.nautobot.lookup_graphql', query=query_string, url='https://nautobot.example.com', token='<redact>') }}"

# Example with variables
- name: SET FACTS TO SEND TO GRAPHQL ENDPOINT
  set_fact:
    graph_variables:
      location_name: DEN
    query_string: |
      query ($location_name:String!) {
          locations (name: $location_name) {
          id
          name
          parent {
              name
          }
          }
      }

# Get Response with variables
- name: Obtain list of devices from Nautobot
  set_fact:
    query_response: "{{ query('networktocode.nautobot.lookup_graphql', query_string, graph_variables=graph_variables,
      url='https://nautobot.example.com', token='<redact>') }}"

Return Value

Key

Description

data

dictionary

Data result from the GraphQL endpoint

Returned: success

Authors

  • Josh VanDeraa (@jvanderaa)

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.