diff --git a/manifests/config.pp b/manifests/config.pp index 4c8ca512..db1aee71 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -46,26 +46,26 @@ # Charlie Sharpsteen # Zack Smith class r10k::config ( - $configfile, - $cachedir, - Boolean $manage_modulepath, - $root_user, - $root_group, - $modulepath = undef, - $remote = '', - Variant[String, Hash ] $sources = 'UNSET', - Optional[Array] $postrun = undef, - Stdlib::Absolutepath $puppetconf_path = $r10k::params::puppetconf_path, + $configfile = $r10k::params::r10k_config_file, + $cachedir = $r10k::params::r10k_cache_dir, + Optional[Hash] $sources = $r10k::params::sources, + $modulepath = $r10k::params::modulepath, + $remote = $r10k::params::remote, + Boolean $manage_modulepath = $r10k::params::manage_modulepath, Stdlib::Absolutepath $r10k_basedir = $r10k::params::r10k_basedir, Boolean $manage_configfile_symlink = $r10k::params::manage_configfile_symlink, - Stdlib::Absolutepath $configfile_symlink = '/etc/r10k.yaml', + Stdlib::Absolutepath $configfile_symlink = $r10k::params::configfile_symlink, + Hash $git_settings = $r10k::params::git_settings, + Hash $forge_settings = $r10k::params::forge_settings, + Hash $deploy_settings = $r10k::params::deploy_settings, + Optional[Array] $postrun = undef, + $root_user = $r10k::params::root_user, + $root_group = $r10k::params::root_group, + Stdlib::Absolutepath $puppetconf_path = $r10k::params::puppetconf_path, String $r10k_yaml_template = 'r10k/r10k.yaml.erb', - Hash $git_settings = {}, - Hash $forge_settings = {}, - Hash $deploy_settings = {}, ) inherits r10k::params { - if $sources == 'UNSET' { + if $sources == undef { $r10k_sources = { 'puppet' => { 'remote' => $remote, diff --git a/manifests/params.pp b/manifests/params.pp index b5f132c2..50576b63 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -10,13 +10,11 @@ $sources = undef $puppet_master = true - if versioncmp("${::puppetversion}", '4.0.0') >= 0 { #lint:ignore:only_variable_string - $r10k_basedir = $::settings::environmentpath - $r10k_cache_dir = "${::settings::vardir}/r10k" - } else { - $r10k_basedir = "${::settings::confdir}/environments" - $r10k_cache_dir = '/var/cache/r10k' - } + $r10k_basedir = $::settings::environmentpath + $r10k_cache_dir = "${::settings::vardir}/r10k" + $r10k_config_file = '/etc/puppetlabs/r10k/r10k.yaml' + $r10k_binary = 'r10k' + $puppetconf_path = '/etc/puppetlabs/puppet' $manage_configfile_symlink = false $configfile_symlink = '/etc/r10k.yaml' $git_settings = {} @@ -59,24 +57,20 @@ } if getvar('::pe_server_version') { - #if $is_pe_server and versioncmp("${::puppetversion}", '4.0.0') >= 0 { #lint:ignore:only_variable_string # PE 4 or greater specific settings # r10k configuration - $r10k_config_file = '/etc/r10k.yaml' - - $puppetconf_path = '/etc/puppetlabs/puppet' $pe_module_path = '/opt/puppetlabs/puppet/modules' + # Mcollective configuration dynamic $mc_service_name = 'mcollective' $plugins_dir = '/opt/puppetlabs/mcollective/plugins/mcollective' - $r10k_binary = 'r10k' $modulepath = "${r10k_basedir}/\$environment/modules:${pe_module_path}" # webhook - $webhook_user = 'peadmin' - $webhook_pass = 'peadmin' - $webhook_group = 'peadmin' + $webhook_user = 'peadmin' + $webhook_pass = 'peadmin' + $webhook_group = 'peadmin' $webhook_public_key_path = '/var/lib/peadmin/.mcollective.d/peadmin-cert.pem' $webhook_private_key_path = '/var/lib/peadmin/.mcollective.d/peadmin-private.pem' $webhook_certname = 'peadmin' @@ -87,21 +81,18 @@ elsif versioncmp("${::puppetversion}", '4.0.0') >= 0 { #lint:ignore:only_variable_string #FOSS 4 or greater specific settings # r10k configuration - $r10k_config_file = '/etc/puppetlabs/r10k/r10k.yaml' - $puppetconf_path = '/etc/puppetlabs/puppet' $module_path = '/opt/puppetlabs/puppet/code/modules' # Mcollective configuration dynamic $mc_service_name = 'mcollective' $plugins_dir = '/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/mcollective' $modulepath = undef - $r10k_binary = 'r10k' # webhook - $webhook_user = 'puppet' - $webhook_pass = 'puppet' - $webhook_group = 'puppet' + $webhook_user = 'puppet' + $webhook_pass = 'puppet' + $webhook_group = 'puppet' $webhook_public_key_path = undef $webhook_private_key_path = undef $webhook_certname = undef diff --git a/spec/classes/config_spec.rb b/spec/classes/config_spec.rb index c6229281..2f53ef0e 100644 --- a/spec/classes/config_spec.rb +++ b/spec/classes/config_spec.rb @@ -6,7 +6,11 @@ facts end - context 'on Puppet Opensource' do + context 'with defaults' do + it { is_expected.to compile.with_all_deps } + end + + context 'modified file locations and ownership' do let :params do { configfile: '/etc/r10k.yaml', @@ -27,92 +31,28 @@ path: '/etc/r10k.yaml' ) end - it { is_expected.to contain_file('r10k.yaml').without_content(%r{^:postrun: .*$}) } - it { is_expected.not_to contain_ini_setting('R10k Modulepath') } end - describe 'with manage_configfile_symlink' do - context 'set to value true and a configfile specified' do - let :params do - { - manage_configfile_symlink: true, - configfile: '/etc/puppet/r10k.yaml', - cachedir: '/var/cache/r10k', - manage_modulepath: false, - root_user: 'root', - root_group: 'root' - } - end - - it do - is_expected.to contain_file('symlink_r10k.yaml').with( - ensure: 'link', - path: '/etc/r10k.yaml', - target: '/etc/puppet/r10k.yaml' - ) - end - end - - context 'set to value false and a configfile specified' do - let :params do - { - manage_configfile_symlink: false, - configfile: '/etc/puppet/r10k.yaml', - cachedir: '/var/cache/r10k', - manage_modulepath: false, - root_user: 'root', - root_group: 'root' - } - end - - it { is_expected.not_to contain_file('symlink_r10k.yaml') } - end - - context 'set to a non-boolean value' do - let :params do - { - manage_configfile_symlink: 'invalid', - configfile: '/etc/r10k.yaml', - cachedir: '/var/cache/r10k', - manage_modulepath: false, - root_user: 'root', - root_group: 'root' - } - end - - it 'fails' do - expect { catalogue }.to raise_error(Puppet::Error) - end - end - end - - context 'with configfile_symlink specified as a non fully qualified path' do + context 'set to value true and a configfile specified' do let :params do { - manage_configfile_symlink: true, - configfile: '/etc/r10k.yaml', - configfile_symlink: 'invalid/path', - cachedir: '/var/cache/r10k', - manage_modulepath: false, - root_user: 'root', - root_group: 'root' + manage_configfile_symlink: true } end - it 'fails' do - expect { catalogue }.to raise_error(Puppet::Error) + it do + is_expected.to contain_file('symlink_r10k.yaml').with( + ensure: 'link', + path: '/etc/r10k.yaml', + target: '/etc/puppetlabs/r10k/r10k.yaml' + ) end end context 'Managing r10k with rugged turned on via git_settings' do let :params do { - configfile: '/etc/r10k.yaml', - cachedir: '/var/cache/r10k', - manage_modulepath: false, - git_settings: { 'provider' => 'rugged', 'private_key' => '/root/.ssh/id_dsa' }, - root_user: 'root', - root_group: 'root' + git_settings: { 'provider' => 'rugged', 'private_key' => '/root/.ssh/id_dsa' } } end @@ -122,33 +62,26 @@ context 'manage forge settings of r10k via forge_settings' do let :params do { - configfile: '/etc/r10k.yaml', - cachedir: '/var/cache/r10k', - manage_modulepath: false, - forge_settings: { 'proxy' => 'https://proxy.example.com:3128', 'baseurl' => 'https://forgeapi.puppetlabs.com' }, - root_user: 'root', - root_group: 'root' + forge_settings: { 'proxy' => 'https://proxy.example.com:3128', 'baseurl' => 'https://forgeapi.puppetlabs.com' } } end it { is_expected.to contain_file('r10k.yaml').with_content(%r{forge:\n.*baseurl: https:\/\/forgeapi\.puppetlabs\.com\n.*proxy: https:\/\/proxy\.example\.com:3128\n}) } end - describe 'with optional parameter postrun specified' do - context 'with array of system call "/usr/bin/curl -F deploy=done http://my-app.site/endpoint"' do - let :params do - { - configfile: '/etc/r10k.yaml', - cachedir: '/var/cache/r10k', - manage_modulepath: false, - postrun: ['/usr/bin/curl', '-F', 'deploy=done', 'http://my-app.site/endpoint'], - root_user: 'root', - root_group: 'root' - } - end - - it { is_expected.to contain_file('r10k.yaml').with_content(%r{^.*:postrun: \[\"/usr/bin/curl\", \"-F\", \"deploy=done\", \"http://my-app\.site/endpoint\"\]\n.*$}) } + context 'with optional parameter postrun specified with array of system call "/usr/bin/curl -F deploy=done http://my-app.site/endpoint"' do + let :params do + { + configfile: '/etc/r10k.yaml', + cachedir: '/var/cache/r10k', + manage_modulepath: false, + postrun: ['/usr/bin/curl', '-F', 'deploy=done', 'http://my-app.site/endpoint'], + root_user: 'root', + root_group: 'root' + } end + + it { is_expected.to contain_file('r10k.yaml').with_content(%r{^.*:postrun: \[\"/usr/bin/curl\", \"-F\", \"deploy=done\", \"http://my-app\.site/endpoint\"\]\n.*$}) } end end end