Showing with 321 additions and 17 deletions.
  1. +3 −0 .fixtures.yml
  2. +12 −0 CHANGELOG
  3. +20 −0 Gemfile
  4. +1 −1 Modulefile
  5. +118 −2 README.md
  6. +10 −0 Rakefile
  7. +53 −0 manifests/eyaml.pp
  8. +60 −11 manifests/init.pp
  9. +10 −2 manifests/params.pp
  10. +14 −0 spec/classes/hiera_spec.rb
  11. +1 −0 spec/spec_helper.rb
  12. +19 −1 templates/hiera.yaml.erb
3 changes: 3 additions & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fixtures:
symlinks:
"hiera": "#{source_dir}"
12 changes: 12 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
2014-10-15 Release 1.1.0
Features:
- Added eyaml, eyaml_datadir, & eyaml_extension parameters to hiera class for configuring hiera-eyaml
- Added hiera::datadir_manage parameter to disable datadir management
- Added hiera::logger parameter to change logger
- Added hiera::merge_behavior parameter to change the hash merge behavior
- Added some spec tests
- Added new readme

Bugfixes:
- Correct datadir regex {} matching

2014-05-01 Release 1.0.2
- Remove swap files from package

Expand Down
20 changes: 20 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
source ENV['GEM_SOURCE'] || "https://rubygems.org"

group :development, :test do
gem 'puppetlabs_spec_helper', :require => false
gem 'pry', :require => false
end

if facterversion = ENV['FACTER_GEM_VERSION']
gem 'facter', facterversion, :require => false
else
gem 'facter', :require => false
end

if puppetversion = ENV['PUPPET_GEM_VERSION']
gem 'puppet', puppetversion, :require => false
else
gem 'puppet', :require => false
end

# vim:ft=ruby
2 changes: 1 addition & 1 deletion Modulefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name 'hunner-hiera'
version '1.0.2'
version '1.1.0'
source 'UNKNOWN'
author 'hunner'
license 'BSD'
Expand Down
120 changes: 118 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,39 @@
# Hiera Puppet

## Description
####Table of Contents

