Skip to main content

Modules modules

Queries Infrahub via its GraphQL API through Infrahub SDK

Parameters

ParameterTypeRequiredDefaultDescription
api_endpointstrNoEndpoint of the Infrahub API, optional env=INFRAHUB_ADDRESS
tokenstrNoThe API token created through Infrahub, optional env=INFRAHUB_API_TOKEN
timeoutintNo10Timeout for Infrahub requests in seconds
querystrYesGraphQL query parameters or filters to send to Infrahub to obtain desired data
graph_variablesdictNoDictionary of keys/values to pass into the GraphQL query
branchstrNomainBranch in which the request is made
validate_certsboolNoTrueWhether or not to validate SSL of the Infrahub instance
update_hostvarsboolNoFalseWhether or not to populate data in the in the root (example hostvars[inventory_hostname]) or within the 'data' key (example hostvars[inventory_hostname]['data']). Beware, that the root keys provided by the query will overwrite any root keys already present, leverage the GraphQL alias feature to avoid issues.

Examples

---
- name: Infrahub action plugin query_graphql
gather_facts: false
hosts: localhost

tasks:
- name: SET FACTS TO SEND TO GRAPHQL ENDPOINT
ansible.builtin.set_fact:
variables:
device_name: "atl1-edge1"
enabled: true

query_dict:
InfraDevice:
'@filters': {name__value: '$device_name'}
edges:
node:
name:
value: null
interfaces:
'@filters': {enabled__value: '$enabled'}
edges:
node:
name:
value: null

- name: Action Plugin
opsmill.infrahub.query_graphql:
query: "{{ query_dict }}"
graph_variables: "{{ variables }}"

Return values

KeyTypeDescription
datadictData result from the Infrahub GraphQL endpoint