Giter Club home page Giter Club logo

hiera-resources's Introduction

Overview

hiera_resources has 1 job in life; create Puppet resources from a hash returned by Hiera. The hash returned should match the structure of the hash required by Puppet's create_resources function. Examples for using this with YAML and Redis (serialized) backends are included below.

Credit

This version of hiera_resources is basically a complete refactoring based on this excellent blog post by Robin Bowes.

Setup for both YAML and Redis backends

Ensure the following gem versions are installed:

This function should exist in a place where puppet can find it. ~/.puppet/var/lib/puppet/parser/functions is certainly fine for testing purposes.

Create a Hiera configuration in ~/.puppet/hiera.yaml

---
:hierarchy:
  - common
:backends:
  - yaml
  - redis
:yaml:
  :datadir: /tmp/hiera/data
$ mkdir -p /tmp/hiera/data

Create some YAML data in /tmp/hiera/data/common.yaml

---
messages1:
  notify:
    title 1:
      message: this is the first message stored in YAML
    title 2:
      message: this is the second message stored in YAML

Creating Puppet resources from the YAML backend

Apply a manifest

$ puppet apply -e "hiera_resources('messages1')"
notice: This is the second message stored in YAML.
notice: /Stage[main]//Notify[title 2]/message: defined 'message' as 'This is the second message stored in YAML.'
notice: This is the first message stored in YAML.
notice: /Stage[main]//Notify[title 1]/message: defined 'message' as 'This is the first message stored in YAML.'

Creating Puppet resources from the Redis backend

Make sure Redis is running on localhost:6379 (or tweak the call to Redis.new below)

Fire up your favorite ruby REPL and add a few serialized Puppet resources into a Redis key.

require 'redis'
require 'json'

resources = { 'notify' => {
  'title 1' => {
    'message' => 'This is the first message stored in Redis.'
    },
  'title 2' => {
    'message' => 'This is the second message stored in Redis.'
    }
  }
}

r = Redis.new
r.set 'common:messages2', resources.to_json

Configure deserialization in ~/.puppet/hiera.yaml (use :yaml instead of :json if appropriate).

:redis:
  :deserialize: :json

Now apply a manifest

$ puppet apply -e "hiera_resources('messages2')"
notice: This is the second message stored in Redis.
notice: /Stage[main]//Notify[title 2]/message: defined 'message' as 'This is the second message stored in Redis.'
notice: This is the first message stored in Redis.
notice: /Stage[main]//Notify[title 1]/message: defined 'message' as 'This is the first message stored in Redis.'

Additional features

hiera_resources will accept a hash as a 2nd argument. When present, the hash will be used as a default if the key can not be found.

hiera-resources's People

Contributors

rimenes avatar

Stargazers

 avatar mineral4x avatar Frank Wall avatar RT avatar Sascha Spreitzer avatar Luke Heidecke avatar Dave Wongillies avatar Justin Bennett avatar Gianluca Varisco avatar Tim avatar

Watchers

James Cloos avatar

hiera-resources's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.