diff --git a/lib/facter/puppet_runmode.rb b/lib/facter/puppet_runmode.rb new file mode 100644 index 00000000..7b5ed57c --- /dev/null +++ b/lib/facter/puppet_runmode.rb @@ -0,0 +1,3 @@ +Facter.add(:puppet_runmode) do + setcode { Puppet.run_mode.name.to_s } +end diff --git a/manifests/init.pp b/manifests/init.pp index a73a2740..f3ba4c56 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -131,7 +131,7 @@ Optional $wait_for_pxp_agent_exit = undef, Optional $wait_for_puppet_run = undef, Array[Puppet_agent::Config] $config = [], - String $version_file_path = $facts['os']['family'] ? { 'windows' => "${facts['env_windows_installdir']}\\VERSION", default => '/opt/puppetlabs/puppet/VERSION' } + String $version_file_path = '/opt/puppetlabs/puppet/VERSION' ) inherits puppet_agent::params { # The configure class uses $puppet_agent::config to manage settings in # puppet.conf, and will always be present. It does not require management of @@ -167,6 +167,9 @@ # The AIO package version and Puppet version can, on rare occasion, diverge. # This logic checks for the AIO version of the server, since that's what the package manager cares about. if $package_version == 'auto' { + if $facts['os']['family'] == 'windows' and $facts['puppet_runmode'] == 'user' { + $version_file_path = "${facts['env_windows_installdir']}\\VERSION" + } $master_or_package_version = chomp(file($version_file_path)) } else { $master_or_package_version = $package_version diff --git a/spec/classes/puppet_agent_osfamily_redhat_spec.rb b/spec/classes/puppet_agent_osfamily_redhat_spec.rb index b92104bc..e2fb40b4 100644 --- a/spec/classes/puppet_agent_osfamily_redhat_spec.rb +++ b/spec/classes/puppet_agent_osfamily_redhat_spec.rb @@ -274,6 +274,36 @@ it { is_expected.to contain_package('puppet-agent').with_ensure(params[:package_version].to_s) } end + context 'with auto package version' do + let(:params) do + { + manage_repo: false, + package_version: 'auto' + } + end + + context 'with Windows agent' do + let(:facts) do + override_facts(super(), + os: { family: 'windows', 'windows' => { 'system32' => 'C:\Windows\System32' } }, + 'env_windows_installdir' => 'C:\Program Files\Puppet Labs\Puppet', + 'puppet_agent_appdata' => 'C:\ProgramData', + 'puppet_confdir' => 'C:\ProgramData\PuppetLabs\puppet', + 'puppet_runmode' => 'agent' + ) + end + + before :each do + allow(Puppet::FileSystem).to receive(:exist?).and_call_original + allow(Puppet::FileSystem).to receive(:read_preserve_line_endings).and_call_original + allow(Puppet::FileSystem).to receive(:exist?).with('/opt/puppetlabs/puppet/VERSION').and_return true + allow(Puppet::FileSystem).to receive(:read_preserve_line_endings).with('/opt/puppetlabs/puppet/VERSION').and_return "7.6.5\n" + end + + it { is_expected.to contain_class('puppet_agent::install::windows') } + end + end + it { is_expected.to contain_class('puppet_agent::osfamily::redhat') } end