Showing with 367 additions and 46 deletions.
  1. +1 −1 .msync.yml
  2. +1 −0 .rubocop.yml
  3. +3 −3 .travis.yml
  4. +11 −0 CHANGELOG.md
  5. +1 −1 Gemfile
  6. +33 −0 README.md
  7. +0 −1 manifests/eyaml_gpg.pp
  8. +48 −5 manifests/init.pp
  9. +1 −1 metadata.json
  10. +259 −8 spec/classes/hiera_spec.rb
  11. +9 −26 templates/hiera.yaml.erb
2 changes: 1 addition & 1 deletion .msync.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
modulesync_config_version: '0.12.4'
modulesync_config_version: '0.12.8'
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ AllCops:
Include:
- ./**/*.rb
Exclude:
- files/**/*
- vendor/**/*
- .vendor/**/*
- pkg/**/*
Expand Down
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ matrix:
env: PUPPET_VERSION="~> 3.0" STRICT_VARIABLES="yes" CHECK=test
- rvm: 1.9.3
env: PUPPET_VERSION="~> 3.0" STRICT_VARIABLES="yes" FUTURE_PARSER="yes" CHECK=test
- rvm: 2.1
- rvm: 2.1.9
env: PUPPET_VERSION="~> 3.0" STRICT_VARIABLES="yes" CHECK=test
- rvm: 2.1
- rvm: 2.1.9
env: PUPPET_VERSION="~> 4.0" CHECK=test
- rvm: 2.2
- rvm: 2.2.5
env: PUPPET_VERSION="~> 4.0" CHECK=test
- rvm: 2.3.1
env: PUPPET_VERSION="~> 4.0" CHECK=build DEPLOY_TO_FORGE=yes
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Change log
All notable changes to this project will be documented in this file.

## 2016-10-07 Release 2.2.0
* Modulesync with latest Vox Pupuli defaults
* Removes unused eyaml_gpg_keygen variable
### Features:
* Adds support for 3rd party backends #153

This module now supports configuration of any backend via a new `backend_options`
parameter. This is a big deal as this opens the doors up to configuring any backend in a generic way.
This is also backwards compatible with prior versions of this module.

## 2016-08-31 Release 2.1.2

* Modulesync with latest Vox Pupuli defaults
Expand Down Expand Up @@ -171,6 +181,7 @@ Note: this is the first release of the module in the voxpupuli namespace.
### Bugfixes:
- Only ensure datadir if it does not have `%{.*}`

[2.2.0]: https://github.com/hunner/puppet-hiera/compare/2.1.1...v2.2.0
[2.1.1]: https://github.com/hunner/puppet-hiera/compare/2.1.0...v2.1.1
[2.1.0]: https://github.com/hunner/puppet-hiera/compare/2.0.1...v2.1.0
[2.0.1]: https://github.com/hunner/puppet-hiera/compare/2.0.0...2.0.1
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ group :test do
gem 'metadata-json-lint', :require => false
gem 'puppet-blacksmith', :require => false
gem 'voxpupuli-release', :require => false, :git => 'https://github.com/voxpupuli/voxpupuli-release-gem.git'
gem 'puppet-strings', :require => false, :git => 'https://github.com/puppetlabs/puppetlabs-strings.git'
gem 'puppet-strings', '0.4.0', :require => false
gem 'rubocop-rspec', '~> 1.6', :require => false if RUBY_VERSION >= '2.3.0'
gem 'json_pure', '<= 2.0.1', :require => false if RUBY_VERSION < '2.0.0'
end
Expand Down
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class { 'hiera':
}
```


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

```yaml
Expand Down Expand Up @@ -210,6 +211,38 @@ The following parameters are available for the hiera class:
* `backends`
The list of backends.
Default: `['yaml']`
If you supply a additional backend you must also supply the backend data in
the `backend_options` hash.
* `backend_options`
An optional hash of backend data for **any** backend.
Each key in the hash should be the name of the backend as listed in
the `backends` array. You can also supply additional settings for the backend
by passing in a hash. By default the `yaml` and `eyaml` backend data will be added
if you enable them via their respective parameters. Any options you supply
for `yaml` and `eyaml` backend types will always override other parameters supplied
to the hiera class for that backend.

Example hiera data for the backend_options hash:

