Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge the package management code into one define. #117

Merged
merged 1 commit into from
Feb 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ The resulting output in /etc/puppet/hiera.yaml:
## 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.
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](https://docs.puppetlabs.com/hiera/1/configuring.html#global-settings).
Expand Down Expand Up @@ -151,15 +151,30 @@ The following parameters are available for the hiera class:
* `eyaml_name`
The 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: `undef`
* `eyaml_source`
An alternate gem source for installing hiera-eyaml.
Default: `undef`, uses gem backend default
* `eyaml_datadir`
The path to the directory where hiera will look for databases with the eyaml backend.
Default: same as `datadir`
* `eyaml_extension`
The file extension for the eyaml backend.
Default: `undef`, backend defaults to `'.eyaml'`
* `eyaml_version`
The version of hiera-eyaml to install. Accepts 'installed', 'latest', '2.0.7', etc
* `deep_merge_name`
The name of the deep_merge gem.
Default: 'deep\_merge'
* `deep_merge_version`
The version of deep\_merge to install. Accepts 'installed', 'latest', '2.0.7', etc.
Default: `undef`
* `deep_merge_source`
An alternate gem source for installing deep_merge.
Default: `undef`, uses gem backend default
* `deep_merge_options`
A hash of options to set in hiera.yaml for the deep merge behavior.
Default: `{}`
* `confdir`
The path to Puppet's confdir.
Default: `$::settings::confdir` which should be the following:
Expand All @@ -177,12 +192,8 @@ The following parameters are available for the hiera class:
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: `true`
* `gem_source`
An alternate gem source for installing hiera-eyaml.
Default: `undef`, uses gem backend default
* `merge_behavior`
Which hiera merge behavior to use.
**Note**: You need to manage any package/gem dependencies yourself.
* `merge_behavior`
Which 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.
Expand Down
73 changes: 10 additions & 63 deletions manifests/deep_merge.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,69 +10,16 @@
#
# Copyright (C) 2016 Joseph Yaworski, unless otherwise noted.
#
class hiera::deep_merge (
$provider = $hiera::provider,
$deep_merge_version = $hiera::deep_merge_version,
$gem_source = $hiera::gem_source,
$deep_merge_name = $hiera::deep_merge_name,
) inherits hiera::params {
class hiera::deep_merge {
$provider = $hiera::provider
$deep_merge_version = $hiera::deep_merge_version
$deep_merge_source = $hiera::deep_merge_source
$deep_merge_name = $hiera::deep_merge_name

$package_ensure = $deep_merge_version ? {
undef => 'installed',
default => $deep_merge_version,
}
if $provider == 'pe_puppetserver_gem' {
Exec {
path => [
'/opt/puppetlabs/server/bin',
'/opt/puppetlabs/puppet/bin',
'/opt/puppet/bin',
'/usr/bin',
'/bin',
],
}

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

# The puppetserver gem wouldn't install the commandline util, so we do
# that here
#XXX Pre-puppet 4.0.0 version (PUP-1073)
#BUG This can't actually update the gem version if already installed.
if $deep_merge_version and $deep_merge_version =~ /^\d+\.\d+\.\d+$/ {
$gem_flag = "--version ${deep_merge_version}"
} else {
$gem_flag = undef
}
#XXX Post-puppet 4.0.0
#package { 'deep_merge command line':
# ensure => installed,
# name => 'deep_merge',
# provider => 'pe_gem',
# source => $gem_source,
#}

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

exec { 'install puppetserver gem deep_merge':
command => "puppetserver gem install deep_merge ${gem_flag}",
creates => $puppetserver_gem_creates,
}
} else {
package { 'deep_merge':
ensure => $package_ensure,
name => $deep_merge_name,
provider => $provider,
source => $gem_source,
}
hiera::install { 'deep_merge':
gem_name => $deep_merge_name,
provider => $provider,
gem_version => $deep_merge_version,
gem_source => $deep_merge_source,
}
}
82 changes: 10 additions & 72 deletions manifests/eyaml.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,85 +11,23 @@
# Copyright (C) 2014 Terri Haber, unless otherwise noted.
#
class hiera::eyaml {
$eyaml_name = $hiera::eyaml_name
$provider = $hiera::provider
$eyaml_version = $hiera::eyaml_version
$eyaml_source = $hiera::_eyaml_source

$owner = $hiera::owner
$group = $hiera::group
$cmdpath = $hiera::cmdpath
$confdir = $hiera::confdir
$create_keys = $hiera::create_keys
$_keysdir = $hiera::_keysdir
$eyaml_version = $hiera::eyaml_version
$gem_source = $hiera::gem_source
$eyaml_name = $hiera::eyaml_name

$package_ensure = $eyaml_version ? {
undef => 'installed',
default => $eyaml_version,
}
if $provider == 'pe_puppetserver_gem' {
Exec {
path => [
'/opt/puppet/bin',
'/usr/bin',
'/bin',
],
}

$hiera_package_depedencies = [
Exec["install ruby gem ${eyaml_name}"],
Exec["install puppetserver gem ${eyaml_name}"],
]

# The puppetserver gem wouldn't install the commandline util, so we do
# that here (PUP-1073)
#BUG This can't actually update the gem version if already installed.
if $eyaml_version and $eyaml_version =~ /^\d+\.\d+\.\d+$/ {
$gem_flag = "--version ${eyaml_version}"
} else {
$gem_flag = undef
}

exec { "install ruby gem ${eyaml_name}":
command => "gem install ${eyaml_name} ${gem_flag}",
creates => '/opt/puppet/bin/eyaml',
}

exec { "install puppetserver gem ${eyaml_name}":
command => "puppetserver gem install ${eyaml_name} ${gem_flag}",
creates => '/var/opt/lib/pe-puppet-server/jruby-gems/bin/eyaml',
}
$master_subscribe = Exec["install puppetserver gem ${eyaml_name}"]
} elsif $provider == 'puppetserver_gem' {
$hiera_package_depedencies = [
Package[$eyaml_name],
Package["puppetserver ${eyaml_name}"],
]
package { "puppetserver ${eyaml_name}":
ensure => $package_ensure,
name => $eyaml_name,
provider => $provider,
source => $gem_source,
}
package { $eyaml_name:
ensure => $package_ensure,
provider => 'puppet_gem',
source => $gem_source,
}
$master_subscribe = [
Package[$eyaml_name],
Package["puppetserver ${eyaml_name}"],
]
} else {
$hiera_package_depedencies = Package[$eyaml_name]
package { $eyaml_name:
ensure => $package_ensure,
provider => $provider,
source => $gem_source,
}
$master_subscribe = Package[$eyaml_name]
}
Service <| title == $hiera::master_service |> {
subscribe +> $master_subscribe,
hiera::install { 'eyaml':
gem_name => $eyaml_name,
provider => $provider,
gem_version => $eyaml_version,
gem_source => $eyaml_source,
}

File {
Expand All @@ -110,7 +48,7 @@
command => 'eyaml createkeys',
path => $cmdpath,
creates => "${_keysdir}/private_key.pkcs7.pem",
require => [ $hiera_package_depedencies, File[$_keysdir] ],
require => [ Hiera::Install['eyaml'], File[$_keysdir] ],
}

file { "${_keysdir}/private_key.pkcs7.pem":
Expand Down
17 changes: 14 additions & 3 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
$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,
Expand All @@ -58,20 +60,28 @@
$cmdpath = $hiera::params::cmdpath,
$create_keys = true,
$keysdir = undef,
$gem_source = undef,
$eyaml_version = undef,
$deep_merge_version = 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,

#Deprecated
$gem_source = undef,
) inherits hiera::params {
if $keysdir {
$_keysdir = $keysdir
} else {
$_keysdir = "${confdir}/keys"
}

if $eyaml_source {
$_eyaml_source = $eyaml_source
} else {
$_eyaml_source = $gem_source
}
File {
owner => $owner,
group => $group,
Expand Down Expand Up @@ -109,6 +119,7 @@
# - $_keysdir
# - $confdir
# - $merge_behavior
# - $deep_merge_options
# - $extra_config
file { $hiera_yaml:
ensure => present,
Expand Down
82 changes: 82 additions & 0 deletions manifests/install.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Private define
define hiera::install (
$gem_name,
$provider,
$creates_bin = $name,
$gem_version = undef,
$gem_source = undef,
) {
$gem_ensure = pick($gem_version, 'installed')
if $provider == 'pe_puppetserver_gem' {
Exec {
path => [
'/opt/puppetlabs/server/bin',
'/opt/puppetlabs/puppet/bin',
'/opt/puppet/bin',
'/usr/bin',
'/bin',
],
}
if $::pe_server_version {
$vendored_gem_creates = "/opt/puppetlabs/puppet/bin/${creates_bin}"
$puppetserver_gem_creates = "/opt/puppetlabs/server/data/puppetserver/jruby-gems/bin/${creates_bin}"
} else {
$vendored_gem_creates = "/opt/puppet/bin/${creates_bin}"
$puppetserver_gem_creates = "/var/opt/lib/pe-puppet-server/jruby-gems/bin/${creates_bin}"
}

# The puppetserver gem wouldn't install the commandline util, so we do
# that here (PUP-1073)
#BUG This can't actually update the gem version if already installed.
if $gem_version and $gem_version =~ /^\d+\.\d+\.\d+$/ {
$gem_flag = "--version ${gem_version}"
} else {
$gem_flag = undef
}
if $gem_source {
# Use a local source, like the package providers would
validate_absolute_path($gem_source)
$source_flag = '--local'
} else {
$source_flag = undef
}

exec { "install ruby gem ${gem_name}":
command => "gem install ${source_flag} ${gem_name} ${gem_flag}",
creates => $vendored_gem_creates,
}

exec { "install puppetserver gem ${gem_name}":
command => "puppetserver gem install ${source_flag} ${gem_name} ${gem_flag}",
creates => $puppetserver_gem_creates,
}
$master_subscribe = Exec["install puppetserver gem ${gem_name}"]
} elsif $provider == 'puppetserver_gem' {
package { "puppetserver ${gem_name}":
ensure => $gem_ensure,
name => $gem_name,
provider => $provider,
source => $gem_source,
}
package { $gem_name:
ensure => $gem_ensure,
provider => 'puppet_gem',
source => $gem_source,
}
$master_subscribe = [
Package[$gem_name],
Package["puppetserver ${gem_name}"],
]
} else {
$hiera_package_depedencies = Package[$gem_name]
package { $gem_name:
ensure => $gem_ensure,
provider => $provider,
source => $gem_source,
}
$master_subscribe = Package[$gem_name]
}
Service <| title == $hiera::master_service |> {
subscribe +> $master_subscribe,
}
}
1 change: 1 addition & 0 deletions spec/acceptance/hiera_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
class { 'hiera':
eyaml => true,
eyaml_name => 'custom-eyaml',
merge_behavior => 'deep',
puppet_conf_manage => true,
hierarchy => [
'virtual/%{::virtual}',
Expand Down
Loading