14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
# Change log
All notable changes to this project will be documented in this file.

## [1.4.0] - 2016-01-05
### Features:
- Added `hiera::create_symlink` parameter to disable /etc/hiera.yaml creation
- Added `hiera::master_service` parameter 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.

## [1.3.2] - 2015-09-14
### Bugfixes:
- Detect correct user on 2015.2.0
Expand Down Expand Up @@ -79,6 +92,7 @@ All notable changes to this project will be documented in this file.
### Bugfixes:
- Only ensure datadir if it does not have `%{.*}`

[1.4.0]: https://github.com/hunner/puppet-hiera/compare/1.3.2...1.4.0
[1.3.2]: https://github.com/hunner/puppet-hiera/compare/1.3.1...1.3.2
[1.3.1]: https://github.com/hunner/puppet-hiera/compare/1.3.0...1.3.1
[1.3.0]: https://github.com/hunner/puppet-hiera/compare/1.2.0...1.3.0
Expand Down
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ group :development, :test do
gem 'pry', :require => false
end

group :system_tests do
gem 'beaker-rspec', :require => false
gem 'beaker-puppet_install_helper', :require => false
end

if facterversion = ENV['FACTER_GEM_VERSION']
gem 'facter', facterversion, :require => false
else
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ The following parameters are available for the hiera class:
Default:
* `'/etc/puppet/hiera.yaml'` for Puppet Open Source
* `'/etc/puppetlabs/puppet/hiera.yaml'` for Puppet Enterprise
* `create_symlink`
Whether to create the symlink `/etc/hiera.yaml`
Default: true
* `datadir`
The path to the directory where hiera will look for databases.
Default:
Expand Down
55 changes: 44 additions & 11 deletions manifests/eyaml.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# Copyright (C) 2014 Terri Haber, unless otherwise noted.
#
class hiera::eyaml (
$provider = $hiera::params::provider,
$provider = $hiera::provider,
$owner = $hiera::owner,
$group = $hiera::group,
$cmdpath = $hiera::cmdpath,
Expand All @@ -25,12 +25,31 @@
undef => 'installed',
default => $eyaml_version,
}
package { 'hiera-eyaml':
ensure => $package_ensure,
provider => $provider,
source => $gem_source,
}
if $provider == 'pe_puppetserver_gem' {
Exec {
path => [
'/opt/puppetlabs/server/bin',
'/opt/puppetlabs/puppet/bin',
'/opt/puppet/bin',
'/usr/bin',
'/bin',
],
}

$hiera_package_depedencies = [
Exec['install ruby gem hiera-eyaml'],
Exec['install puppetserver gem hiera-eyaml'],
]

if $::pe_server_version {
# PE 2015
$vendored_gem_creates = '/opt/puppetlabs/puppet/bin/eyaml'
$puppetserver_gem_creates = '/opt/puppetlabs/server/data/puppetserver/jruby-gems/bin/eyaml'
} else {
$vendored_gem_creates = '/opt/puppet/bin/eyaml'
$puppetserver_gem_creates = '/var/opt/lib/pe-puppet-server/jruby-gems/bin/eyaml'
}

# The puppetserver gem wouldn't install the commandline util, so we do
# that here
#XXX Pre-puppet 4.0.0 version (PUP-1073)
Expand All @@ -40,17 +59,31 @@
} else {
$gem_flag = undef
}
exec { 'install pe_gem':
command => "/opt/puppet/bin/gem install hiera-eyaml ${gem_flag}",
creates => '/opt/puppet/bin/eyaml',
}
#XXX Post-puppet 4.0.0
#package { 'hiera-eyaml command line':
# ensure => installed,
# name => 'hiera-eyaml',
# provider => 'pe_gem',
# source => $gem_source,
#}

exec { 'install ruby gem hiera-eyaml':
command => "gem install hiera-eyaml ${gem_flag}",
creates => $vendored_gem_creates,
}

exec { 'install puppetserver gem hiera-eyaml':
command => "puppetserver gem install hiera-eyaml ${gem_flag}",
creates => $puppetserver_gem_creates,
notify => Service[$hiera::master_service],
}
} else {
$hiera_package_depedencies = Package['hiera-eyaml']
package { 'hiera-eyaml':
ensure => $package_ensure,
provider => $provider,
source => $gem_source,
}
}

