diff --git a/REFERENCE.md b/REFERENCE.md index e5586f62..95e21a80 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -9,7 +9,6 @@ #### Public Classes * [`r10k`](#r10k): This class configures r10k -* [`r10k::install`](#r10k--install): This class is used by the ruby or pe_ruby class * [`r10k::install::bundle`](#r10k--install--bundle): This class installs the r10k bundle * [`r10k::install::gem`](#r10k--install--gem): Install the r10k gem using system ruby * [`r10k::install::puppet_gem`](#r10k--install--puppet_gem): This class links the r10k binary for Puppet FOSS 4.2 and up @@ -26,6 +25,7 @@ #### Private Classes * `r10k::config`: Set up the root r10k config file (/etc/r10k.yaml). +* `r10k::install`: This class is used by the ruby or pe_ruby class ### Data types @@ -311,84 +311,6 @@ Data type: `Stdlib::Absolutepath` Default value: `$r10k::params::puppetconf_path` -### `r10k::install` - -This class is used by the ruby or pe_ruby class - -#### Parameters - -The following parameters are available in the `r10k::install` class: - -* [`package_name`](#-r10k--install--package_name) -* [`version`](#-r10k--install--version) -* [`provider`](#-r10k--install--provider) -* [`keywords`](#-r10k--install--keywords) -* [`install_options`](#-r10k--install--install_options) -* [`manage_ruby_dependency`](#-r10k--install--manage_ruby_dependency) -* [`puppet_master`](#-r10k--install--puppet_master) -* [`is_pe_server`](#-r10k--install--is_pe_server) -* [`gem_source`](#-r10k--install--gem_source) - -##### `package_name` - -Data type: `Any` - - - -##### `version` - -Data type: `Any` - - - -##### `provider` - -Data type: `Any` - - - -##### `keywords` - -Data type: `Any` - - - -##### `install_options` - -Data type: `Any` - - - -##### `manage_ruby_dependency` - -Data type: `Any` - - - -##### `puppet_master` - -Data type: `Any` - - - -Default value: `true` - -##### `is_pe_server` - -Data type: `Any` - - - -Default value: `$r10k::params::is_pe_server` - -##### `gem_source` - -Data type: `Optional[String[1]]` - - - -Default value: `undef` - ### `r10k::install::bundle` This class installs the r10k bundle diff --git a/manifests/init.pp b/manifests/init.pp index f4bbf4bf..457f9d10 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -55,17 +55,7 @@ include r10k::postrun_command } - class { 'r10k::install': - install_options => $install_options, - keywords => $gentoo_keywords, - manage_ruby_dependency => $manage_ruby_dependency, - package_name => $package_name, - provider => $provider, - gem_source => $gem_source, - version => $version, - puppet_master => $puppet_master, - } - + contain r10k::install contain r10k::config if $mcollective { diff --git a/manifests/install.pp b/manifests/install.pp index fe145eb6..f294af1c 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -1,42 +1,23 @@ -# This class is used by the ruby or pe_ruby class -class r10k::install ( - $package_name, - $version, - $provider, - $keywords, - $install_options, - $manage_ruby_dependency, - $puppet_master = true, - $is_pe_server = $r10k::params::is_pe_server, - Optional[String[1]] $gem_source = undef, -) inherits r10k::params { - if $package_name == '' { - case $provider { - 'openbsd': { - if (versioncmp("${facts['kernelversion']}", '5.8') < 0) { #lint:ignore:only_variable_string - $real_package_name = 'ruby21-r10k' - } else { - $real_package_name = 'ruby22-r10k' - } - } - default: { $real_package_name = 'r10k' } - } - } else { - $real_package_name = $package_name - } +# +# @summary This class is used by the ruby or pe_ruby class +# +# @api private +# +class r10k::install { + assert_private() - case $provider { + case $r10k::provider { 'bundle': { include r10k::install::bundle } 'puppet_gem', 'gem', 'openbsd', 'pkgng', 'pacman', 'portage': { - if $provider == 'gem' { + if $r10k::provider == 'gem' { class { 'r10k::install::gem': - manage_ruby_dependency => $manage_ruby_dependency, - version => $version; + manage_ruby_dependency => $r10k::manage_ruby_dependency, + version => $r10k::version; } } - elsif $provider == 'puppet_gem' { + elsif $r10k::provider == 'puppet_gem' { # Puppet FOSS 4.2 and up ships a vendor provided ruby. # Using puppet_gem uses that instead of the system ruby. include r10k::install::puppet_gem @@ -47,21 +28,21 @@ # empty to value to the gem providers This code # converts an empty array to semi-standard gem options # This was previously undef but that caused strict var issues - if $provider in ['puppet_gem', 'gem'] and $install_options == [] { + if $r10k::provider in ['puppet_gem', 'gem'] and $r10k::install_options == [] { $provider_install_options = ['--no-document'] } else { - $provider_install_options = $install_options + $provider_install_options = $r10k::install_options } # Puppet Enterprise 3.8 and ships an embedded r10k so thats all thats supported # This conditional should not effect FOSS customers based on the fact - package { $real_package_name: - ensure => $version, - provider => $provider, - source => $gem_source, + package { $r10k::package_name: + ensure => $r10k::version, + provider => $r10k::provider, + source => $r10k::gem_source, install_options => $provider_install_options, } } - default: { fail("${module_name}: ${provider} is not supported. Valid values are: 'gem', 'puppet_gem', 'bundle', 'openbsd'") } + default: { fail("${module_name}: ${r10k::provider} is not supported. Valid values are: 'gem', 'puppet_gem', 'bundle', 'openbsd'") } } } diff --git a/manifests/params.pp b/manifests/params.pp index 48a3bcf7..a726d97d 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -1,7 +1,9 @@ # Reasonable defaults for all classes class r10k::params { - $postrun = undef - $package_name = '' + $package_name = $facts['os']['name'] ? { + 'OpenBSD' => 'ruby31-r10k', + default => 'r10k' + } $version = 'installed' $manage_modulepath = false $manage_ruby_dependency = 'ignore' diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index a30ed8e5..6a55f88f 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -1,6 +1,9 @@ # frozen_string_literal: true require 'spec_helper' + +version = '2.0.0' + describe 'r10k' do on_supported_os.each do |os, os_facts| context "on #{os}" do @@ -156,6 +159,147 @@ it { is_expected.to contain_file('r10k.yaml').with_content(%r{^pool_size: 5$}) } end + # This install method uses the archived puppetlabs/ruby module + # It doesn't support Gentoo + context 'with gem provider', if: os_facts[:os]['name'] != 'Gentoo' do + let :params do + { + install_options: '', + manage_ruby_dependency: 'declare', + provider: 'gem', + version: version, + puppet_master: true + } + end + + it { is_expected.to contain_class('r10k::install::gem').with(version: version) } + + it do + expect(subject).to contain_package('r10k').with( + ensure: version, + provider: 'gem' + ) + end + end + context 'with gem with empty install_options', if: os_facts[:os]['name'] != 'Gentoo' do + let :params do + { + manage_ruby_dependency: 'include', + provider: 'gem', + version: version, + install_options: [], + puppet_master: true + } + end + + it do + expect(subject).to contain_package('r10k').with( + ensure: version, + provider: 'gem', + install_options: ['--no-document'] + ) + end + end + + context 'with gem with populated install_options', if: os_facts[:os]['name'] != 'Gentoo' do + let :params do + { + manage_ruby_dependency: 'include', + provider: 'gem', + version: version, + install_options: ['BOGON'], + puppet_master: true + } + end + + it do + expect(subject).to contain_package('r10k').with( + ensure: version, + provider: 'gem', + install_options: ['BOGON'] + ) + end + end + context 'with puppet_gem provider' do + let :params do + { + version: version, + provider: 'puppet_gem', + manage_ruby_dependency: 'declare', + install_options: '' + } + end + + it { is_expected.to contain_class('r10k::install::puppet_gem') } + + it do + expect(subject).to contain_package('r10k').with( + ensure: version, + provider: 'puppet_gem' + ) + end + end + + context 'with puppet_gem on Puppet FOSS' do + let :params do + { + manage_ruby_dependency: 'declare', + install_options: '', + provider: 'puppet_gem', + version: version, + } + end + + it { is_expected.to contain_package('r10k').with( + ensure: version, + provider: 'puppet_gem' + ) } + + it do + expect(subject).to contain_file('/usr/bin/r10k').with( + ensure: 'link', + target: '/opt/puppetlabs/puppet/bin/r10k', + require: 'Package[r10k]' + ) + end + end + context 'with defaults and source specified', if: os_facts[:os]['name'] != 'Gentoo' do + let :params do + { + manage_ruby_dependency: 'include', + provider: 'gem', + version: version, + gem_source: 'https://some.alternate.source.com/', + install_options: [], + puppet_master: true + } + end + + it { is_expected.to contain_class('r10k::install::gem') } + + it do + expect(subject).to contain_package('r10k').with( + ensure: version, + provider: 'gem', + source: 'https://some.alternate.source.com/' + ) + end + end + + context 'with bundle provider' do + let :params do + { + version: version, + provider: 'bundle', + manage_ruby_dependency: 'declare', + install_options: '', + puppet_master: true + } + end + + it { is_expected.to contain_class('r10k::install::bundle') } + it { is_expected.not_to contain_package('r10k') } + end end end end