Forge Home

hiera_graphql

A GraphQL backend for Hiera 5.

325 downloads

325 latest version

5.0 quality score

We run a couple of automated
scans to help you access a
module's quality. Each module is
given a score based on how well
the author has formatted their
code and documentation and
modules are also checked for
malware using VirusTotal.

Please note, the information below
is for guidance only and neither of
these methods should be considered
an endorsement by Puppet.

Version information

  • 0.1.0 (latest)
released Nov 8th 2022
This version is compatible with:
  • Puppet Enterprise 2023.2.x, 2023.1.x, 2023.0.x, 2021.7.x, 2021.6.x, 2021.5.x, 2021.4.x, 2021.3.x, 2021.2.x, 2021.1.x, 2021.0.x, 2019.8.x
  • Puppet >= 6.21.0 < 8.0.0
  • , , , , , , , , , , ,

Start using this module

  • r10k or Code Manager
  • Bolt
  • Manual installation
  • Direct download

Add this module to your Puppetfile:

mod 'phihos-hiera_graphql', '0.1.0'
Learn more about managing modules with a Puppetfile

Add this module to your Bolt project:

bolt module add phihos-hiera_graphql
Learn more about using this module with an existing project

Manually install this module globally with Puppet module tool:

puppet module install phihos-hiera_graphql --version 0.1.0

Direct download is not typically how you would use a Puppet module to manage your infrastructure, but you may want to download the module in order to inspect the code.

Download

Documentation

phihos/hiera_graphql — version 0.1.0 Nov 8th 2022

hiera_graphql

A GraphQL backend for Hiera 5.

Table of Contents

  1. Description
  2. Setup - The basics of getting started with hiera_graphql
  3. Usage - Configuration options and additional functionality
  4. Limitations - OS compatibility, etc.
  5. Development - Guide for contributing to the module

Description

Enables Hiera 5 to query GraphQL backends for data. Its primary use-case is retrieving information from NetBox but the general nature of this module should be able to retrieve data from any GraphQL backend.

Setup

What hiera_graphql affects

This hiera backend hooks into your hiera lookups. Since you have to statically set confige_key for a query it is very unlikely that a GraphQL query is being done by accident.

Setup Requirements

This module requires the graphql module which in turn requires the graphql-client gem to be installed on the puppetserver.

You can install it manually by running:

puppetserver gem install graphql-client

You can also automate this by applying the included class graphql::puppetserver:

class { 'graphql::puppetserver':
  gem_ensure           => 'present',
  puppetserver_service => 'puppetserver',
}

The parameters above are the defaults.

Usage

The hiera_graphql backend in meant to be used alongside the default YAML backend to retrieve options for the graphql::graphql_query function. This is a basic example:

# hiera.yaml
---
version: 5
defaults:
  datadir: data
  data_hash: yaml_data
hierarchy:
  - name: "Netbox lookup"
    lookup_key: hiera_graphql
    options:
      confine_to_key: netbox # will only do something when this exact key is looked up
      graphql_query_opts_lookup_key: '__hiera_graphql_netbox' # a hiera key containin query options
  - name: "Common"
    glob: "common.yaml"
# data/common.yaml
__hiera_graphql_netbox:
   url: 'https://netbox.tls/graphql/'
   headers:
      # for auth try to fetch the credentials via backends lieke hiera_vault or hiera_eyaml
      Authorization: "Token %{lookup('vault_netbox.token')}"  
    # not that facts and variables can be interpolated into the query
   query: |
      {
        device_list(name: "%{::hostname}") {
          config_context
        }
        interface_list(device: "%{::hostname}") {
          name
          lag {
            name
          }
          ip_addresses {
            address
          }
        }
      }

# this key actually fetches the data
__netbox_graphql_data: "%{alias('netbox.data')}"

# this key just provides a shortcut to the fetched data
__netbox_graphql_config_context: "%{alias('__netbox_graphql_data.device_list.0.config_context')}"

# we can now parametrize a class like this
profile::dns::nameservers: "%{alias('__netbox_graphql_config_context.nameservers')}"

Limitations

This hiera backend currently does not use caching. PRs welcome.

Development

Pull requests welcome.

THis module is developed via PDK so the usual commands apply:

pdk bundle install
pdk validate
pdk test unit