Skip to content

Commit

Permalink
Docs and more params of psick::puppet::gems and psick::rbenv #50 #47
Browse files Browse the repository at this point in the history
  • Loading branch information
alvagante committed Feb 1, 2018
1 parent 9de7f1b commit f68c085
Show file tree
Hide file tree
Showing 2 changed files with 191 additions and 94 deletions.
168 changes: 119 additions & 49 deletions manifests/puppet/gems.pp
Original file line number Diff line number Diff line change
@@ -1,80 +1,150 @@
# This class installs the gems needed to run Puppet with this control-repo
# It can be also be used to install any gem on any gem environment (Puppet,
# PuppetServer, System, RBenv...).
#
# @example Install under rbenv environment gems needed for CI tests:
# psick::puppet::gems::default_set: citest
# psick::puppet::gems::install_puppet_gems: false
# psick::puppet::gems::install_rbenv_gems: true
#
# @example Install under system, puppet and puppet server environment
# gems needed for server. Add a specific gem for puppetserver only
# psick::puppet::gems::default_set: 'master
# psick::puppet::gems::install_puppet_gems: true
# psick::puppet::gems::install_puppetserver_gems: true
# psick::puppet::gems::install_system_gems: true
# psick::puppet::gems::additional_puppetserver_gems:
# - hiera-mysql
#
# @param ensure Set status of managed resources
# @param default_set Define a set of default gems to install for different
# use cases. Possible values: 'none','client','master','developer','citest',
# 'cideploy','integration'. Gems defined here are installed under all the
# environments set by install_*_gems params.
# @param install_gems Array of additional custom gems to install under all the
# environments set by install_*_gems params.
# @param install_options Optional optional to add to the package provider when
# installing gems
# @param install_system_gems Manage installation of gems using system's gem
# @param install_puppet_gems Manage installation of gems using Puppet's gem
# @param install_puppetserver_gems Manage installation of gems using Puppetserver's gem
# @param install_rbenv_gems Manage installation of gems under rbenv (requires
# jdowning/rbenv or compatible module)
# @param additional_system_gems Array of additional gems to install using system's gem
# @param additional_puppet_gems Array of additional gems to install using Puppet's gem
# @param additional_puppetserver_gems Array of additional gems to install using
# Puppetserver's gem
# @param additional_rbenv_gems Array of additional gems to install under rbenv
# @param rbenv_ruby_version Ruby version to use under rbenv. Default is from
# $::psick::rbenv::default_ruby_version
# @param manage If to actually manage ANY resource from this class.
# When set to false, no resource from this class is managed whatever are
# the other parameters.
# @param auto_prereq If to automatically install eventual dependencies required
# by this class. Set to false if you have problems with duplicated resources.
# If so, you'll need to ensure the needed prerequisites are present.
# @param no_noop Set noop metaparameter to false to all the resources of this class.
# This overrides any noop setting which might be in place.
#
class psick::puppet::gems (
Enum['present','absent'] $ensure = 'present',
Enum['none','client','master','developer','citest','cideploy','integration'] $default_set = 'client',
Enum['none','client','master','developer','citest','cideploy','integration'] $default_set = 'none',
Array $install_gems = [ ],
Array $install_options = [ ],
Boolean $install_system_gems = false,
Boolean $install_puppet_gems = true,
Boolean $install_puppetserver_gems = false,
Boolean $install_rbenv_gems = false,
Boolean $install_rbenv_gems = false,
Array $additional_system_gems = [],
Array $additional_puppet_gems = [],
Array $additional_puppetserver_gems = [],
Array $additional_rbenv_gems = [],
Optional[String] $rbenv_ruby_version = undef,
Boolean $no_noop = false,
Boolean $manage = $::psick::manage,
Boolean $auto_prereq = $::psick::auto_prereq,
Boolean $no_noop = false,
) {

if $no_noop {
info('Forced no-noop mode.')
noop(false)
}

$minimal_gems = ['r10k','hiera-eyaml','deep_merge']
$minimal_test_gems = ['puppet-lint','rspec-puppet','rake','bundler','simplecov','minitest','rspec-puppet-facts','puppetlabs_spec_helper']

$default_gems = $default_set ? {
'none' => [],
'client' => [],
'master' => $minimal_gems,
'cideploy' => $minimal_gems + $minimal_test_gems,
'citest' => $minimal_gems + $minimal_test_gems,
'integration' => $minimal_gems + $minimal_test_gems + ['beaker','beaker-rspec','beaker-puppet_install_helper'],
'developer' => $minimal_gems + $minimal_test_gems + ['puppet-debug','puppet-blacksmith'],
}

if $install_rbenv_gems and $auto_prereq {
include psick::rbenv
}

$all_gems = $default_gems + $install_gems
$all_gems.each | $gem | {
if $manage {
if $no_noop {
info('Forced no-noop mode.')
noop(false)
}

$minimal_gems = ['r10k','hiera-eyaml','deep_merge']
$minimal_test_gems = ['puppet-lint','rspec-puppet','rake','bundler','simplecov','minitest','rspec-puppet-facts','puppetlabs_spec_helper','yaml-lint']

$default_gems = $default_set ? {
'none' => [],
'client' => [],
'master' => $minimal_gems,
'cideploy' => $minimal_gems + $minimal_test_gems,
'citest' => $minimal_gems + $minimal_test_gems,
'integration' => $minimal_gems + $minimal_test_gems + ['beaker','beaker-rspec','beaker-puppet_install_helper'],
'developer' => $minimal_gems + $minimal_test_gems + ['puppet-debug','puppet-blacksmith'],
}

$all_gems = $default_gems + $install_gems

if $install_system_gems {
include ::psick::ruby
package { $gem:
ensure => $ensure,
install_options => $install_options,
provider => 'gem',
require => Class['psick::ruby'],
if $auto_prereq {
include ::psick::ruby
}
$system_gems = $all_gems + $additional_system_gems
$system_gems.each | $gem | {
package { $gem:
ensure => $ensure,
install_options => $install_options,
provider => 'gem',
require => Class['psick::ruby'],
}
}
}

if $install_puppet_gems {
if !defined(Class['r10k']) {
package { "puppet_${gem}":
$puppet_gems = $all_gems + $additional_puppet_gems
$puppet_gems.each | $gem | {
if !defined(Class['r10k']) {
package { "puppet_${gem}":
ensure => $ensure,
name => $gem,
install_options => $install_options,
provider => 'puppet_gem',
}
}
}
}

if $install_puppetserver_gems {
$puppetserver_gems = $all_gems + $additional_puppetserver_gems
$puppetserver_gems.each | $gem | {
package { "puppetserver_${gem}":
ensure => $ensure,
name => $gem,
install_options => $install_options,
provider => 'puppet_gem',
provider => 'puppetserver_gem',
}
}
}
if $install_puppetserver_gems {
package { "puppetserver_${gem}":
ensure => $ensure,
name => $gem,
install_options => $install_options,
provider => 'puppetserver_gem',

if $install_rbenv_gems {
if $auto_prereq {
include ::psick::rbenv
}
}
if $install_rbenv_gems and $gem != 'bundler' {
# bundler gem already installed by rbenv module
$rbenv_require = $auto_prereq ? {
true => Class['psick::rbenv'],
false => undef,
}
rbenv::gem { $gem:
ruby_version => pick($rbenv_ruby_version,$::psick::rbenv::default_ruby_version),
skip_docs => true,
require => $rbenv_require,
$rbenv_gems = $all_gems + $additional_rbenv_gems
$rbenv_gems.each | $gem | {
# bundler gem already installed by rbenv module
if $gem != 'bundler' {
rbenv::gem { $gem:
ruby_version => pick($rbenv_ruby_version,$::psick::rbenv::default_ruby_version),
skip_docs => true,
require => $rbenv_require,
}
}
}
}
}
Expand Down
117 changes: 72 additions & 45 deletions manifests/rbenv.pp
Original file line number Diff line number Diff line change
@@ -1,62 +1,89 @@
# @class rbenv
# @class Manages rbenv using jdowning/rbenv module
#
# @param module The name of the module to use to manage rbenv. Currently
# only jdowning/rbenv supported.
# @param default_ruby_version Default ruby version to use under rbenv. When set
# (default is '2.4.2') the relevant rbenv::build is created
# @param Where rbenv will be installed to.
# @param owner This defines who owns the rbenv install directory.
# @param group This defines the group membership for rbenv.
# @param latest This defines whether the rbenv $install_dir is kept up-to-date.
# @param plugin_hash An hash of resources data to be passed to rbenv::plugin
# @param build_hash An hash of resources data to be passed to rbenv::build
# @param gem_hash An hash of resources data to be passed to rbenv::gem
# @param manage If to actually manage ANY resource from this class.
# When set to false, no resource from this class is managed whatever are
# the other parameters.
# @param auto_prereq If to automatically install eventual dependencies required
# by this class. Set to false if you have problems with duplicated resources.
# If so, you'll need to ensure the needed prerequisites are present.
# @param no_noop Set noop metaparameter to false to all the resources of this class.
# This overrides any noop setting which might be in place.
#
class psick::rbenv (

Variant[Boolean,String] $ensure = present,
Enum['jdowning'] $module = 'jdowning',
Variant[Boolean,String] $ensure = present,
Enum['jdowning'] $module = 'jdowning',

Optional[String] $default_ruby_version = '2.4.2',
Optional[String] $install_dir = undef,
Optional[String] $owner = undef,
Optional[String] $group = undef,
Optional[String] $latest = undef,

Hash $plugin_hash = {},
Hash $build_hash = {},
Hash $gem_hash = {},
Optional[String] $install_dir = undef,
Optional[String] $owner = undef,
Optional[String] $group = undef,
Optional[String] $latest = undef,

Boolean $auto_prereq = $::psick::auto_prereq,
Hash $plugin_hash = {},
Hash $build_hash = {},
Hash $gem_hash = {},

Boolean $manage = $::psick::manage,
Boolean $auto_prereq = $::psick::auto_prereq,
Boolean $no_noop = false,
) {

# Installation management
case $module {
'jdowning': {
class { 'rbenv':
manage_deps => $auto_prereq,
install_dir => $install_dir,
owner => $owner,
group => $group,
latest => $latest,
}
$default_gem_options = {
ruby_version => $default_ruby_version,
}
if $default_ruby_version and $auto_prereq {
rbenv::plugin { 'rbenv/ruby-build': }
rbenv::build { $default_ruby_version:
global => true,
if $manage {
if $no_noop {
info('Forced no-noop mode.')
noop(false)
}

# Installation management
case $module {
'jdowning': {
class { 'rbenv':
manage_deps => $auto_prereq,
install_dir => $install_dir,
owner => $owner,
group => $group,
latest => $latest,
}
}
$plugin_hash.each |$k,$v| {
rbenv::plugin { $k:
* => $v,
$default_gem_options = {
ruby_version => $default_ruby_version,
}
}
$build_hash.each |$k,$v| {
rbenv::build { $k:
* => $v,
if $default_ruby_version and $auto_prereq {
rbenv::plugin { 'rbenv/ruby-build': }
rbenv::build { $default_ruby_version:
global => true,
}
}
}
$gem_hash.each |$k,$v| {
rbenv::gem { $k:
* => $default_gem_options + $v,
$plugin_hash.each |$k,$v| {
rbenv::plugin { $k:
* => $v,
}
}
$build_hash.each |$k,$v| {
rbenv::build { $k:
* => $v,
}
}
$gem_hash.each |$k,$v| {
rbenv::gem { $k:
* => $default_gem_options + $v,
}
}
}
}
default: {
contain ::rbenv
default: {
contain ::rbenv
}
}
}

}

0 comments on commit f68c085

Please sign in to comment.