Skip to content

Commit cd56e62

Browse files
committed
(MODULES-10653) Failed to upgrade agent using puppet task
Before this commit, when trying to run the `puppet_agent::install_powershell` task, with a specific version as parameter, it was failing with below error message: Error: Timed out waiting for status response from <node_name> On the node, both `puppet agent` and `pxp-agent` services got stopped and the event log viewer showed: Application or service 'task_wrapper' could not be shut down. Due to Windows agents becoming unresponsive when running this task and as per MODULES-10633 discussions, the `puppet_agent::install_poweshell` task should not be used for upgrading Puppet Agents while either of `puppet agent` or `pxp-agent` services are still running. This Puppet Agent module task will now fail immediately and output a message if any of the two affected services are still running. The task will stop and output a message if the given version is already installed on the node, thus avoiding unnecessary msi download/installation. This behaviour is aligned with the existing implementation for no version given and Puppet Agent already installed on the node.
1 parent b83c5b9 commit cd56e62

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tasks/install_powershell.ps1

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,45 @@ function Test-PuppetInstalled {
3434
}
3535
}
3636

37+
function Test-PuppetInstalledVersion {
38+
$rootPath = 'HKLM:\SOFTWARE\Puppet Labs\Puppet'
39+
40+
$reg = Get-ItemProperty -Path $rootPath -ErrorAction SilentlyContinue
41+
if ($null -ne $reg) {
42+
if ($null -ne $reg.RememberedInstallDir64) {
43+
$loc = $reg.RememberedInstallDir64+'VERSION'
44+
} elseif ($null -ne $reg.RememberedInstallDir) {
45+
$loc = $reg.RememberedInstallDir+'VERSION'
46+
}
47+
}
48+
49+
if ($null -ne $loc) {
50+
$installedVersion = Get-Content -Path $loc -ErrorAction SilentlyContinue
51+
if ($installedVersion -eq $version) {
52+
RETURN $true
53+
}
54+
}
55+
56+
RETURN $false
57+
}
58+
59+
function Test-RunningServices {
60+
$puppetAgentService = Get-Service -DisplayName 'Puppet Agent' -ErrorAction SilentlyContinue
61+
$pxpAgentService = Get-Service -DisplayName 'Puppet PXP Agent' -ErrorAction SilentlyContinue
62+
63+
if ($puppetAgentService.Status -eq 'Running' -or $pxpAgentService.Status -eq 'Running') {
64+
RETURN $true
65+
}
66+
67+
RETURN $false
68+
}
69+
3770
if ($version) {
71+
if (Test-PuppetInstalledVersion) {
72+
Write-Output "Puppet Agent version $version is already installed on $env:COMPUTERNAME. Nothing to do."
73+
Exit
74+
}
75+
3876
if ($version -eq "latest") {
3977
$msi_name = "puppet-agent-${arch}-latest.msi"
4078
} else {
@@ -50,6 +88,10 @@ else {
5088
$msi_name = "puppet-agent-${arch}-latest.msi"
5189
}
5290

91+
if (Test-RunningServices) {
92+
Write-Error "Puppet Agent upgrade cannot be done while Puppet services are still running."
93+
}
94+
5395
# Change windows_source only if the collection is a nightly build, and the source was not explicitly specified.
5496
if (($collection -like '*nightly*') -And -Not ($PSBoundParameters.ContainsKey('windows_source'))) {
5597
$windows_source = 'https://nightlies.puppet.com/downloads'

0 commit comments

Comments
 (0)