```yaml
backend_options:
json:
datadir: '/etc/puppetlabs/puppet/%{::environment}/jsondata'
redis:
password: clearp@ssw0rd # if your Redis server requires authentication
port: 6380 # unless present, defaults to 6379
db: 1 # unless present, defaults to 0
host: db.example.com # unless present, defaults to localhost
path: /tmp/redis.sock # overrides port if unixsocket exists
soft_connection_failure: true # bypass exception if Redis server is unavailable; default is false
separator: / # unless present, defaults to :
deserialize: :json # Try to deserialize; both :yaml and :json are supported
```

**NOTE:** The backend_options must **not** contain symbols as keys ie `:json:` despite the hiera config needing symbols.
The template will perform all the conversions to symbols in order for hiera to be happy. Because puppet does not
use symbols there are minor annoyances when converting back and forth and merge data together.

* `hiera_yaml`
The path to the hiera config file.
**Note**: Due to a bug, hiera.yaml is not placed in the codedir. Your puppet.conf `hiera_config` setting must match the configured value; see also `hiera::puppet_conf_manage`
Expand Down
1 change: 0 additions & 1 deletion manifests/eyaml_gpg.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
$group = $::hiera::group
$cmdpath = $::hiera::cmdpath
$_keysdir = $::hiera::_keysdir
$eyaml_gpg_keygen = $::hiera::eyaml_gpg_keygen

require ::hiera::eyaml

Expand Down
53 changes: 48 additions & 5 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
class hiera (
$hierarchy = $::hiera::params::hierarchy,
$backends = ['yaml'],
$backend_options = {},
$hiera_yaml = $::hiera::params::hiera_yaml,
$create_symlink = true,
$datadir = $::hiera::params::datadir,
Expand Down Expand Up @@ -135,16 +136,33 @@
}

if ( $eyaml_gpg ) or ( $eyaml ) {

$eyaml_real_datadir = empty($eyaml_datadir) ? {
false => $eyaml_datadir,
true => $datadir,
}
# the requested_backends has a side affect in that the eyaml will always be
# last for backend lookups. This can be fixed by specifing the order in
# the backends parameter ie. ['yaml', 'eyaml', 'redis']
$requested_backends = unique(concat($backends, 'eyaml'))
} else {
$requested_backends = $backends
$eyaml_real_datadir = undef
}

# without these variables defined here puppet will puke when strict
# variables is enabled, which are needed for delete_undef_values
if $eyaml_gpg {
$encrypt_method = 'gpg'
$gpg_gnupghome = "${_keysdir}/gpg"
require ::hiera::eyaml_gpg
} elsif $eyaml {
require ::hiera::eyaml
$encrypt_method = undef
$gpg_gnupghome = undef
} else {
$encrypt_method = undef
$gpg_gnupghome = undef
}

if $manage_package {
Expand All @@ -153,16 +171,41 @@
name => $package_name,
}
}
# these are the default eyaml options that were interpolated in
# the above logic. This was neccessary in order to maintain compability
# with prior versions of this module
$eyaml_options = {
'eyaml' => delete_undef_values({
'datadir' => $eyaml_real_datadir,
'extension' => $eyaml_extension,
'pkcs7_private_key' => $_eyaml_pkcs7_private_key,
'pkcs7_public_key' => $_eyaml_pkcs7_public_key,
'encrypt_method' => $encrypt_method,
'gpg_gnupghome' => $gpg_gnupghome,
'gpg_recipients' => $eyaml_gpg_recipients,
}),
}
$yaml_options = { 'yaml' => { 'datadir' => $datadir } }
# all the backend options are merged together into a single hash
# the user can override anything via the backend_options hash parameter
# which will override any data set in the eyaml or yaml parameters above.
# the template will only use the backends that were defined in the backends
# array even if there is info in the backend data hash
$backend_data = deep_merge($yaml_options, $eyaml_options, $backend_options)
# if for some reason the user mispelled the backend in the backend_options lets
# catch that error here and notify the user
$missing_backends = difference($backends, keys($backend_data))
if count($missing_backends) > 0 {
fail("The supplied backends: ${missing_backends} are missing from the backend_options hash:\n ${backend_options}\n
or you might be using symbols in your hiera data")
}

# Template uses:
# - $eyaml
# - $backends
# - $requested_backends
# - $backend_data
# - $logger
# - $hierarchy
# - $datadir
# - $eyaml_real_datadir
# - $eyaml_extension
# - $_keysdir
# - $confdir
# - $merge_behavior
# - $deep_merge_options
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": "2.1.2",
"version": "2.2.0",
"author": "Vox Pupuli",
"summary": "Deploy hiera.yaml with hierarchy, and datadir",
"license": "Apache-2.0",
Expand Down
Loading