query_graphql¶
Collection Note
This module is part of the opsmill.infrahub collection. To install the collection, use:
Added in version0.0.1.
You need further requirements to be able to use this module, see the Requirements section for details.
Synopsis¶
- Queries Infrahub via its GraphQL API through Infrahub SDK
Requirements¶
The following Python packages are needed on the host that executes this module:
Parameters¶
| Parameter | Defaults / Choices | Comments |
|---|---|---|
| api_endpoint str |
Endpoint of the Infrahub API, optional env=INFRAHUB_ADDRESS | |
| branch str |
Default: main |
Branch in which the request is made |
| graph_variables dict |
Dictionary of keys/values to pass into the GraphQL query | |
| query str required |
GraphQL query parameters or filters to send to Infrahub to obtain desired data | |
| timeout int |
Default: 10 |
Timeout for Infrahub requests in seconds |
| token str |
The API token created through Infrahub, optional env=INFRAHUB_API_TOKEN | |
| update_hostvars bool |
Whether 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. | |
| validate_certs bool |
Default: True |
Whether or not to validate SSL of the Infrahub instance |
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¶
| Key | Data Type | Description | Returned |
|---|---|---|---|
| data | dict | Data result from the Infrahub GraphQL endpoint | success |
Authors¶
- Benoit Kohler (@bearchitek)