Skip to main content

Inventory inventory

Get inventory hosts from Infrahub

Parameters

ParameterTypeRequiredDefaultDescription
plugin``Yestoken that ensures this is a source file for the 'opsmill.infrahub' plugin.
api_endpoint``YesEndpoint of the Infrahub API
token``YesInfrahub API token to be able to read against Infrahub.
timeoutintNo10Timeout for Infrahub requests in seconds
nodesdictYesConfiguration for specific node types within Infrahub. Defines the attributes to include or exclude for each node.
branchstrNomainBranch in which the request is made
composedictNoList of custom Ansible host vars to create from the objects fetched from Infrahub
keyed_groupslistNo[]Create groups based on attributes or relationships. groups is created as attribute__value
groupsdictNoCreate groups based on jinja filter.
validate_certs``NoTrueWhether or not to validate SSL of the Infrahub instance

Examples

# inventory.yml file in YAML format
# Example command line: ansible-inventory -v --list -i .yml
# Add -vvv to the command to also see the GraphQL query that gets sent in the debug output.
# Add -vvvv to the command to also see the JSON response that comes back in the debug output.

# Minimum required parameters
plugin: opsmill.infrahub.inventory
api_endpoint: http://localhost:8000 # Can be omitted if the INFRAHUB_ADDRESS environment variable is set
token: 1234567890123456478901234567 # Can be omitted if the INFRAHUB_API_TOKEN environment variable is set

# Complete Example
# This will :
# - Retrieve in the branch "branch1" attributes for the Node Kind "InfraDevice"
# - The attributes wanted for "InfraDevice" are forced with the keyword "include"
# - Create 2 compose variable "hostname" ad "platform" (platform will override the attribute platform retrieved)
# - Create group based on the "site" name

strict: true

branch: "branch1"

nodes:
InfraDevice:
include:
- name
- platform.ansible_network_os
- primary_address.address
- site.name
- interfaces

compose:
hostname: name
platform: platform.ansible_network_os

keyed_groups:
- prefix: site
key: site.name

Return values

KeyTypeDescription
_listlistlist of composed dictionaries with key and value