Version information
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
Add this module to your Puppetfile:
mod 'phihos-hiera_graphql', '0.1.0'
Learn more about managing modules with a PuppetfileDocumentation
hiera_graphql
A GraphQL backend for Hiera 5.
Table of Contents
- Description
- Setup - The basics of getting started with hiera_graphql
- Usage - Configuration options and additional functionality
- Limitations - OS compatibility, etc.
- 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
Dependencies
- phihos-graphql (0.x.x)
MIT License Copyright (c) 2022 Philipp Hossner Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.