2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ before_install:
matrix:
fast_finish: true
include:
- rvm: 2.5.3
env: CHECK="commits"
- rvm: 2.5.3
env: CHECK="validate lint spec"
- rvm: 2.5.3
Expand Down
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
# Change Log
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
## [2.2.1] - 2019-10-21

### Summary
Support for Debian 10, Linux Mint, Amazon Linux 2. Stop puppet agent service after install. Puppet_agent task as a plugin.

### Features
- Debian 10 amd64 support
- Linux Mint Support
- Amazon Linux 2 support ([MODULES-9981](https://tickets.puppetlabs.com/browse/MODULES-9981))
- Update facts module used for testing install task ([MODULES-9698](https://tickets.puppetlabs.com/browse/MODULES-9698))
- Add option to stop the puppet agent service after install ([GH-1204](https://tickets.puppetlabs.com/browse/GH-1204))
- Added task to check commit messages
- Make the puppet_agent task available as a plugin

### Bug fixes
- Failed puppet agent upgrade prevents future upgrading because of locked .pid file ([MODULES-9497](https://tickets.puppetlabs.com/browse/MODULES-9497)
- Update bash implementation metadata to require facts implementation
- Add bolt team as codeowners
- Cached Catalog on Windows not idempotent ([MODULES-9846](https://tickets.puppetlabs.com/browse/MODULES-9846))
- Fix failing tests due to rspec changes

## [2.2.0] - 2019-08-05

### Summary
Expand Down
2 changes: 2 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
* @puppetlabs/night-s-watch
/tasks @puppetlabs/bolt
/task_spec @puppetlabs/bolt
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ detected>"}`. If a version cannot be found, returns `{"version": null}`.

#### `puppet_agent::install`

Installs the puppet-agent package. Currently only supports Linux variants: Debian, Ubuntu, SLES, RHEL/CentOS/Fedora. A specific
Installs the puppet-agent package. Currently only supports Linux variants: Debian, Ubuntu, SLES, RHEL/CentOS/Fedora, Amazon Linux 2. A specific
package `version` can be specified; if not, will install or upgrade to the latest Puppet 5 version available.

**Note**: The `puppet_agent::install_shell` task requires the `facts::bash` implementation from the [facts](https://forge.puppet.com/puppetlabs/facts) module. Both the `puppet_agent` and `facts` modules are packaged with Bolt. For use outside of Bolt make sure the `facts` module is installed to the same `modules` directory as `puppet_agent`.
Expand Down
30 changes: 30 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,33 @@ task :gen_nodeset do
end
puts nodeset
end

desc "verify that commit messages match CONTRIBUTING.md requirements"
task(:commits) do
# This rake task looks at the summary from every commit from this branch not
# in the branch targeted for a PR. This is accomplished by using the
# TRAVIS_COMMIT_RANGE environment variable, which is present in travis CI and
# populated with the range of commits the PR contains. If not available, this
# falls back to `master..HEAD` as a next best bet as `master` is unlikely to
# ever be absent.
commit_range = ENV['TRAVIS_COMMIT_RANGE'].nil? ? 'master..HEAD' : ENV['TRAVIS_COMMIT_RANGE'].sub(/\.\.\./, '..')
puts "Checking commits #{commit_range}"
%x{git log --no-merges --pretty=%s #{commit_range}}.each_line do |commit_summary|
# This regex tests for the currently supported commit summary tokens.
# The exception tries to explain it in more full.
if /^\((maint|packaging|doc|docs|modules-\d+)\)|revert/i.match(commit_summary).nil?
raise "\n\n\n\tThis commit summary didn't match CONTRIBUTING.md guidelines:\n" \
"\n\t\t#{commit_summary}\n" \
"\tThe commit summary (i.e. the first line of the commit message) should start with one of:\n" \
"\t\t(MODULES-<digits>) # this is most common and should be a ticket at tickets.puppet.com\n" \
"\t\t(docs)\n" \
"\t\t(docs)(DOCUMENT-<digits>)\n" \
"\t\t(packaging)\n"
"\t\t(maint)\n" \
"\n\tThis test for the commit summary is case-insensitive.\n\n\n"
else
puts "#{commit_summary}"
end
puts "...passed"
end
end
6 changes: 6 additions & 0 deletions bolt_plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"hooks": {
"puppet_library": { "task": "puppet_agent::install" }
},
"config": { }
}
11 changes: 9 additions & 2 deletions files/install_puppet.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,15 @@ function Script:Lock-Installation {
begin {
Write-Log "Locking installation"
if (Test-Path $install_pid_lock) {
Write-Log "Another process has control of $install_pid_lock! Cannot lock, exiting..."
throw
# if the PID found in $install_pid_lock file is not running, this means
# the installation can take control of the file, and assign the new running PID
if((Get-Process -Id (Get-Content $install_pid_lock) -ErrorAction SilentlyContinue) -eq $null){
Write-Log "Process with PID found in $install_pid_lock is no longer running! Continuing installation and assigning new PID!"
$PID | Out-File -FilePath $install_pid_lock
}else{
Write-Log "Another process has control of $install_pid_lock! Cannot lock, exiting..."
throw
}
} else {
$PID | Out-File -NoClobber -FilePath $install_pid_lock
}
Expand Down
10 changes: 10 additions & 0 deletions manifests/install/windows.pp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@
-PuppetStartType '${_agent_startup_mode}' \
-InstallArgs '${_install_options}' \
${_move_dll_workaround}",
unless => "${::system32}\\WindowsPowerShell\\v1.0\\powershell.exe \
-ExecutionPolicy Bypass \
-NoProfile \
-NoLogo \
-NonInteractive \
-Command {\$CurrentVersion = [string](facter.bat -p aio_agent_version); \
if (\$CurrentVersion -eq '${puppet_agent::_expected_package_version}') { \
exit 0; \
} \
exit 1; }.Invoke()",
path => $::path,
require => [
Puppet_agent_upgrade_error['puppet_agent_upgrade_failure.log'],
Expand Down
7 changes: 4 additions & 3 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "puppetlabs-puppet_agent",
"version": "2.2.0",
"version": "2.2.1",
"author": "puppetlabs",
"summary": "Upgrades All-In-One Puppet Agents",
"license": "Apache-2.0",
Expand Down Expand Up @@ -53,7 +53,8 @@
"operatingsystem": "Debian",
"operatingsystemrelease": [
"8",
"9"
"9",
"10"
]
},
{
Expand Down Expand Up @@ -117,7 +118,7 @@
],
"dependencies": [
{"name":"puppetlabs-stdlib","version_requirement":">= 5.1.0 < 7.0.0"},
{"name":"puppetlabs-inifile","version_requirement":">= 2.4.0 <= 3.0.0"},
{"name":"puppetlabs-inifile","version_requirement":">= 2.4.0 <= 4.0.0"},
{"name":"puppetlabs-apt","version_requirement":">= 7.0.1 < 8.0.0"},
{"name":"puppetlabs-facts","version_requirement":">= 0.5.0 < 1.0.0"}
]
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/puppet_agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def global_facts(facts, os)
end
let(:params) { global_params }

it { is_expected.to raise_error(Puppet::Error, %r{Nexenta not supported}) }
it { expect { catalogue }.to raise_error(Puppet::Error, %r{Nexenta not supported}) }
end
end
end
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 @@ -73,6 +73,17 @@
end
end

context 'package_version =>' do
describe '5.6.7' do
let(:params) { global_params.merge(
{:package_version => '5.6.7'})
}
it {
is_expected.to contain_exec('install_puppet.ps1').with_unless(/\-Command {\$CurrentVersion = \[string\]\(facter.bat \-p aio_agent_version\);/)
is_expected.to contain_exec('install_puppet.ps1').with_unless(/\-Command.*if \(\$CurrentVersion \-eq '5\.6\.7'\) { +exit 0; *} *exit 1; }\.Invoke\(\)/)
}
end
end
context 'install_options =>' do
describe 'OPTION1=value1 OPTION2=value2' do
let(:params) { global_params.merge(
Expand Down
2 changes: 1 addition & 1 deletion task_spec/.fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ fixtures:
forge_modules:
facts:
repo: "puppetlabs/facts"
ref: "0.5.1"
ref: "0.6.0"
symlinks:
puppet_agent: "#{File.absolute_path(File.join(source_dir, '..'))}"
12 changes: 11 additions & 1 deletion task_spec/spec/acceptance/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def target_platform
end

# Try to install an older version
results = run_task('puppet_agent::install', 'target', { 'collection' => 'puppet5', 'version' => puppet_5_version })
results = run_task('puppet_agent::install', 'target', { 'collection' => 'puppet5',
'version' => puppet_5_version,
'stop_service' => true })
results.each do |res|
expect(res).to include('status' => 'success')
end
Expand All @@ -57,6 +59,14 @@ def target_platform
expect(res['result']['source']).to be
end

service = if target_platform =~ /win/
run_command('c:/"program files"/"puppet labs"/puppet/bin/puppet resource service puppet', 'target')
else
run_command('/opt/puppetlabs/bin/puppet resource service puppet', 'target')
end
output = service[0]['result']['stdout']
expect(output).to include("ensure => 'stopped'")

# Run with no argument upgrades
results = run_task('puppet_agent::install', 'target', { 'collection' => 'puppet5' })
results.each do |res|
Expand Down
4 changes: 4 additions & 0 deletions tasks/install.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
"install_options": {
"description": "optional install arguments to the windows installer (defaults to REINSTALLMODE=\"amus\")",
"type": "Optional[String]"
},
"stop_service": {
"description": "Whether to stop the puppet agent service after install",
"type": "Optional[Boolean]"
}
},
"implementations": [
Expand Down
4 changes: 4 additions & 0 deletions tasks/install_powershell.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
"install_options": {
"description": "optional install arguments to the windows installer (defaults to REINSTALLMODE=\"amus\")",
"type": "Optional[String]"
},
"stop_service": {
"description": "Whether to stop the puppet agent service after install",
"type": "Optional[Boolean]"
}
}
}
6 changes: 5 additions & 1 deletion tasks/install_powershell.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Param(
[String]$version,
[String]$collection = 'puppet',
[String]$windows_source = 'https://downloads.puppet.com',
[String]$install_options = 'REINSTALLMODE="amus"'
[String]$install_options = 'REINSTALLMODE="amus"',
[Bool]$stop_service = $False
)
# If an error is encountered, the script will stop instead of the default of "Continue"
$ErrorActionPreference = "Stop"
Expand Down Expand Up @@ -65,6 +66,9 @@ function InstallPuppet {
}

function Cleanup {
if($stop_service -eq 'true') {
C:\"Program Files"\"Puppet Labs"\Puppet\bin\puppet resource service puppet ensure=stopped enable=false
}
Write-Output "Deleting $msi_dest and $install_log"
Remove-Item -Force $msi_dest
Remove-Item -Force $install_log
Expand Down
7 changes: 6 additions & 1 deletion tasks/install_shell.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
"install_options": {
"description": "optional install arguments to the windows installer (defaults to REINSTALLMODE=\"amus\")",
"type": "Optional[String]"
},
"stop_service": {
"description": "Whether to stop the puppet agent service after install",
"type": "Optional[Boolean]"
}
}
},
"files": ["facts/tasks/bash.sh"]
}
28 changes: 28 additions & 0 deletions tasks/install_shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ case $platform in
"SLES")
platform_version=$major_version
;;
"Amzn"|"Amazon Linux")
case $platform_version in
"2") platform_version="7";;
esac
;;
esac

# Find which version of puppet is currently installed if any
Expand Down Expand Up @@ -463,6 +468,12 @@ case $platform in
filename="${collection}-release-el-${platform_version}.noarch.rpm"
download_url="${yum_source}/${filename}"
;;
"Amzn"|"Amazon Linux")
info "Amazon platform! Lets get you an RPM..."
filetype="rpm"
filename="${collection}-release-el-${platform_version}.noarch.rpm"
download_url="${yum_source}/${filename}"
;;
"Fedora")
info "Fedora platform! Lets get the RPM..."
filetype="rpm"
Expand All @@ -477,6 +488,19 @@ case $platform in
"7") deb_codename="wheezy";;
"8") deb_codename="jessie";;
"9") deb_codename="stretch";;
"10") deb_codename="buster";;
esac
filetype="deb"
filename="${collection}-release-${deb_codename}.deb"
download_url="${apt_source}/${filename}"
;;
"Linuxmint"|"LinuxMint")
info "Mint platform! Lets get you a DEB..."
case $major_version in
"3") deb_codename="stretch";;
"19") deb_codename="bionic";;
"18") deb_codename="xenial";;
"17") deb_codename="trusty";;
esac
filetype="deb"
filename="${collection}-release-${deb_codename}.deb"
Expand Down Expand Up @@ -524,6 +548,10 @@ do_download "$download_url" "$download_filename"

install_file $filetype "$download_filename"

if [[ $PT_stop_service = true ]]; then
/opt/puppetlabs/bin/puppet resource service puppet ensure=stopped enable=false
fi

#Cleanup
if test "x$tmp_dir" != "x"; then
rm -r "$tmp_dir"
Expand Down