Skip to content

Commit

Permalink
Merge pull request #306 from MikaelSmith/version-task
Browse files Browse the repository at this point in the history
(BOLT-641) Add version task
  • Loading branch information
MikaelSmith authored Aug 2, 2018
2 parents 73c71c8 + 02cbcc4 commit fa0c9e2
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ log/
pkg/
spec/fixtures/manifests/
spec/fixtures/modules/
task_spec/spec/fixtures/manifests/
task_spec/spec/fixtures/modules/
tmp/
vendor/

Expand Down
15 changes: 15 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
* [Setup requirements](#setup-requirements)
* [Beginning with puppet_agent](#beginning-with-puppet_agent)
4. [Usage - Configuration options and additional functionality](#usage)
* [Puppet 3 Upgrades](#puppet-3-upgrades)
* [Puppet 4 Upgrades](#puppet-4-upgrades)
5. [Reference](#reference)
* [Public classes](#public-classes)
* [Private classes](#private-classes)
* [Parameters](#parameters)
* [Tasks](#tasks)
6. [Limitations - OS compatibility, etc.](#limitations)
* [Known issues](#known-issues)
7. [Development - Guide for contributing to the module](#development)
Expand Down Expand Up @@ -195,6 +198,18 @@ This is only applicable for Windows operating systems. There may be instances wh
msi_move_locked_files => true
```

### Tasks

#### `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}`.

#### `puppet_agent::install`

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

## Limitations

Mac OS X Open Source packages are currently not supported.
Expand Down
17 changes: 17 additions & 0 deletions task_spec/spec/acceptance/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ def bolt_on(target, type, action, object,
result
end

it 'version returns null with no agent present' do
results = run_task_on('target', 'puppet_agent::version')
results.each do |res|
expect(res['status']).to eq('success')
expect(res['result']['version']).to eq(nil)
end
end

it 'runs and installs the agent' do
results = run_task_on('target', "puppet_agent::install")
results.each do |res|
Expand All @@ -173,4 +181,13 @@ def bolt_on(target, type, action, object,
expect(res["status"]).to eq("success")
end
end

it 'vesion returns the version with agent present' do
results = run_task_on('target', 'puppet_agent::version')
results.each do |res|
expect(res['status']).to eq('success')
expect(res['result']['version']).to match(/^\d\.\d\.\d/)
expect(res['result']['source']).to be
end
end
end
6 changes: 3 additions & 3 deletions tasks/install.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"description": "Install the puppet 5 agent package",
"description": "Install the Puppet 5 agent package",
"parameters": {
"version": {
"description": "The version of puppet to install",
"description": "The version of puppet-agent to install",
"type": "Optional[String]"
}
},
"implementations": [
{"name": "shell.sh", "requirements": ["shell"]}
{"name": "install_shell.sh", "requirements": ["shell"]}
]
}
File renamed without changes.
8 changes: 8 additions & 0 deletions tasks/version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"description": "Get the version of the Puppet 5 agent package installed. Returns nothing if none present.",
"parameters": {},
"implementations": [
{"name": "version_shell.sh", "requirements": ["shell"]},
{"name": "version_powershell.ps1", "requirements": ["powershell"]}
]
}
14 changes: 14 additions & 0 deletions tasks/version_powershell.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
if (Test-Path 'HKLM:\SOFTWARE\Puppet Labs\Puppet') {
$reg = $(Get-ItemProperty -Path 'HKLM:\SOFTWARE\Puppet Labs\Puppet')
if (Test-Path $reg.RememberedInstallDir64) {
$loc = $reg.RememberedInstallDir64+'VERSION'
} elseif (Test-Path $reg.RememberedInstallDir) {
$loc = $reg.RememberedInstallDir+'VERSION'
}
}

if ($loc -ne $null) {
Write-Output "{`"version`":`"$(type $loc)`",`"source`":`"$($loc.replace('\', '/'))`"}"
} else {
Write-Output '{"version":null,"source":null}'
}
8 changes: 8 additions & 0 deletions tasks/version_shell.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

loc=/opt/puppetlabs/puppet/VERSION
if test -f $loc; then
echo "{\"version\":\"$(cat $loc)\",\"source\":\"${loc}\"}"
else
echo '{"version":null,"source":null}'
fi

0 comments on commit fa0c9e2

Please sign in to comment.