win_chocolatey: Fix error when choco.exe not found (#53115) (#64881)

* win_chocolatey: Fix error when choco.exe not found

* Slight tweak to check and added changelog fragment

* Removed ignore rule that's no longer needed

(cherry picked from commit 521d6465f6)
pull/65015/head^2
Jordan Borean 5 years ago committed by Matt Davis
parent 6ee5297c02
commit ca5e7e7cc2

@ -0,0 +1,2 @@
bugfixes:
- win_chocolatey - Improve error checking when finding the path of a newly installed Chocolatey app

@ -284,23 +284,21 @@ Function Install-Chocolatey {
# locate the newly installed choco.exe # locate the newly installed choco.exe
$choco_app = Get-Command -Name choco.exe -CommandType Application -ErrorAction SilentlyContinue $choco_app = Get-Command -Name choco.exe -CommandType Application -ErrorAction SilentlyContinue
if ($null -eq $choco_app) { if ($null -eq $choco_app) {
$choco_path = $env:ChocolateyInstall $choco_dir = $env:ChocolateyInstall
if ($null -ne $choco_path) { if ($null -eq $choco_dir) {
$choco_path = "$choco_path\bin\choco.exe" $choco_dir = "$env:SYSTEMDRIVE\ProgramData\Chocolatey"
} else {
$choco_path = "$env:SYSTEMDRIVE\ProgramData\Chocolatey\bin\choco.exe"
} }
$choco_app = Get-Command -Name "$choco_dir\bin\choco.exe" -CommandType Application -ErrorAction SilentlyContinue
$choco_app = Get-Command -Name $choco_path -CommandType Application -ErrorAction SilentlyContinue
} }
} }
if ($module.CheckMode -and $null -eq $choco_app) { if ($module.CheckMode -and $null -eq $choco_app) {
$module.Result.skipped = $true $module.Result.skipped = $true
$module.Result.msg = "Skipped check mode run on win_chocolatey as choco.exe cannot be found on the system" $module.Result.msg = "Skipped check mode run on win_chocolatey as choco.exe cannot be found on the system"
$module.ExitJson() $module.ExitJson()
} }
if (-not (Test-Path -Path $choco_app.Path)) { if ($null -eq $choco_app -or -not (Test-Path -LiteralPath $choco_app.Path)) {
$module.FailJson("Failed to find choco.exe, make sure it is added to the PATH or the env var 'ChocolateyInstall' is set") $module.FailJson("Failed to find choco.exe, make sure it is added to the PATH or the env var 'ChocolateyInstall' is set")
} }
@ -321,6 +319,7 @@ Function Install-Chocolatey {
} }
$module.Warn("Chocolatey was older than v0.10.5 so it was upgraded during this task run.") $module.Warn("Chocolatey was older than v0.10.5 so it was upgraded during this task run.")
Update-ChocolateyPackage -choco_path $choco_app.Path -packages @("chocolatey") ` Update-ChocolateyPackage -choco_path $choco_app.Path -packages @("chocolatey") `
-proxy_url $proxy_url -proxy_username $proxy_username ` -proxy_url $proxy_url -proxy_username $proxy_username `
-proxy_password $proxy_password -source $source ` -proxy_password $proxy_password -source $source `
-source_username $source_username -source_password $source_password -source_username $source_username -source_password $source_password

@ -5649,7 +5649,6 @@ lib/ansible/modules/windows/setup.ps1 pslint:PSCustomUseLiteralPath
lib/ansible/modules/windows/win_acl_inheritance.ps1 pslint:PSAvoidTrailingWhitespace lib/ansible/modules/windows/win_acl_inheritance.ps1 pslint:PSAvoidTrailingWhitespace
lib/ansible/modules/windows/win_audit_rule.ps1 pslint:PSCustomUseLiteralPath lib/ansible/modules/windows/win_audit_rule.ps1 pslint:PSCustomUseLiteralPath
lib/ansible/modules/windows/win_certificate_store.ps1 validate-modules:parameter-type-not-in-doc lib/ansible/modules/windows/win_certificate_store.ps1 validate-modules:parameter-type-not-in-doc
lib/ansible/modules/windows/win_chocolatey.ps1 pslint:PSCustomUseLiteralPath
lib/ansible/modules/windows/win_chocolatey_config.ps1 pslint:PSCustomUseLiteralPath lib/ansible/modules/windows/win_chocolatey_config.ps1 pslint:PSCustomUseLiteralPath
lib/ansible/modules/windows/win_chocolatey_facts.ps1 pslint:PSCustomUseLiteralPath lib/ansible/modules/windows/win_chocolatey_facts.ps1 pslint:PSCustomUseLiteralPath
lib/ansible/modules/windows/win_chocolatey_source.ps1 pslint:PSCustomUseLiteralPath lib/ansible/modules/windows/win_chocolatey_source.ps1 pslint:PSCustomUseLiteralPath

Loading…
Cancel
Save