Inventory Providers

GRU supports pluggable inventory providers. Inventory providers fill in the list of hosts that make up GRU’s view of the world. They allow grouping, listing and searching for hosts, as well as provide metadata for every host in the inventory.

Out of the box, GRU provides two different inventory providers: an ElasticSearch provider that assumes hosts appear as documents in an ElasticSearch cluster; and an EC2 provider that queries the AWS EC2 API

Configuring an Inventory Provider

at the most basic level, you need to set the inventory.provider configuration parameter to a fully qualified class name of a class that implements an inventory provider.

ElasticSearch Provider

The ElasticSearch provider assumes that you have configured an ElasticSearch cluster with an index containing hosts as documents. The document IDs in the index correlate to host IDs, and the documents are JSON encoded dictionaries of host metadata.

It’s actually pretty simple to create such an index. See the provided mapping file and an example script that populates the hosts index

To enable the ElasticSearch provider, please use gru.contrib.inventory.providers.ElasticSearchProvider as the value for inventory.provider and refer to the provider documentation.

Here’s a snippet of such a configuration:

---
inventory:
  provider: gru.contrib.inventory.providers.ElasticSearchProvider
  config:
    index: gru-inventory
    timeout_seconds: 10
    hosts:
      # HTTP endpoints to your elasticsearch clusters.
      # No need to specify all servers, they are used for discovery
      - http://10.0.0.1:9200
      - http://10.0.0.2:9200
  ...

EC2 Provider

To enable the EC2 provider, please use gru.contrib.inventory.providers.EC2Proivder as the value for inventory.provider and refer to the provider documentation.

The EC2 provider supports aggregation of hosts from several different AWS accounts and/or regions.

Here’s a snippet of such a configuration:

---
provider: gru.contrib.inventory.providers.EC2Provider
config:
  accounts:
    - aws_access_key_id: AKXXXXXXXXXXXXXXXXXX
      aws_secret_access_key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
      regions: ['us-east-1', 'us-west-2']

Writing your own

Writing an inventory provider is covered under Writing your own inventory providers