Version information
This version is compatible with:
- Puppet Enterprise >= 3.0.0 < 2015.4.0
- Puppet >= 3.0.0 < 5.0.0
- , , ,
Start using this module
Add this module to your Puppetfile:
mod 'puppet-hiera', '2.1.0'Learn more about managing modules with a PuppetfileDocumentation
Hiera Puppet
####Table of Contents
- Overview
- Module Description - What the module does and why it is useful
- Setup - The basics of getting started with hiera
- Usage - Configuration options and additional functionality
- Reference - An under-the-hood peek at what the module is doing and how
- Limitations - OS compatibility, etc.
- Development - Guide for contributing to the module
Module Description
This module configures Hiera for Puppet.
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 the eyaml backend on:
- Puppet Enterprise 3.3 or earlier then you will need the puppetlabs-pe_gem module to install the eyaml gem using PE's gem command.
- Puppet Enterprise 3.7 or 3.8 then you will need the puppetlabs-pe_puppetserver_gem module.
- Puppet Enterprise 2015.x or FOSS puppetserver then you will need the puppetlabs-puppetserver_gem module.
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).
class { 'hiera':
hierarchy => [
'%{environment}/%{calling_class}',
'%{environment}',
'common',
],
}
The resulting output in /etc/puppet/hiera.yaml:
---
:backends:
- yaml
:logger: console
:hierarchy:
- "%{environment}/%{calling_class}"
- "%{environment}"
- common
:yaml:
:datadir: /etc/puppet/hieradata
Usage
Reference
This module will also allow you to configure different options for logger and merge_behavior. The default behavior is to set logger to console and merge behavior to native.
For details and valid options see Configuring Hiera.
Note: For merge_behavior if you set deep or deeper you need to ensure the deep_merge Ruby gem is installed.
class { 'hiera':
hierarchy => [
'%{environment}/%{calling_class}',
'%{environment}',
'common',
],
logger => 'console',
merge_behavior => 'deep'
}
The resulting output in /etc/puppet/hiera.yaml:
---
:backends:
- yaml
:logger: console
:hierarchy:
- "%{environment}/%{calling_class}"
- "%{environment}"
- common
:yaml:
:datadir: /etc/puppet/hieradata
:merge_behavior: deep
Hiera-Eyaml-GPG
The default PKCS#7 encryption scheme used by hiera-eyaml is perfect if only simple encryption and decryption is needed.
However, if you are in a sizable team it helps to encrypt and decrypt data with multiple keys. This means that each team member can hold their own private key and so can the puppetmaster. Equally, each puppet master can have their own key if desired and when you need to rotate keys for either users or puppet masters, re-encrypting your files and changing the key everywhere does not need to be done in lockstep.
Requirements
Note: This module will create a /gpg sub-directory in the $keysdir.
-
The GPG keyring must be passphraseless on the on the PuppetServer(Master).
-
The GPG keyring must live in the /gpg sub-directory in the
$keysdir. -
The GPG keyring must be owned by the Puppet user. ex: pe-puppet
GPG Keyring Creation Tips
RNG-TOOLS
When generating a GPG keyring the system requires a good amount of entropy. To help generate entropy to speed up the process then rng-tools package on RHEL based systems or equivilent can be used. Note: Update the /etc/sysconfig/rngd or equivilent file to set the EXTRAOPTIONS to EXTRAOPTIONS="-r /dev/urandom -o /dev/random -t 5"
Keyring Generation
Below is a sample GPG answers file that will assist in generating a passphraseless key
cat << EOF >> /tmp/gpg_answers
%echo Generating a Puppet Hiera GPG Key
Key-Type: RSA
Key-Length: 4096
Subkey-Type: ELG-E
Subkey-Length: 4096
Name-Real: Hiera Data
Name-Comment: Hiera Data Encryption
Name-Email: puppet@$(hostname -d)
Expire-Date: 0
%no-ask-passphrase
# Do a commit here, so that we can later print "done" :-)
# %commit
# %echo done
EOF
You can then use the GPG answer file to generate your keyring within the /gpg sub-directory in the $keysdir
gpg --batch --homedir /etc/puppetlabs/code-staging/keys/gpg --gen-key /tmp/gpg_answers
Usage
class { 'hiera':
hierarchy => [
'nodes/%{::clientcert}',
'locations/%{::location}',
'environments/%{::applicationtier}',
'common',
],
eyaml => true,
eyaml_gpg => true,
eyaml_gpg_recipients => 'sihil@example.com,gtmtech@example.com,tpoulton@example.com',
}
The resulting output in /etc/puppet/hiera.yaml:
---
:backends:
- eyaml
- yaml
:logger: console
:hierarchy:
- "nodes/%{::clientcert}"
- "locations/%{::location}"
- "environments/%{::applicationtier}"
- common
:yaml:
:datadir: /etc/puppet/hieradata
:eyaml:
:datadir: /etc/puppet/hieradata
:pkcs7_private_key: /etc/puppet/keys/private_key.pkcs7.pem
:pkcs7_public_key: /etc/puppet/keys/public_key.pkcs7.pem
:encrypt_method: "gpg"
:gpg_gnupghome: "/etc/puppet/keys/gpg"
:gpg_recipients: "sihil@example.com,gtmtech@example.com,tpoulton@example.com"
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
The hiera hierarchy.
Default:[]backends
The list of backends.
Default:['yaml']hiera_yaml
The path to the hiera config file.
Note: Due to a bug, hiera.yaml is not placed in the codedir. Your puppet.confhiera_configsetting must match the configured value; see alsohiera::puppet_conf_manageDefault:'/etc/puppet/hiera.yaml'for Puppet Open Source'/etc/puppetlabs/puppet/hiera.yaml'for Puppet Enterprise
create_symlinkWhether to create the symlink/etc/hiera.yamlDefault: truedatadir
The path to the directory where hiera will look for databases.
Default:'/etc/puppet/hieradata'for Puppet Open Source'/etc/puppetlabs/puppet/hieradata'for PE Puppet < 4'/etc/puppetlabs/code/environments/%{::environment}/hieradata'for Puppet >= 4
datadir_manage
Whether to create and manage the datadir as a file resource.
Default:trueowner
The owner of managed files and directories.
Default:'puppet'for Puppet Open Source'pe-puppet'for Puppet Enterprise
group
The group owner of managed files and directories.
Default:'puppet'for Puppet Open Source'pe-puppet'for Puppet Enterprise
eyaml
Whether to install, configure, and enable the eyaml backend. Also see the provider and master_service parameters.
Default:falseeyaml_nameThe name of the eyaml gem. Default: 'hiera-eyaml'eyaml_version
The version of hiera-eyaml to install. Accepts 'installed', 'latest', '2.0.7', etc
Default:undefeyaml_sourceAn alternate gem source for installing hiera-eyaml. Default:undef, uses gem backend defaulteyaml_datadir
The path to the directory where hiera will look for databases with the eyaml backend.
Default: same asdatadireyaml_extension
The file extension for the eyaml backend.
Default:undef, backend defaults to'.eyaml'deep_merge_nameThe name of the deep_merge gem. Default: 'deep_merge'deep_merge_versionThe version of deep_merge to install. Accepts 'installed', 'latest', '2.0.7', etc. Default:undefdeep_merge_sourceAn alternate gem source for installing deep_merge. Default:undef, uses gem backend defaultdeep_merge_optionsA hash of options to set in hiera.yaml for the deep merge behavior. Default:{}manage_packageAA boolean for wether the hiera package should be managed. Defaults totrueon FOSS 3 butfalseotherwise.package_nameSpecifies the name of the hiera package. Default: 'hiera'package_ensureSpecifies the ensure value of the hiera package. Default: 'present'confdir
The path to Puppet's confdir. Default:$::settings::confdirwhich should be the following:'/etc/puppet'for Puppet Open Source'/etc/puppetlabs/puppet'for Puppet Enterprise
logger
Which hiera logger to use.
Note: You need to manage any package/gem dependencies yourself.
Default:undef, hiera defaults to'console'cmdpath
Search paths for command binaries, like theeyamlcommand.
The default should cover most cases.
Default:['/opt/puppet/bin', '/usr/bin', '/usr/local/bin']create_keys
Whether to create pkcs7 keys and manage key files for hiera-eyaml.
This is useful if you need to distribute a pkcs7 key pair.
Default:truemerge_behaviorWhich hiera merge behavior to use. Valid values are 'native', 'deep', and 'deeper'. Deep and deeper values will install the deep_merge gem into the puppet runtime. Default:undef, hiera defaults to'native'extra_config
Arbitrary YAML content to append to the end of the hiera.yaml config file.
This is useful for configuring backend-specific parameters.
Default:''keysdirDirectory for hiera to manage for eyaml keys. Default:$confdir/keysNote: If using PE 2013.x+ and code-manager set the keysdir under the$confdir/code-staging directoryto allow the code manager to sync the keys to all PuppetServers Example:/etc/puppetlabs/code-staging/keyspuppet_conf_manageWhether to manage the puppet.confhiera_configvalue or not. Default:trueprovider
Which provider to use to install hiera-eyaml. Can be:puppetserver_gem(PE 2015.x or FOSS using puppetserver)pe_puppetserver_gem(PE 3.7 or 3.8)pe_gem(PE pre-3.7)puppet_gem(agent-only gem)gem(FOSS using system ruby (ie puppetmaster)) Note: this module cannot detect FOSS puppetserver and you must passprovider => 'puppetserver_gem'for that to work. See also master_service. Default: Depends on puppet version detected as specified above.
master_service
The service name of the master to restart after package installation or hiera.yaml changes.
Note: You must passmaster_service => 'puppetserver'for FOSS puppetserver
Default: 'pe-puppetserver' for PE 2015.x, otherwise 'puppetmaster'
Limitations
The pe-puppetserver service must be restarted after hiera-eyaml is installed; this module will not do it for you. The eyaml_version parameter does not currently modify the eyaml version of the command-line gem on pe-puppetserver.
Development
Pull requests on github! If someone wrote spec tests, that would be awesome.
Change log
All notable changes to this project will be documented in this file.
2016-05-21 Release 2.1.0
Note: this is the first release of the module in the voxpupuli namespace.
Features:
- Add parameters to give more control over package management:
eyaml_nameeyaml_versioneyaml_source(deprecatesgem_sourceparameter)deep_merge_namedeep_merge_versiondeep_merge_sourcemanage_packagepackage_namepackage_source
- Add
deep_merge_optionsparameter for passing parameters in hiera.yaml - The
merge_behaviorparameter installs thedeep_mergegem when needed.
Bugfixes:
- Typo for
master_serviceparameter in readme. - Improve dependency management around packages
- Fix
hierarchyparameter default on Puppet 4
2016-01-27 Release 2.0.1
Fixes:
- Fix key creation when passing a custom
hiera::keysdir
2016-01-26 Release 2.0.0
Changes:
- eyaml keys/ directory moved from
/etc/puppetlabs/code/keysto/etc/puppetlabs/puppet/keyson PE > 3.x. You should move you keys directory when upgrading. hiera::hiera_yamldefault changed from/etc/puppetlabs/code/hiera.yamlto/etc/puppetlabs/puppet/hiera.yamlon Puppet >= 4.x. The hiera_yaml puppet config setting in puppet.conf should be updated when upgrading; seehiera::puppet_conf_managehiera::datadirdefault changed from/etc/puppetlabs/puppet/hieradatato/etc/puppetlabs/code/environments/%{::environment}/hieradataon puppet versions >= 4. Verify that this is your prefered value when upgrading.
Features:
- No longer using exec resources to install eyaml on puppet versions >= 4!
- Add
hiera::puppet_conf_manageparameter to managehiera_confpuppet.conf setting - Add
hiera::keysdirparameter for putting the keys somewhere other than $confdir/keys
Bugfixes:
- Fix hiera.yaml and keys/ directory being overwritten by file sync on PE 2015.x
- Fix eyaml package provider detection on puppet versions >= 4
2016-01-08 Release 1.4.1
Bugfixes:
- Fix rubocop linting
- Correct the name of the license file so the forge can find it.
- Add travis testing
2016-01-05 Release 1.4.0
Features:
- Added
hiera::create_symlinkparameter to disable /etc/hiera.yaml creation - Added
hiera::master_serviceparameter to set the master service name - Added ability to restart master service on hiera.yaml change
- Added beaker-rspec acceptance tests
- Bumped PE range to include 2015.3
Bugfixes:
- Fixed bugs on PE 2015.2 when versioncmp() raised errors
- Fixed hiera.yaml output to be consistent across puppet 3 and 4
- Fixed stdlib metadata requirement.
2015-09-14 Release 1.3.2
Bugfixes:
- Detect correct user on 2015.2.0
- Clean up hiera formatting.
2015-07-24 Release 1.3.1
Bugfixes:
- Allow
eyaml_versionto be undef (the default) on PE 3.7/3.8
2015-07-23 Release 1.3.0
Features:
- Add PE 3.8 support
- Add Puppet 4 support
Bugfixes:
- Fix
eyaml_datadirparameter default todatadirvalue - Handle cmdpath on different versions of puppet
2015-03-05 Release 1.2.0
Features:
- Added
hiera::create_keysparam to disable pkcs7 key generation with hiera-eyaml - Added
hiera::gem_sourceparam to specify source of hiera-eyaml gem - Added
hiera::eyaml_versionparam to specify the version of eyaml
Bugfixes:
- Change Modulefile to metadata.json
- Add validation on
merge_behaviorparam - Make it kind of work on PE 3.7 (pe-puppetserver must still be restarted after the gem is installed)
2014-11-21 Release 1.1.1
Bugfixes:
- Correct handling of
cmdpath(using an array of paths instead of hardcoded path). Also addscmdpathparameter - Fix permissions on private key (604 was a typo)
- Add "Managed by puppet" header
2014-10-15 Release 1.1.0
Features:
- Added
eyaml,eyaml_datadir, &eyaml_extensionparameters to hiera class for configuring hiera-eyaml - Added
hiera::datadir_manageparameter to disable datadir management - Added
hiera::loggerparameter to change logger - Added
hiera::merge_behaviorparameter 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
2014-03-25 Release 1.0.1
Bugfixes:
- Readme tweak
- Use template instance variables to remove warnings
2014-02-27 Release 1.0.0
Features:
backendsparameter for an array of hiera backendsextra_configparameter for a string of extra yaml config
Bugfixes:
- Correct the yaml formatting
2013-06-17 Release 0.3.1
Bugfixes:
- Docs!
2013-06-17 Release 0.3.0
Features:
- PE + POSS support
Bugfixes:
- Only ensure datadir if it does not have
%{.*}
Dependencies
- puppetlabs-stdlib (>= 4.3.1 < 5.0.0)
- puppetlabs-inifile (>= 1.0.0 < 2.0.0)
Copyright (c) 2015, Hunter Haugen All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.