networktocode / networktocode.nautobot / 4.5.0 / lookup / lookup_graphql Queries and returns elements from Nautobot GraphQL endpoint | "added in version" 1.1.0 of networktocode.nautobot" Authors: Josh VanDeraa (@jvanderaa)networktocode.nautobot.lookup_graphql (4.5.0) — lookup
Install with ansible-galaxy collection install networktocode.nautobot:==4.5.0
collections: - name: networktocode.nautobot version: 4.5.0
Queries Nautobot via its GraphQL API through pynautobot
# 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>') }}"
url: description: - The URL to the Nautobot instance to query (http://nautobot.example.com:8000) env: - name: NAUTOBOT_URL required: true query: description: - The GraphQL formatted query string, see [pynautobot GraphQL documentation](https://pynautobot.readthedocs.io/en/latest/advanced/graphql.html). required: true token: description: - The API token created through Nautobot env: - name: NAUTOBOT_TOKEN required: false api_version: description: - The Nautobot Rest API Version to use required: false version_added: 4.1.0 version_added_collection: networktocode.nautobot validate_certs: default: true description: - Whether or not to validate SSL of the Nautobot instance required: false graph_variables: description: - 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 required: false
data: description: - Data result from the GraphQL endpoint type: dict