Showing with 80 additions and 19 deletions.
  1. +6 −0 CHANGELOG.md
  2. +18 −5 README.markdown
  3. +1 −1 metadata.json
  4. +1 −0 spec/classes/puppet_agent_spec.rb
  5. +15 −1 task_spec/spec/acceptance/init_spec.rb
  6. +2 −2 tasks/install.json
  7. +2 −1 tasks/install_powershell.json
  8. +15 −1 tasks/install_powershell.ps1
  9. +20 −8 tasks/install_shell.sh
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Change Log
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [3.0.0] - 2020-01-24

### Summary
Assume latest version of the puppet-agent package only when no version is specified and the puppet-agent package is not installed (`puppet_agent::install` task).

## [2.2.3] - 2019-12-10

### Summary
Expand Down
23 changes: 18 additions & 5 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,28 @@ This is only applicable for Windows operating systems and pertains to /files/ins

#### `puppet_agent::version`

Checks for the version of puppet-agent package installed. Returns results as `{"version": "<ver>", "source": "<how version was
detected>"}`. If a version cannot be found, returns `{"version": null}`.
Checks for the version of puppet-agent package installed.

**Return value**

The `puppet_agent::version` task returns a Result on success specifying the version of the agent installed and how it was detected.

```
{
"version": <version>,
"source": <source>
}
```

#### `puppet_agent::install`

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.
Installs the puppet-agent package.

> **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`.
**Return value**

**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`.
The task returns the output of the installation script.

## Limitations

Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "puppetlabs-puppet_agent",
"version": "2.2.3",
"version": "3.0.0",
"author": "puppetlabs",
"summary": "Upgrades All-In-One Puppet Agents",
"license": "Apache-2.0",
Expand Down
1 change: 1 addition & 0 deletions spec/classes/puppet_agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def global_facts(facts, os)
elsif os =~ %r{solaris}
{
is_pe: true,
puppet_agent_pid: 298,
}
elsif os =~ %r{aix}
{
Expand Down
16 changes: 15 additions & 1 deletion task_spec/spec/acceptance/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ def target_platform
expect(res).to include('status' => 'success')
end

# Verify that it did nothing
results = run_task('puppet_agent::version', 'target', {})
results.each do |res|
expect(res).to include('status' => 'success')
expect(res['result']['version']).to eq(puppet_5_version)
expect(res['result']['source']).to be
end

# Run with latest upgrades
results = run_task('puppet_agent::install', 'target', { 'collection' => 'puppet5', 'version' => 'latest' })
results.each do |res|
expect(res).to include('status' => 'success')
end

# Verify that it upgraded
results = run_task('puppet_agent::version', 'target', {})
results.each do |res|
Expand All @@ -85,7 +99,7 @@ def target_platform
end

# Upgrade from puppet5 to puppet6
results = run_task('puppet_agent::install', 'target', { 'collection' => 'puppet6' })
results = run_task('puppet_agent::install', 'target', { 'collection' => 'puppet6', 'version' => 'latest' })
results.each do |res|
expect(res).to include('status' => 'success')
end
Expand Down
4 changes: 2 additions & 2 deletions tasks/install.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"description": "Install the Puppet agent package",
"parameters": {
"version": {
"description": "The version of puppet-agent to install",
"description": "The version of puppet-agent to install (defaults to latest when no agent is installed)",
"type": "Optional[String]"
},
"collection": {
Expand Down Expand Up @@ -36,6 +36,6 @@
},
"implementations": [
{"name": "install_shell.sh", "requirements": ["shell"], "files": ["facts/tasks/bash.sh"], "input_method": "environment"},
{"name": "install_powershell.ps1", "requirements": ["powershell"]}
{"name": "install_powershell.ps1", "requirements": ["powershell"], "files": ["puppet_agent/tasks/version_powershell.ps1"]}
]
}
3 changes: 2 additions & 1 deletion tasks/install_powershell.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@
"description": "Whether to stop the puppet agent service after install",
"type": "Optional[Boolean]"
}
}
},
"files": ["puppet_agent/tasks/version_powershell.ps1"]
}
16 changes: 15 additions & 1 deletion tasks/install_powershell.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,24 @@ catch [System.Management.Automation.CommandNotFoundException] {
}
}

function Test-PuppetInstalled {
$result = & "$PSScriptRoot\version_powershell.ps1" | ConvertFrom-Json
return $result.version
}

if ($version) {
$msi_name = "puppet-agent-${version}-${arch}.msi"
if ($version -eq "latest") {
$msi_name = "puppet-agent-${arch}-latest.msi"
} else {
$msi_name = "puppet-agent-${version}-${arch}.msi"
}
}
else {
if (Test-PuppetInstalled) {
Write-Output "Puppet Agent detected and no version specified. Nothing to do."
Exit
}

$msi_name = "puppet-agent-${arch}-latest.msi"
}

Expand Down
28 changes: 20 additions & 8 deletions tasks/install_shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,26 @@ else
installed_version=uninstalled
fi

# Only install the agent in cases where no agent is present, or the version of the agent
# has been explicitly defined and does not match the version of an installed agent.
if [ -z "$version" ]; then
if [ "$installed_version" == "uninstalled" ]; then
info "Version parameter not defined and no agent detected. Assuming latest."
version=latest
else
info "Version parameter not defined and agent detected. Nothing to do."
exit 0
fi
else
info "Version parameter defined: ${version}"
if [ "$version" == "$installed_version" ]; then
info "Version parameter defined: ${version}. Puppet Agent ${version} detected. Nothing to do."
exit 0
elif [ "$version" != "latest" ]; then
puppet_agent_version="$version"
fi
fi

# Retrieve Platform and Platform Version
# Utilize facts implementation when available
if [ -f "$PT__installdir/facts/tasks/bash.sh" ]; then
Expand Down Expand Up @@ -171,14 +191,6 @@ if test "x$platform" = "x"; then
exit 1
fi

if test "x$version" = "x"; then
version="latest";
info "Version parameter not defined, assuming latest";
else
info "Version parameter defined: $version";
puppet_agent_version=$version
fi

# Mangle $platform_version to pull the correct build
# for various platforms
major_version=`echo $platform_version | cut -d. -f1`
Expand Down