File {
Expand All @@ -69,7 +102,7 @@
command => 'eyaml createkeys',
path => $cmdpath,
creates => "${confdir}/keys/private_key.pkcs7.pem",
require => [ Package['hiera-eyaml'], File["${confdir}/keys"] ]
require => [ $hiera_package_depedencies, File["${confdir}/keys"] ]
}

file { "${confdir}/keys/private_key.pkcs7.pem":
Expand Down
15 changes: 12 additions & 3 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
$hierarchy = [],
$backends = ['yaml'],
$hiera_yaml = $hiera::params::hiera_yaml,
$create_symlink = true,
$datadir = $hiera::params::datadir,
$datadir_manage = true,
$owner = $hiera::params::owner,
Expand All @@ -57,6 +58,7 @@
$eyaml_version = undef,
$merge_behavior = undef,
$extra_config = '',
$master_service = $hiera::params::master_service,
) inherits hiera::params {
File {
owner => $owner,
Expand Down Expand Up @@ -96,8 +98,15 @@
content => template('hiera/hiera.yaml.erb'),
}
# Symlink for hiera command line tool
file { '/etc/hiera.yaml':
ensure => symlink,
target => $hiera_yaml,
if $create_symlink {
file { '/etc/hiera.yaml':
ensure => symlink,
target => $hiera_yaml,
}
}

# Restart master service
Service <| title == $master_service |> {
subscribe +> File[$hiera_yaml],
}
}
24 changes: 14 additions & 10 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@
$confdir = '/etc/puppetlabs/puppet'
$cmdpath = ['/opt/puppet/bin', '/usr/bin', '/usr/local/bin']

if versioncmp($::pe_version, '3.7.0') >= 0 {
$provider = 'pe_puppetserver_gem'
if $::pe_version and versioncmp($::pe_version, '3.7.0') >= 0 {
$provider = 'pe_puppetserver_gem'
$master_service = 'pe-puppetserver'
} else {
$provider = 'pe_gem'
$master_service = 'pe-httpd'
}
else {
$provider = 'pe_gem'
} else {
if $::pe_server_version {
$master_service = 'pe-puppetserver'
} else {
$master_service = 'puppetmaster'
}
}
else {
if versioncmp($::puppetversion, '4.0.0') >= 0 {
if $::puppetversion and versioncmp($::puppetversion, '4.0.0') >= 0 {
# Configure for AIO packaging.
$provider = 'puppet_gem'
$confdir = '/etc/puppetlabs/code'
Expand All @@ -40,11 +45,10 @@
$confdir = '/etc/puppet'
$cmdpath = ['/usr/bin', '/usr/local/bin']
}
if versioncmp($::pe_server_version, '2015.2.0') >= 0 {
if $::pe_server_version {
$owner = 'pe-puppet'
$group = 'pe-puppet'
}
else {
} else {
$owner = 'puppet'
$group = 'puppet'
}
Expand Down
6 changes: 3 additions & 3 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hunner-hiera",
"version": "1.3.2",
"version": "1.4.0",
"author": "hunner",
"summary": "Deploy hiera.yaml with hierarchy, and datadir",
"license": "BSD-2-Clause",
Expand Down Expand Up @@ -40,7 +40,7 @@
"requirements": [
{
"name": "pe",
"version_requirement": ">= 3.0.0 < 2015.3.0"
"version_requirement": ">= 3.0.0 < 2015.4.0"
},
{
"name": "puppet",
Expand All @@ -50,7 +50,7 @@
"dependencies": [
{
"name": "puppetlabs-stdlib",
"version_range": ">= 4.3.1 < 5.0.0"
"version_requirement": ">= 4.3.1 < 5.0.0"
}
]
}
90 changes: 90 additions & 0 deletions spec/acceptance/hiera_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
require 'spec_helper_acceptance'

describe 'hiera' do
version = on(master, puppet('--version')).stdout
case version
when /Puppet Enterprise 3/
confdir = '/etc/puppetlabs/puppet'
manifestsdir = "#{confdir}/manifests"
when /^3/
confdir = '/etc/puppet'
manifestsdir = "#{confdir}/manifests"
when /^4/
confdir = '/etc/puppetlabs/code'
manifestsdir = "#{confdir}/environments/production/manifests"
else
fail "Unknown puppet version #{version}"
end
hierayaml = "#{confdir}/hiera.yaml"
datadir = "#{confdir}/hieradata"
sitepp = File.join(manifestsdir, 'site.pp')

describe 'puppet apply' do
it 'creates a hiera.yaml' do
pp = <<-EOS
class { 'hiera':
eyaml => true,
hierarchy => [
'%{environment}/%{calling_class}',
'%{environment}',
'common',
],
}
EOS
apply_manifest_on(master, pp, :catch_failures => true)
apply_manifest_on(master, pp, :catch_changes => true)
end
end
describe file(hierayaml), :node => master do
its(:content) do should eq(<<-EOS
# managed by puppet
---
:backends:
- eyaml
- yaml
:logger: console
:hierarchy:
- "%{environment}/%{calling_class}"
- "%{environment}"
- common
:yaml:
:datadir: #{datadir}
:eyaml:
:datadir: #{datadir}
:pkcs7_private_key: #{confdir}/keys/private_key.pkcs7.pem
:pkcs7_public_key: #{confdir}/keys/public_key.pkcs7.pem
EOS
)
end
end
describe 'querying hiera' do
let(:pp) do
<<-EOS
class myclass {
notify { hiera('myclass::value'): }
}
include myclass
EOS
end
before :all do
on master, "mkdir -p #{datadir}/production"
on master, "echo myclass::value: 'found output' > #{datadir}/production/myclass.eyaml"
end
it 'finds it on the command line' do
expect(on(master, 'hiera myclass::value environment=production calling_class=myclass').stdout.strip).to eq('found output')
end
it 'finds it in puppet apply' do
expect(apply_manifest_on(master, pp, :catch_failures => true).stdout.strip).to match(%r{found output})
end
it 'finds it in puppet agent', :if => (master.is_pe? || master[:roles].include?('aio')) do
on master, "mkdir -p #{manifestsdir}"
create_remote_file(master, sitepp, pp)
sleep(5)
expect(on(master, puppet('agent', '-t', '--server', '$(hostname -f)'), :acceptable_exit_codes => [0,2]).stdout.strip).to match(%r{found output})
end
end
end
18 changes: 18 additions & 0 deletions spec/acceptance/nodesets/pe-redhat-7-vcloud.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
HOSTS:
'redhat-7-vcloud':
roles:
- master
- dashboard
- database
- agent
platform: el-7-x86_64
hypervisor: vcloud
template: redhat-7-x86_64
CONFIG:
type: pe
ssh:
keys: "~/.ssh/id_rsa-acceptance"
datastore: instance0
folder: Delivery/Quality Assurance/Enterprise/Dynamic
resourcepool: delivery/Quality Assurance/Enterprise/Dynamic
pooling_api: http://vcloud.delivery.puppetlabs.net/
18 changes: 18 additions & 0 deletions spec/acceptance/nodesets/pe-ubuntu-1404-vcloud.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
HOSTS:
'ubuntu-1404-vcloud':
roles:
- master
- dashboard
- database
- agent
platform: ubuntu-1404-x86_64
template: ubuntu-1404-x86_64
hypervisor: vcloud
CONFIG:
type: pe
ssh:
keys: "~/.ssh/id_rsa-acceptance"
datastore: instance0
folder: Delivery/Quality Assurance/Enterprise/Dynamic
resourcepool: delivery/Quality Assurance/Enterprise/Dynamic
pooling_api: http://vcloud.delivery.puppetlabs.net/
15 changes: 15 additions & 0 deletions spec/acceptance/nodesets/redhat-7-vcloud.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
HOSTS:
'redhat-7-vcloud':
roles:
- master
platform: el-7-x86_64
hypervisor: vcloud
template: redhat-7-x86_64
CONFIG:
type: foss
ssh:
keys: "~/.ssh/id_rsa-acceptance"
datastore: instance0
folder: Delivery/Quality Assurance/Enterprise/Dynamic
resourcepool: delivery/Quality Assurance/Enterprise/Dynamic
pooling_api: http://vcloud.delivery.puppetlabs.net/
Loading