Showing with 369 additions and 51 deletions.
  1. +1 −1 .msync.yml
  2. +1 −0 .rspec_parallel
  3. +10 −0 CHANGELOG.md
  4. +1 −0 Gemfile
  5. +45 −0 README.md
  6. +83 −45 manifests/init.pp
  7. +6 −4 manifests/params.pp
  8. +1 −1 metadata.json
  9. +13 −0 spec/acceptance/nodesets/archlinux-2-x64.yml
  10. +121 −0 spec/classes/hiera_spec.rb
  11. +64 −0 templates/hiera.yaml.epp
  12. +8 −0 types/hiera5_defaults.pp
  13. +15 −0 types/hiera5_hierarchy.pp
2 changes: 1 addition & 1 deletion .msync.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
modulesync_config_version: '0.21.1'
modulesync_config_version: '0.21.3'
1 change: 1 addition & 0 deletions .rspec_parallel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--format progress
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
Each new release typically also includes the latest Vox Pupuli modulesync defaults.
These should not impact the functionality of the module.

## 2017-08-29 - Release 3.1.0

Introduce support for Hiera 5
* [GH-194](https://github.com/voxpupuli/puppet-hiera/pull/197)
Add support for Hiera 5 hiera.yaml
* [GH-197](https://github.com/voxpupuli/puppet-hiera/pull/197)
Fix bug in error code reporting type validation for hierarchy param
* [GH-200](https://github.com/voxpupuli/puppet-hiera/pull/200)
Relax overly restrictive validation for hierarchy param

## 2017-05-10 - Release 3.0.0

puppet/hiera no longer supports Puppet 3
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ group :test do
gem 'github_changelog_generator', '~> 1.13.0', :require => false if RUBY_VERSION < '2.2.2'
gem 'rack', '~> 1.0', :require => false if RUBY_VERSION < '2.2.2'
gem 'github_changelog_generator', :require => false if RUBY_VERSION >= '2.2.2'
gem 'parallel_tests', :require => false
end

group :development do
Expand Down
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ class { 'hiera':
],
}
```
### For Hiera version 5
```puppet
class { 'hiera':
hiera_version => '5',
hiera5_defaults => {"datadir" => "data", "data_hash" => "yaml_data"},
hierarchy => [
{"name" => "Virtual yaml", "path" => "virtual/%{::virtual}.yaml"},
{"name" => "Nodes yaml", "paths" => ['nodes/%{::trusted.certname}.yaml', 'nodes/%{::osfamily}.yaml']},
{"name" => "Default yaml file", "path" => "common.yaml"},
],
}
```
** Note: For Hiera version 5 when calling the class, please remember to pass '5' to 'hiera_version' as in the example above. **
** Also please note that 'hierarchy' is an array of hash in version 5. **

The resulting output in /etc/puppet/hiera.yaml:

Expand All @@ -78,6 +92,27 @@ The resulting output in /etc/puppet/hiera.yaml:
:yaml:
:datadir: /etc/puppet/hieradata
```
### Resulting output for Hiera 5
```yaml
# hiera.yaml Managed by Puppet
version: 5
defaults:
datadir: data
data_hash: yaml_data
hierarchy:

- name: "Virtual yaml"
path: "virtual/%{::virtual}.yaml"

- name: "Nodes yaml"
paths:
- "nodes/%{::trusted.certname}.yaml"
- "nodes/%{::osfamily}.yaml"

- name: "Default yaml file"
path: "common.yaml"
```
## Usage
Expand All @@ -100,6 +135,7 @@ class { 'hiera':
merge_behavior => 'deeper'
}
```
## For Hiera version 5 please see the example above in beginning with Hiera.

The resulting output in /etc/puppet/hiera.yaml:

Expand Down Expand Up @@ -241,6 +277,15 @@ The following parameters are available for the hiera class:
* `hierarchy`
The hiera hierarchy.
Default: `[]`
For Hiera verison 5.
Default: `[{}]`
* `hiera5_defaults`
To set hiera 5 defaults. e.g. datadir, data_hash
Default: `{}`
* `hiera_version`
Version format to layout hiera.yaml.
Should be a string.
Default: `3`
* `backends`
The list of backends.
Default: `['yaml']`
Expand Down
128 changes: 83 additions & 45 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# Installs either /etc/puppet/hiera.yaml or /etc/puppetlabs/puppet/hiera.yaml.
# Links /etc/hiera.yaml to the above file.
# Creates $datadir (if $datadir_manage == true).
# Creates hiera.yaml in hiera version 5 format if hiera_version = 5 is passed to the class
#
# === Requires:
#
Expand All @@ -25,6 +26,20 @@
# ],
# }
#
# === Sample Usage for Hiera 5:
#
# class { 'hiera':
# hiera_version => '5',
# hiera5_defaults => {"datadir" => "data", "data_hash" => "yaml_data"},
# hierarchy => [
# {"name" => "Virtual yaml", "path" => "virtual/%{::virtual}.yaml"},
# {"name" => "Nodes yaml", "paths" => ['nodes/%{::trusted.certname}.yaml', 'nodes/%{::osfamily}.yaml']},
# {"name" => "Global yaml file", "path" => "common.yaml"},
# ],
# }
#
# Note: Please note that hiera 5 hierarchy should be an array of hash
#
# === Authors:
#
# Hunter Haugen <h.haugen@gmail.com>
Expand All @@ -40,54 +55,55 @@
# Copyright (C) 2016 Vox Pupuli, unless otherwise noted.
#
class hiera (
$hierarchy = $::hiera::params::hierarchy,
$backends = ['yaml'],
$backend_options = {},
$hiera_yaml = $::hiera::params::hiera_yaml,
$create_symlink = true,
$datadir = $::hiera::params::datadir,
$datadir_manage = true,
$owner = $::hiera::params::owner,
$group = $::hiera::params::group,
$provider = $::hiera::params::provider,
$eyaml = false,
$eyaml_name = 'hiera-eyaml',
$eyaml_version = undef,
$eyaml_source = undef,
$eyaml_datadir = undef,
$eyaml_extension = undef,
$confdir = $::hiera::params::confdir,
$puppet_conf_manage = true,
$logger = 'console',
$cmdpath = $::hiera::params::cmdpath,
$create_keys = true,
$keysdir = undef,
$deep_merge_name = 'deep_merge',
$deep_merge_version = undef,
$deep_merge_source = undef,
$deep_merge_options = {},
$merge_behavior = undef,
$extra_config = '',
$master_service = $::hiera::params::master_service,
$manage_package = $::hiera::params::manage_package,
$package_name = $::hiera::params::package_name,
$package_ensure = $::hiera::params::package_ensure,
$eyaml_gpg_name = 'hiera-eyaml-gpg',
$eyaml_gpg_version = undef,
$eyaml_gpg_source = undef,
$eyaml_gpg = false,
$eyaml_gpg_recipients = undef,
$eyaml_pkcs7_private_key = undef,
$eyaml_pkcs7_public_key = undef,

$ruby_gpg_name = 'ruby_gpg',
$ruby_gpg_version = undef,
$ruby_gpg_source = undef,
Variant[Array, Array[Hash]] $hierarchy = $::hiera::params::hierarchy,
Optional[Enum['3','5']] $hiera_version = $::hiera::params::hiera_version,
Hiera::Hiera5_defaults $hiera5_defaults = $::hiera::params::hiera5_defaults,
$backends = ['yaml'],
$backend_options = {},
$hiera_yaml = $::hiera::params::hiera_yaml,
$create_symlink = true,
$datadir = $::hiera::params::datadir,
$datadir_manage = true,
$owner = $::hiera::params::owner,
$group = $::hiera::params::group,
$provider = $::hiera::params::provider,
$eyaml = false,
$eyaml_name = 'hiera-eyaml',
$eyaml_version = undef,
$eyaml_source = undef,
$eyaml_datadir = undef,
$eyaml_extension = undef,
$confdir = $::hiera::params::confdir,
$puppet_conf_manage = true,
$logger = 'console',
$cmdpath = $::hiera::params::cmdpath,
$create_keys = true,
$keysdir = undef,
$deep_merge_name = 'deep_merge',
$deep_merge_version = undef,
$deep_merge_source = undef,
$deep_merge_options = {},
$merge_behavior = undef,
$extra_config = '',
$master_service = $::hiera::params::master_service,
$manage_package = $::hiera::params::manage_package,
$package_name = $::hiera::params::package_name,
$package_ensure = $::hiera::params::package_ensure,
$eyaml_gpg_name = 'hiera-eyaml-gpg',
$eyaml_gpg_version = undef,
$eyaml_gpg_source = undef,
$eyaml_gpg = false,
$eyaml_gpg_recipients = undef,
$eyaml_pkcs7_private_key = undef,
$eyaml_pkcs7_public_key = undef,
$ruby_gpg_name = 'ruby_gpg',
$ruby_gpg_version = undef,
$ruby_gpg_source = undef,

Optional[Array] $gem_install_options = undef,

#Deprecated
$gem_source = undef,
$gem_source = undef,
) inherits ::hiera::params {

if $keysdir {
Expand Down Expand Up @@ -216,9 +232,31 @@
# - $merge_behavior
# - $deep_merge_options
# - $extra_config

# Hiera 5 additional parameters:
# - hiera_version (String)
# - hiera5_defaults (Hash)
# - hierarchy (Array[Hash])

# Determine hiera version
case $hiera_version {
'5': { if ($hierarchy !~ Hiera::Hiera5_hierarchy) {
fail('${hierarchy} should be an array of hash')
}
else
{ $hiera_template = epp('hiera/hiera.yaml.epp',
{
'hiera_version' => $hiera_version,
'hiera5_defaults' => $hiera5_defaults,
'hierarchy' => $hierarchy
})
}
} # Apply epp if hiera version is 5
default: { $hiera_template = template('hiera/hiera.yaml.erb') } # Apply erb for default version 3
}
file { $hiera_yaml:
ensure => present,
content => template('hiera/hiera.yaml.erb'),
content => $hiera_template,
}
# Symlink for hiera command line tool
if $create_symlink {
Expand Down
10 changes: 6 additions & 4 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
# Copyright (C) 2013 Mike Arnold, unless otherwise noted.
#
class hiera::params {
$confdir = $::settings::confdir
$package_ensure = 'present'
$package_name = 'hiera'
$hierarchy = []
$confdir = $::settings::confdir
$hiera_version = '3'
$hiera5_defaults = {'datadir' => 'data', 'data_hash' => 'yaml_data'}
$package_ensure = 'present'
$package_name = 'hiera'
$hierarchy = []
if str2bool($::is_pe) {
$hiera_yaml = '/etc/puppetlabs/puppet/hiera.yaml'
$datadir = '/etc/puppetlabs/puppet/hieradata'
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "puppet-hiera",
"version": "3.0.0",
"version": "3.1.0",
"author": "Vox Pupuli",
"summary": "Deploy hiera.yaml with hierarchy, and datadir",
"license": "Apache-2.0",
Expand Down
13 changes: 13 additions & 0 deletions spec/acceptance/nodesets/archlinux-2-x64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
# This file is managed via modulesync
# https://github.com/voxpupuli/modulesync
# https://github.com/voxpupuli/modulesync_config
HOSTS:
archlinux-2-x64:
roles:
- master
platform: archlinux-2-x64
box: archlinux/archlinux
hypervisor: vagrant
CONFIG:
type: foss
Loading