Skip to content

Commit

Permalink
(MODULES-8431) Update windows installation to use powershell
Browse files Browse the repository at this point in the history
This commit updates the installation method on windows to use a powershell
script rather than a batch file
  • Loading branch information
Sean P. McDonald committed Jan 11, 2019
1 parent fb40923 commit 75c9fbb
Show file tree
Hide file tree
Showing 3 changed files with 239 additions and 82 deletions.
37 changes: 20 additions & 17 deletions manifests/windows/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,27 @@
$_https_source = "https://downloads.puppetlabs.com/windows/${dir}${package_file_name}"
}

$_install_options = $install_options ? {
[] => ['REINSTALLMODE="amus"'],
default => $install_options
}
$_installps1 = windows_native_path("${::env_temp_variable}/install_puppet.ps1")

$_source = $source ? {
undef => $_https_source,
/^[a-zA-Z]:/ => windows_native_path($source),
default => $source,
}

$_msi_location = $_source ? {
/^puppet:/ => windows_native_path("${::env_temp_variable}/puppet-agent.msi"),
default => $_source,
}

$_installbat = windows_native_path("${::env_temp_variable}/install_puppet.bat")
if $_source =~ /^puppet:/ {
file{ $_msi_location:
source => $_source,
before => File["${_installbat}"],
before => File["${_installps1}"],
}
}

