diff --git a/data/common.yaml b/data/common.yaml new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/data/common.yaml @@ -0,0 +1 @@ +--- diff --git a/data/kernel/Linux.yaml b/data/kernel/Linux.yaml new file mode 100644 index 00000000..8738d11d --- /dev/null +++ b/data/kernel/Linux.yaml @@ -0,0 +1,2 @@ +--- +os_patching::puppet_binary_dir: '/opt/puppetlabs/bin' diff --git a/data/kernel/windows.yaml b/data/kernel/windows.yaml new file mode 100644 index 00000000..53eb02d1 --- /dev/null +++ b/data/kernel/windows.yaml @@ -0,0 +1,2 @@ +--- +os_patching::puppet_binary_dir: 'C:/Program Files/Puppet Labs/Puppet/bin' diff --git a/hiera.yaml b/hiera.yaml new file mode 100644 index 00000000..5566a5af --- /dev/null +++ b/hiera.yaml @@ -0,0 +1,13 @@ +--- +version: 5 + +defaults: + datadir: 'data' + data_hash: 'yaml_data' + +hierarchy: + - name: 'System kernel' + path: 'kernel/%{facts.kernel}.yaml' + + - name: 'common' + path: 'common.yaml' diff --git a/manifests/init.pp b/manifests/init.pp index 8dfcb970..faf1574e 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,6 +1,9 @@ # @summary This manifest sets up a script and cron job to populate # the `os_patching` fact. # +# @param puppet_binary_dir [String] +# Location of the Puppet binaries +# # @param patch_data_owner [String] # User name for the owner of the patch data # @@ -130,6 +133,7 @@ # ensure => absent, # } class os_patching ( + String $puppet_binary_dir, String $patch_data_owner = 'root', String $patch_data_group = 'root', String $patch_cron_user = $patch_data_owner, @@ -175,7 +179,7 @@ } } 'windows': { - $fact_upload_cmd = '"C:/Program Files/Puppet Labs/Puppet/bin/puppet.bat" facts upload' + $fact_upload_cmd = "\"${puppet_binary_dir}/puppet.bat\" facts upload" $cache_dir = 'C:/ProgramData/os_patching' $fact_dir = $cache_dir $fact_file = 'os_patching_fact_generation.ps1' diff --git a/spec/classes/os_patching_spec.rb b/spec/classes/os_patching_spec.rb index d394c2f5..80977c72 100644 --- a/spec/classes/os_patching_spec.rb +++ b/spec/classes/os_patching_spec.rb @@ -9,9 +9,45 @@ when 'Linux' let(:cache_dir) { '/var/cache/os_patching' } let(:fact_cmd) { '/usr/local/bin/os_patching_fact_generation.sh' } + + context 'default installation path for Puppet' do + it { + is_expected.to contain_exec('os_patching::exec::fact_upload').with( + 'command' => '/opt/puppetlabs/bin/puppet facts upload', + ) + } + end + + context 'alternate installation path for Puppet' do + let(:params) { {'puppet_binary_dir' => '/usr/local/bin' } } + + it { + is_expected.to contain_exec('os_patching::exec::fact_upload').with( + 'command' => '/usr/local/bin/puppet facts upload', + ) + } + end when 'windows' let(:cache_dir) { 'C:/ProgramData/os_patching' } let(:fact_cmd) { 'C:/ProgramData/os_patching/os_patching_fact_generation.ps1' } + + context 'default installation path for Puppet' do + it { + is_expected.to contain_exec('os_patching::exec::fact_upload').with( + 'command' => '"C:/Program Files/Puppet Labs/Puppet/bin/puppet.bat" facts upload', + ) + } + end + + context 'alternate installation path for Puppet' do + let(:params) { {'puppet_binary_dir' => 'D:/Program Files/Puppet Labs/Puppet/bin' } } + + it { + is_expected.to contain_exec('os_patching::exec::fact_upload').with( + 'command' => '"D:/Program Files/Puppet Labs/Puppet/bin/puppet.bat" facts upload', + ) + } + end end case os_facts[:osfamily]