Skip to content

Commit

Permalink
Merge pull request #204 from glennsarti/ticket/master/MODULES-4214-ad…
Browse files Browse the repository at this point in the history
…d-install-params

(MODULES-4214) Add additional installation parameters during upgrade
  • Loading branch information
MikaelSmith authored Feb 4, 2017
2 parents ba56ed4 + 458a747 commit c1610f5
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 5 deletions.
8 changes: 8 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ The directory the puppet agent should be installed to. This is only applicable f
install_dir => 'D:\Program Files\Puppet Labs'
```

##### `install_options`

An array of additional options to pass when installing puppet-agent. Each option in the array can either be a string or a hash. Each option will automatically be quoted when passed to the install command. With Windows packages, note that file paths in an install option must use backslashes. (Since install options are passed directly to the installation command, forward slashes won't be automatically converted like they are in `file` resources.) Note also that backslashes in double-quoted strings _must_ be escaped and backslashes in single-quoted strings _can_ be escaped.

``` puppet
install_options => ['PUPPET_AGENT_ACCOUNT_DOMAIN=ExampleCorp','PUPPET_AGENT_ACCOUNT_USER=bob','PUPPET_AGENT_ACCOUNT_PASSWORD=password']
```

##### `msi_move_locked_files`

This is only applicable for Windows operating systems. There may be instances where file locks cause unncessary service restarts. By setting to true, the module will move files prior to installation that are known to cause file locks. By default this is set to false.
Expand Down
10 changes: 10 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
# The directory the puppet agent should be installed to. This is only applicable for
# windows operating systems. This only applies when upgrading the agent to a new
# version; it will not cause re-installation of the same version to a new location.
# [install_options]
# An array of additional options to pass when installing puppet-agent. Each option in
# the array can either be a string or a hash. Each option will automatically be quoted
# when passed to the install command. With Windows packages, note that file paths in an
# install option must use backslashes. (Since install options are passed directly to
# the installation command, forward slashes won't be automatically converted like they
# are in `file` resources.) Note also that backslashes in double-quoted strings _must_
# be escaped and backslashes in single-quoted strings _can_ be escaped.
# [msi_move_locked_files]
# This is only applicable for Windows operating systems. There may be instances where
# file locks cause unncessary service restarts. By setting to true, the module
Expand All @@ -51,6 +59,7 @@
$source = $::puppet_agent::params::_source,
$install_dir = $::puppet_agent::params::install_dir,
$disable_proxy = false,
$install_options = $::puppet_agent::params::install_options,
$msi_move_locked_files = false,
) inherits ::puppet_agent::params {

Expand Down Expand Up @@ -140,6 +149,7 @@
package_file_name => $_package_file_name,
package_version => $_package_version,
install_dir => $install_dir,
install_options => $install_options,
}

contain '::puppet_agent::prepare'
Expand Down
12 changes: 10 additions & 2 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
$package_file_name = undef,
$package_version = 'present',
$install_dir = undef,
$install_options = [],
) {
assert_private()

Expand All @@ -35,6 +36,7 @@
$_package_options = {
provider => 'rpm',
source => "/opt/puppetlabs/packages/${package_file_name}",
install_options => $install_options,
}
} elsif $::operatingsystem == 'Solaris' and $::operatingsystemmajrelease == '10' {
contain puppet_agent::install::remove_packages
Expand All @@ -44,7 +46,7 @@
adminfile => '/opt/puppetlabs/packages/solaris-noask',
source => "/opt/puppetlabs/packages/${_unzipped_package_name}",
require => Class['puppet_agent::install::remove_packages'],
install_options => '-G',
install_options => concat(['-G'],$install_options),
}
} elsif $::operatingsystem == 'Solaris' and $::operatingsystemmajrelease == '11' and $old_packages {
# Updating from PE 3.x requires removing all the old packages before installing the puppet-agent package.
Expand All @@ -66,16 +68,20 @@
$_package_options = {
require => Exec['puppet_agent restore /etc/puppetlabs'],
notify => Exec['puppet_agent post-install restore /etc/puppetlabs'],
install_options => $install_options,
}
} elsif $::operatingsystem == 'Darwin' and $::macosx_productversion_major =~ /10\.[9,10,11]/ {
contain puppet_agent::install::remove_packages

$_package_options = {
source => "/opt/puppetlabs/packages/${package_file_name}",
require => Class['puppet_agent::install::remove_packages'],
install_options => $install_options,
}
} else {
$_package_options = {}
$_package_options = {
install_options => $install_options,
}
}

if $::osfamily == 'windows' {
Expand All @@ -88,12 +94,14 @@
source => $local_package_file_path,
install_dir => $install_dir,
require => File[$local_package_file_path],
install_options => $install_options,
}
} else {
class { 'puppet_agent::windows::install':
package_file_name => $package_file_name,
source => $::puppet_agent::source,
install_dir => $install_dir,
install_options => $install_options,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

$package_name = 'puppet-agent'
$install_dir = undef
$install_options = []

case $::osfamily {
'RedHat', 'Debian', 'Suse', 'Solaris', 'Darwin', 'AIX': {
Expand Down
1 change: 1 addition & 0 deletions manifests/windows/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
$package_file_name,
$source = $::puppet_agent::source,
$install_dir = undef,
$install_options = [],
$msi_move_locked_files = $::puppet_agent::msi_move_locked_files,
) {
assert_private()
Expand Down
4 changes: 2 additions & 2 deletions spec/classes/puppet_agent_osfamily_solaris_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@
is_expected.to contain_package('puppet-agent').with_adminfile('/opt/puppetlabs/packages/solaris-noask')
is_expected.to contain_package('puppet-agent').with_ensure('present')
is_expected.to contain_package('puppet-agent').with_source("/opt/puppetlabs/packages/puppet-agent-#{package_version}-1.i386.pkg")
is_expected.to contain_package('puppet-agent').with_install_options('-G')
is_expected.to contain_package('puppet-agent').with_install_options( ['-G'] )
end
end

Expand Down Expand Up @@ -450,7 +450,7 @@
is_expected.to contain_package('puppet-agent').with_adminfile('/opt/puppetlabs/packages/solaris-noask')
is_expected.to contain_package('puppet-agent').with_ensure('present')
is_expected.to contain_package('puppet-agent').with_source("/opt/puppetlabs/packages/puppet-agent-#{package_version}-1.sparc.pkg")
is_expected.to contain_package('puppet-agent').with_install_options('-G')
is_expected.to contain_package('puppet-agent').with_install_options( ['-G'] )
end
end
end
Expand Down
15 changes: 15 additions & 0 deletions spec/classes/puppet_agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,21 @@ def global_facts(facts, os)
end
end

[{}, {:service_names => []}].each do |params|
context "puppet_agent class with install_options" do
let(:params) { global_params.merge(
{:install_options => ['OPTION1=value1','OPTION2=value2'],})
}

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('puppet_agent::install').with_install_options(['OPTION1=value1','OPTION2=value2']) }

# Note this should fail on Windows, but it doesn't get tested due to https://github.com/mcanevet/rspec-puppet-facts/issues/42
# Windows is not seen as a supported OS when `on_supported_os` is used :-(
it { is_expected.to contain_package('puppet-agent').with_install_options(['OPTION1=value1','OPTION2=value2']) }
end
end

[{}, {:service_names => []}].each do |params|
context "puppet_agent class without any parameters" do
let(:params) { params.merge(global_params) }
Expand Down
11 changes: 11 additions & 0 deletions spec/classes/puppet_agent_windows_install_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@
end
end

context 'install_options =>' do
describe 'OPTION1=value1 OPTION2=value2' do
let(:params) { global_params.merge(
{: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/)
}
end
end

context 'source =>' do
describe 'https://alterernate.com/puppet-agent.msi' do
let(:params) { global_params.merge(
Expand Down
2 changes: 1 addition & 1 deletion templates/install_puppet.bat.erb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ IF EXIST "%PUPPETRES%" (
)
<% end %>

start /wait msiexec.exe /qn /norestart /i "<%= @_msi_location %>" /l*vx "<%= @_logfile %>" PUPPET_MASTER_SERVER="<%= @_puppet_master %>" PUPPET_AGENT_ENVIRONMENT="%environment%" <% unless @install_dir.to_s.empty? -%>INSTALLDIR="<%= @install_dir %>"<% end -%> <% unless @_agent_startup_mode.to_s.empty? -%>PUPPET_AGENT_STARTUP_MODE="<%= @_agent_startup_mode %>"<% end -%>
start /wait msiexec.exe /qn /norestart /i "<%= @_msi_location %>" /l*vx "<%= @_logfile %>" PUPPET_MASTER_SERVER="<%= @_puppet_master %>" PUPPET_AGENT_ENVIRONMENT="%environment%" <% unless @install_dir.to_s.empty? -%>INSTALLDIR="<%= @install_dir %>"<% end -%> <% unless @_agent_startup_mode.to_s.empty? -%>PUPPET_AGENT_STARTUP_MODE="<%= @_agent_startup_mode %>"<% end -%><% unless @install_options.to_s.empty? -%><% @install_options.each do |option| -%> <%= option%><% end -%><% end -%>

:End

Expand Down

0 comments on commit c1610f5

Please sign in to comment.