$_cmd_location = $::rubyplatform ? {
/i386/ => 'C:\\Windows\\system32\\cmd.exe',
default => "${::system32}\\cmd.exe"
$_install_options = $install_options ? {
[] => ['REINSTALLMODE="amus"'],
default => $install_options,
}

if (member($::puppet_agent::service_names, 'puppet')) {
Expand All @@ -62,24 +56,33 @@
$_agent_startup_mode = undef
}

if $msi_move_locked_files {
$_move_dll_workaround = '$true'
} else {
$_move_dll_workaround = '$false'
}

$_timestamp = strftime('%Y_%m_%d-%H_%M')
$_logfile = windows_native_path("${::env_temp_variable}/puppet-${_timestamp}-installer.log")
$_puppet_master = $::puppet_master_server
$_install_pid_file_loc = windows_native_path("${::env_temp_variable}/puppet_agent_install.pid")

notice ("Puppet upgrade log file at ${_logfile}")
debug ("Installing puppet from ${_msi_location}")
file { "${_installbat}":

file { "${_installps1}":
ensure => file,
content => template('puppet_agent/install_puppet.bat.erb')
content => template('puppet_agent/install_puppet.ps1.erb')
}
-> exec { 'install_puppet.bat':
command => "${::system32}\\cmd.exe /c start /b ${_cmd_location} /c \"${_installbat}\" ${::puppet_agent_pid}",
path => $::path,
-> exec { 'install_puppet.ps1':
command => "${::system32}\\cmd.exe /c start /b ${::system32}\\WindowsPowerShell\\v1.0\\powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -NonInteractive -Command ${_installps1} ${::puppet_agent_pid}",
path => $::path,
}

# PUP-5480/PE-15037 Cache dir loses inheritable SYSTEM perms
exec { 'fix inheritable SYSTEM perms':
command => "${::system32}\\icacls.exe \"${::puppet_client_datadir}\" /grant \"SYSTEM:(OI)(CI)(F)\"",
unless => "${::system32}\\icacls.exe \"${::puppet_client_datadir}\" | findstr \"SYSTEM:(OI)(CI)(F)\"",
require => Exec['install_puppet.bat'],
require => Exec['install_puppet.ps1'],
}
}
99 changes: 34 additions & 65 deletions spec/classes/puppet_agent_windows_install_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RSpec.describe 'puppet_agent' do
package_version = '1.2.1.1'
global_params = {
:package_version => package_version
:package_version => package_version,
}

{'5.1' => {:expect_arch => 'x86', :appdata => 'C:\Document and Settings\All Users\Application Data'},
Expand Down Expand Up @@ -44,26 +44,14 @@

let(:facts) { facts.merge({:is_pe => true}) }

if Puppet.version < '4.0.0'
context 'with aio_agent_version unset' do
let(:facts) { facts.merge({:is_pe => true}) }

it { is_expected.to contain_class('puppet_agent::windows::install') }
it { is_expected.to contain_file('C:\tmp\install_puppet.bat').with_content(
%r[#{Regexp.escape("msiexec.exe /qn /norestart /i \"#{values[:appdata]}\\Puppetlabs\\packages\\puppet-agent-#{values[:expect_arch]}.msi\"")}])
}
it { is_expected.to contain_exec('fix inheritable SYSTEM perms') }
end
end

if Puppet.version >= '4.0.0'
context 'with up to date aio_agent_version matching server' do
let(:facts) { facts.merge({
:is_pe => true,
:aio_agent_version => package_version
})}

it { is_expected.not_to contain_file('c:\tmp\install_puppet.bat') }
it { is_expected.not_to contain_file('c:\tmp\install_puppet.ps1') }
it { is_expected.not_to contain_exec('fix inheritable SYSTEM perms') }
end

Expand All @@ -77,8 +65,8 @@
global_params.merge(:package_version => "#{package_version}.g886c5ab")
}

it { is_expected.not_to contain_file('c:\tmp\install_puppet.bat') }
it { is_expected.not_to contain_exec('install_puppet.bat') }
it { is_expected.not_to contain_file('c:\tmp\install_puppet.ps1') }
it { is_expected.not_to contain_exec('install_puppet.ps1') }
end

context 'with out of date aio_agent_version' do
Expand All @@ -88,8 +76,8 @@
})}

it { is_expected.to contain_class('puppet_agent::windows::install') }
it { is_expected.to contain_file('C:\tmp\install_puppet.bat').with_content(
%r[#{Regexp.escape("msiexec.exe /qn /norestart /i \"#{values[:appdata]}\\Puppetlabs\\packages\\puppet-agent-#{values[:expect_arch]}.msi\"")}])
it { is_expected.to contain_file('C:\tmp\install_puppet.ps1').with_content(
%r[#{Regexp.escape("\$Source=\'#{values[:appdata]}\\Puppetlabs\\packages\\puppet-agent-#{values[:expect_arch]}.msi\'")}])
}
it { is_expected.to contain_exec('fix inheritable SYSTEM perms') }
end
Expand All @@ -102,18 +90,18 @@
{:install_options => ['OPTION1=value1','OPTION2=value2'],})
}
it {
is_expected.to contain_file('C:\tmp\install_puppet.bat').with_content(/msiexec.exe .+ OPTION1=value1 OPTION2=value2/)
is_expected.to contain_file('C:\tmp\install_puppet.ps1').with_content(/\$InstallArgs='OPTION1=value1 OPTION2=value2'/)
}
it {
is_expected.not_to contain_file('C:\tmp\install_puppet.bat').with_content(/msiexec.exe .+ REINSTALLMODE="amus"/)
is_expected.not_to contain_file('C:\tmp\install_puppet.ps1').with_content(/\$InstallArgs='REINSTALLMODE="amus"'/)
}
end
end

context 'Default INSTALLMODE Option' do
describe 'REINSTALLMODE=amus' do
it {
is_expected.to contain_file('C:\tmp\install_puppet.bat').with_content(/msiexec.exe .+ REINSTALLMODE="amus"/)
is_expected.to contain_file('C:\tmp\install_puppet.ps1').with_content(/\$InstallArgs='REINSTALLMODE="amus"'/)
}
end
end
Expand All @@ -124,9 +112,8 @@
{:source => 'https://alternate.com/puppet-agent.msi',})
}
it {
is_expected.to contain_file('C:\tmp\install_puppet.bat').with_content(
/msiexec.exe \/qn \/norestart \/i "https:\/\/alternate.com\/puppet-agent.msi"/)
is_expected.to contain_file('C:\tmp\install_puppet.bat').with_content(/\/l\*vx "C:\\tmp\\puppet-\d+_\d+_\d+-\d+_\d+-installer.log"/)
is_expected.to contain_file('C:\tmp\install_puppet.ps1').with_content(/\$Source='https:\/\/alternate.com\/puppet-agent.msi'/)
is_expected.to contain_file('C:\tmp\install_puppet.ps1').with_content(/\$Logfile='C:\\tmp\\puppet-\d+_\d+_\d+-\d+_\d+-installer.log'/)
}
it { is_expected.to contain_exec('fix inheritable SYSTEM perms') }
end
Expand All @@ -135,9 +122,8 @@
{:source => 'C:/tmp/puppet-agent-x64.msi',})
}
it {
is_expected.to contain_file('C:\tmp\install_puppet.bat').with_content(
/msiexec.exe \/qn \/norestart \/i "C:\\tmp\\puppet-agent-x64\.msi"/)
is_expected.to contain_file('C:\tmp\install_puppet.bat').with_content(/\/l\*vx "C:\\tmp\\puppet-\d+_\d+_\d+-\d+_\d+-installer.log"/)
is_expected.to contain_file('C:\tmp\install_puppet.ps1').with_content(/\$Source='C:\\tmp\\puppet-agent-x64\.msi'/)
is_expected.to contain_file('C:\tmp\install_puppet.ps1').with_content(/\$Logfile='C:\\tmp\\puppet-\d+_\d+_\d+-\d+_\d+-installer.log'/)
}
it { is_expected.to contain_exec('fix inheritable SYSTEM perms') }
end
Expand All @@ -146,20 +132,8 @@
{:source => 'C:\Temp/ Folder\puppet-agent-x64.msi',})
}
it {
is_expected.to contain_file('C:\tmp\install_puppet.bat').with_content(
/msiexec.exe \/qn \/norestart \/i "C:\\Temp Folder\\puppet-agent-x64\.msi"/)
is_expected.to contain_file('C:\tmp\install_puppet.bat').with_content(/\/l\*vx "C:\\tmp\\puppet-\d+_\d+_\d+-\d+_\d+-installer.log"/)
}
it { is_expected.to contain_exec('fix inheritable SYSTEM perms') }
end
describe 'C:/Temp/ Folder/puppet-agent-x64.msi' do
let(:params) { global_params.merge(
{:source => 'C:/Temp/ Folder/puppet-agent-x64.msi',})
}
it {
is_expected.to contain_file('C:\tmp\install_puppet.bat').with_content(
/msiexec.exe \/qn \/norestart \/i "C:\\Temp Folder\\puppet-agent-x64\.msi"/)
is_expected.to contain_file('C:\tmp\install_puppet.bat').with_content(/\/l\*vx "C:\\tmp\\puppet-\d+_\d+_\d+-\d+_\d+-installer.log"/)
is_expected.to contain_file('C:\tmp\install_puppet.ps1').with_content(/\$Source='C:\\Temp Folder\\puppet-agent-x64\.msi'/)
is_expected.to contain_file('C:\tmp\install_puppet.ps1').with_content(/\$Logfile='C:\\tmp\\puppet-\d+_\d+_\d+-\d+_\d+-installer.log'/)
}
it { is_expected.to contain_exec('fix inheritable SYSTEM perms') }
end
Expand All @@ -168,21 +142,19 @@
{:source => "\\\\garded\\c$\\puppet-agent-x64.msi",})
}
it {
is_expected.to contain_file('C:\tmp\install_puppet.bat').with_content(
/msiexec.exe \/qn \/norestart \/i "\\\\garded\\c\$\\puppet-agent-x64\.msi"/)
is_expected.to contain_file('C:\tmp\install_puppet.bat').with_content(/\/l\*vx "C:\\tmp\\puppet-\d+_\d+_\d+-\d+_\d+-installer.log"/)
is_expected.to contain_file('C:\tmp\install_puppet.ps1').with_content(/\$Source='\\\\garded\\c\$\\puppet-agent-x64\.msi'/)
is_expected.to contain_file('C:\tmp\install_puppet.ps1').with_content(/\$Logfile='C:\\tmp\\puppet-\d+_\d+_\d+-\d+_\d+-installer.log'/)
}
it { is_expected.to contain_exec('fix inheritable SYSTEM perms') }
end
describe 'default source' do
it {
is_expected.to contain_file('C:\tmp\install_puppet.bat').with_content(
/msiexec.exe \/qn \/norestart \/i "https:\/\/downloads.puppetlabs.com\/windows\/puppet-agent-#{package_version}-#{values[:expect_arch]}\.msi"/)
is_expected.to contain_file('C:\tmp\install_puppet.bat').with_content(/\/l\*vx "C:\\tmp\\puppet-\d+_\d+_\d+-\d+_\d+-installer\.log"/)
is_expected.to contain_file('C:\tmp\install_puppet.ps1').with_content(/\$Source='https:\/\/downloads.puppetlabs.com\/windows\/puppet-agent-#{package_version}-#{values[:expect_arch]}\.msi'/)
is_expected.to contain_file('C:\tmp\install_puppet.ps1').with_content(/\$Logfile='C:\\tmp\\puppet-\d+_\d+_\d+-\d+_\d+-installer.log'/)
}
it {
should contain_exec('install_puppet.bat').with { {
'command' => 'C:\windows\sysnative\cmd.exe /c start /b "C:\tmp\install_puppet.bat" 42',
should contain_exec('install_puppet.ps1').with { {
'command' => 'C:\windows\sysnative\cmd.exe /c start /b C:\windows\sysnative\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -NonInteractive -Command C:\tmp\install_puppet.ps1 42',
} }
}
it {
Expand All @@ -195,10 +167,8 @@
{:source => 'puppet:///puppet_agent/puppet-agent-1.1.0-x86.msi'})
}
it {
is_expected.to contain_file('C:\tmp\puppet-agent.msi').with_before('File[C:\tmp\install_puppet.bat]')
is_expected.to contain_file('C:\tmp\install_puppet.bat').with_content(
/msiexec.exe \/qn \/norestart \/i "C:\\tmp\\puppet-agent.msi"/
)
is_expected.to contain_file('C:\tmp\puppet-agent.msi').with_before('File[C:\tmp\install_puppet.ps1]')
is_expected.to contain_file('C:\tmp\install_puppet.ps1').with_content(/\$Source='C:\\tmp\\puppet-agent.msi'/)
}
it { is_expected.to contain_exec('fix inheritable SYSTEM perms') }
end
Expand All @@ -209,8 +179,7 @@
{:arch => 'x86'})
}
it {
is_expected.to contain_file('C:\tmp\install_puppet.bat').with_content(
/msiexec.exe \/qn \/norestart \/i "https:\/\/downloads.puppetlabs.com\/windows\/puppet-agent-#{package_version}-x86.msi"/
is_expected.to contain_file('C:\tmp\install_puppet.ps1').with_content(/\$Source='https:\/\/downloads.puppetlabs.com\/windows\/puppet-agent-#{package_version}-x86.msi'/
)
}
end
Expand All @@ -236,24 +205,24 @@
context 'msi_move_locked_files =>' do
describe 'default' do
it {
is_expected.to contain_file('C:\tmp\install_puppet.bat').without_content(/Move puppetres\.dll/)
}
is_expected.to contain_file('C:\tmp\install_puppet.ps1').with_content(/\$UseLockedFilesWorkaround=\$false/)
}
end
describe 'specify false' do
let(:params) { global_params.merge(
{:msi_move_locked_files => false,})
}
it {
is_expected.to contain_file('C:\tmp\install_puppet.bat').without_content(/Move puppetres\.dll/)
}
is_expected.to contain_file('C:\tmp\install_puppet.ps1').with_content(/\$UseLockedFilesWorkaround=\$false/)
}
end
describe 'specify true' do
let(:params) { global_params.merge(
{:msi_move_locked_files => true,})
}
it {
is_expected.to contain_file('C:\tmp\install_puppet.bat').with_content(/Move puppetres\.dll/)
}
is_expected.to contain_file('C:\tmp\install_puppet.ps1').with_content(/\$UseLockedFilesWorkaround=\$true/)
}
end
end
end
Expand All @@ -274,8 +243,8 @@
let(:facts) { facts.merge({:rubyplatform => 'i386-ming32'}) }
let(:params) { global_params }
it {
is_expected.to contain_exec('install_puppet.bat').with { {
'command' => 'C:\windows\sysnative\cmd.exe /c start /b C:\windows\system32\cmd.exe /c "C:\tmp\install_puppet.bat" 42',
is_expected.to contain_exec('install_puppet.ps1').with { {
'command' => 'C:\windows\sysnative\cmd.exe /c start /b C:\windows\system32\cmd.exe /c "C:\tmp\install_puppet.ps1" 42',
} }

}
Expand All @@ -285,8 +254,8 @@
let(:facts) { facts.merge({:rubyplatform => 'x86_64'}) }
let(:params) { global_params }
it {
is_expected.to contain_exec('install_puppet.bat').with { {
'command' => 'C:\windows\sysnative\cmd.exe /c start /b C:\windows\sysnative\cmd.exe /c "C:\tmp\install_puppet.bat" 42',
is_expected.to contain_exec('install_puppet.ps1').with { {
'command' => 'C:\windows\sysnative\cmd.exe /c start /b C:\windows\sysnative\cmd.exe /c "C:\tmp\install_puppet.ps1" 42',
} }

}
Expand Down
Loading

0 comments on commit 75c9fbb

Please sign in to comment.