1. [Overview](#overview)
2. [Module Description - What the module does and why it is useful](#module-description)
3. [Setup - The basics of getting started with hiera](#setup)
* [What hiera affects](#what-hiera-affects)
* [Setup requirements](#setup-requirements)
* [Beginning with hiera](#beginning-with-hiera)
4. [Usage - Configuration options and additional functionality](#usage)
5. [Reference - An under-the-hood peek at what the module is doing and how](#reference)
5. [Limitations - OS compatibility, etc.](#limitations)
6. [Development - Guide for contributing to the module](#development)

## Module Description
This module configures [Hiera](https://github.com/puppetlabs/hiera) for Puppet.

## Usage
## Setup

### What hiera affects
- Hiera yaml file
- Hiera datadir
- hiera-eyaml package
- keys/ directory for eyaml
- /etc/hiera.yaml for symlink

### Setup requirements
If you are using Puppet Enterprise and the eyaml backend, you will need the [puppetlabs-pe_gem](https://forge.puppetlabs.com/puppetlabs/pe_gem) module to install the eyaml gem using PE's gem command.

Otherwise you just need puppet.

### Beginning with hiera

Declaring the class with a given hierarchy is a pretty good starting point:

This class will write out a hiera.yaml file in either /etc/puppetlabs/puppet/hiera.yaml or /etc/puppet/hiera.yaml (depending on if the node is running Puppet Enterprise or not).

```puppet
Expand Down Expand Up @@ -31,3 +61,89 @@ The resulting output in /etc/puppet/hiera.yaml:
:datadir: /etc/puppet/hieradata
```
## Usage
## Reference
This module will also allow you to configure different options for logger and merge_behaviour. The default behaviour is to set logger to console and merge behaviour to native.
For details and valid options [Configuring Hiera][https://docs.puppetlabs.com/hiera/1/configuring.html#global-settings].
Note: For `merge_behavior` if you set deep or deeper you need to ensure the deep_merge Ruby gem is installed.

```puppet
class { 'hiera':
hierarchy => [
'%{environment}/%{calling_class}',
'%{environment}',
'common',
],
logger => 'console',
merge_behavior => 'deep'
}
```

The resulting output in /etc/puppet/hiera.yaml:
```yaml
---
:backends:
- yaml
:logger: console
:hierarchy:
- "%{environment}/%{calling_class}"
- "%{environment}"
- common
:yaml:
:datadir: /etc/puppet/hieradata
:merge_behavior: deep
```

### Classes

#### Public Classes
- hiera: Main class to configure hiera

#### Private Classes
- hiera::params: Handles variable conditionals
- hiera::eyaml: Handles eyaml configuration

### Parameters

The following parameters are available for the hiera class:

#### `hierarchy`
Configures the hiera hierarchy. Default is []
#### `backends`
Configures the list of backends. Default is ['yaml']
#### `hiera_yaml`
Configures the path to hiera.yaml
#### `datadir`
Configures the path to the hieradata directory.
#### `datadir_manage`
Enables/disables the datadir file resource
#### `owner`
Sets the owner of the managed files and directories.
#### `group`
Sets the group of the managed files and directories.
#### `eyaml`
Enables/disables the eyaml backend. Default true
#### `eyaml_datadir`
Configures the eyaml data directory. Default is the same as datadir
#### `eyaml_extension`
Configures the eyaml file extension. No default
#### `confdir`
Configures the directory for puppet's confdir.
#### `logger`
Configures the hiera logger. Default is 'console'
#### `merge_behavior`
Configures the hiera merge behavior (e.g. for deep merges). No default
#### `extra_config`
Accepts arbitrary content to add to the end of hiera.yaml

## Limitations

Unknown.

## Development

Pull requests on github! If someone wrote spec tests, that would be awesome.
10 changes: 10 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet-lint/tasks/puppet-lint'

PuppetLint.configuration.fail_on_warnings
PuppetLint.configuration.send('disable_80chars')
PuppetLint.configuration.send('disable_class_inherits_from_params_class')
PuppetLint.configuration.send('disable_class_parameter_defaults')
PuppetLint.configuration.send('disable_documentation')
PuppetLint.configuration.send('disable_single_quote_string_with_variables')
PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"]
53 changes: 53 additions & 0 deletions manifests/eyaml.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# == Class: hiera::eyaml
#
# This class installs and configures hiera-eyaml
#
# === Authors:
#
# Terri Haber <terri@puppetlabs.com>
#
# === Copyright:
#
# Copyright (C) 2014 Terri Haber, unless otherwise noted.
#
class hiera::eyaml (
$provider = $hiera::params::provider,
$owner = $hiera::params::owner,
$group = $hiera::params::group,
$cmdpath = $hiera::params::cmdpath,
$confdir = $hiera::params::confdir
) inherits hiera::params {

package { 'hiera-eyaml':
ensure => installed,
provider => $provider,
}

file { "${confdir}/keys":
ensure => directory,
owner => $owner,
group => $group,
before => Exec['createkeys'],
}

exec { 'createkeys':
user => $owner,
cwd => $confdir,
command => "${cmdpath}/eyaml createkeys",
path => $cmdpath,
creates => "${confdir}/keys/private_key.pkcs7.pem",
require => Package['hiera-eyaml'],
}

$eyaml_files = [
"${confdir}/keys/private_key.pkcs7.pem",
"${confdir}/keys/public_key.pkcs7.pem"]

file { $eyaml_files:
ensure => file,
mode => '0604',
owner => $owner,
group => $group,
require => Exec['createkeys'],
}
}
71 changes: 60 additions & 11 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
# Directory in which hiera will start looking for databases.
# Default: auto-set, platform specific
#
# [*datadir_manage*]
# Enables creating $datadir directory
# Default: true
#
# [*owner*]
# Owner of the files.
# Default: auto-set, platform specific
Expand All @@ -33,11 +37,33 @@
# Useful for configuring backend-specific parameters.
# Default: ''
#
# [*eyaml*]
# Install and configure hiera-eyaml
# Default: false
#
# [*eyaml_datadir*]
# Location of eyaml-specific data
# Default: Same as datadir
#
# [*eyaml_extension*]
# File extension for eyaml backend
# Default: undef, use backend default
#
# [*logger*]
# Configure a valid hiera logger
# Note: You need to manage any package/gem dependancies
# Default: console
#
# [*merge_behavior*]
# Configure hiera merge behavior.
# Note: You need to manage any package/gem dependancies
# Default: native
#
# === Actions:
#
# Installs either /etc/puppet/hiera.yaml or /etc/puppetlabs/puppet/hiera.yaml.
# Links /etc/hiera.yaml to the above file.
# Creates $datadir.
# Creates $datadir (if $datadir_manage == true).
#
# === Requires:
#
Expand All @@ -56,32 +82,55 @@
#
# Hunter Haugen <h.haugen@gmail.com>
# Mike Arnold <mike@razorsedge.org>
# Terri Haber <terri@puppetlabs.com>
# Greg Kitson <greg.kitson@puppetlabs.com>
#
# === Copyright:
#
# Copyright (C) 2012 Hunter Haugen, unless otherwise noted.
# Copyright (C) 2013 Mike Arnold, unless otherwise noted.
# Copyright (C) 2014 Terri Haber, unless otherwise noted.
#
class hiera (
$hierarchy = [],
$backends = $hiera::params::backends,
$hiera_yaml = $hiera::params::hiera_yaml,
$datadir = $hiera::params::datadir,
$owner = $hiera::params::owner,
$group = $hiera::params::group,
$extra_config = '',
$hierarchy = [],
$backends = $hiera::params::backends,
$hiera_yaml = $hiera::params::hiera_yaml,
$datadir = $hiera::params::datadir,
$datadir_manage = $hiera::params::datadir_manage,
$owner = $hiera::params::owner,
$group = $hiera::params::group,
$eyaml = false,
$eyaml_datadir = $hiera::params::datadir,
$eyaml_extension = $hiera::params::eyaml_extension,
$confdir = $hiera::params::confdir,
$logger = $hiera::params::logger,
$merge_behavior = undef,
$extra_config = '',
) inherits hiera::params {
File {
owner => $owner,
group => $group,
mode => '0644',
}
if $datadir !~ /%{.*}/ {
if ($datadir !~ /%\{.*\}/) and ($datadir_manage == true) {
file { $datadir:
ensure => directory,
}
}
# Template uses $hierarchy, $datadir
if $eyaml {
require hiera::eyaml
}
# Template uses:
# - $eyaml
# - $backends
# - $logger
# - $hierarchy
# - $datadir
# - $eyaml_datadir
# - $eyaml_extension
# - $confdir
# - $merge_behavior
# - $extra_config
file { $hiera_yaml:
ensure => present,
content => template('hiera/hiera.yaml.erb'),
Expand All @@ -90,5 +139,5 @@
file { '/etc/hiera.yaml':
ensure => symlink,
target => $hiera_yaml,
}
}
}
12 changes: 10 additions & 2 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@
$datadir = '/etc/puppetlabs/puppet/hieradata'
$owner = 'pe-puppet'
$group = 'pe-puppet'
$provider = 'pe_gem'
$cmdpath = '/opt/puppet/bin'
$confdir = '/etc/puppetlabs/puppet'
} else {
$hiera_yaml = '/etc/puppet/hiera.yaml'
$datadir = '/etc/puppet/hieradata'
$owner = 'puppet'
$group = 'puppet'
$provider = 'gem'
$cmdpath = '/usr/bin/puppet'
$confdir = '/etc/puppet'
}

$backends = ['yaml']
$datadir_manage = true
$backends = ['yaml']
$logger = 'console'
$eyaml_extension = undef
}
Loading