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 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.lookup_graphql
.
New in version 1.1.0: of networktocode.nautobot
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
Parameters¶
Parameter |
Comments |
---|---|
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 |
|
The GraphQL formatted query string, see [pynautobot GraphQL documentation](https://pynautobot.readthedocs.io/en/latest/advanced/graphql.html). |
|
The API token created through Nautobot Configuration:
|
|
The URL to the Nautobot instance to query (http://nautobot.example.com:8000) Configuration:
|
|
Whether or not to validate SSL of the Nautobot instance Default: “yes” |
Examples¶
# Make API Query without variables
- name: SET FACT OF STRING
set_fact:
query_string: |
query {
sites {
id
name
region {
name
}
}
}
# Make query to GraphQL Endpoint
- name: Obtain list of sites 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:
site_name: DEN
query_string: |
query ($site_name:String!) {
sites (name: $site_name) {
id
name
region {
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¶
Common return values are documented here, the following are the fields unique to this lookup:
Key |
Description |
---|---|
Data result from the GraphQL endpoint Returned: success |