Skip to content

lookup

Collection Note

This module is part of the opsmill.infrahub collection. To install the collection, use:

ansible-galaxy collection install opsmill.infrahub

Synopsis

  • Get inventory hosts from Infrahub

Parameters

Parameter Defaults / Choices Comments
api_endpoint
required
Endpoint of the Infrahub API
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 to send to Infrahub to obtain desired data
timeout
int
Default: 10
Timeout for Infrahub requests in seconds
token
required
Infrahub API token to be able to read against Infrahub.
Env: INFRAHUB_API_TOKEN
validate_certs Default: True
Whether or not to validate SSL of the Infrahub instance

Examples

- name: Infrahub lookup
  gather_facts: false
  hosts: localhost

  tasks:
    - name: SET FACT OF STRING
      ansible.builtin.set_fact:
        query_string: |
          query {
            BuiltinLocation {
              edges {
                node {
                  name {
                    value
                  }
                }
              }
            }
          }

    - name: Obtain list of sites from Infrahub
      ansible.builtin.set_fact:
        query_response: "{{ query('opsmill.infrahub.lookup', query=query_string) }}"

    - name: Print result
      ansible.builtin.debug:
        msg: "{{ query_response }}"

Return Values

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

Authors

  • Benoit Kohler (@bearchitek)