Skip to content

lookup_graphql

Collection Note

This module is part of the networktocode.nautobot collection. To install the collection, use:

ansible-galaxy collection install networktocode.nautobot
Added in version 1.1.0.

You need further requirements to be able to use this module, see the Requirements section for details.

Synopsis

  • Queries Nautobot via its GraphQL API through pynautobot

Requirements

The following Python packages are needed on the host that executes this module:

Parameters

Parameter Data Type Environment Variable Comments
api_version The Nautobot Rest API Version to use
Version Added: 4.1.0
graph_variables Dictionary of keys/values to pass into the GraphQL query See pynautobot GraphQL documentation for more details
query
required
The GraphQL formatted query string, see pynautobot GraphQL documentation.
token NAUTOBOT_TOKEN The API token created through Nautobot
url
required
NAUTOBOT_URL The URL to the Nautobot instance to query (http://nautobot.example.com:8000)
validate_certs Whether or not to validate SSL of the Nautobot instance

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 Values

Key Data Type Description Returned
data dict Data result from the GraphQL endpoint

Authors

  • Josh Vanderaa (@jvanderaa)