Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: devel
from

Conversation

Projects
None yet
3 participants
@dagwieers
Copy link
Member

dagwieers commented Feb 28, 2019

SUMMARY

This fixes an issue where Get-Command would return $null, but we access the Path property anyway and PowerShell accepts it as if everything is possible. Sigh.

This relates to #47821 but does not fix it. We still do not know why the newly installed choco.exe was not found. (Possibly because it was not correctly installed, it was removed or it requires a reboot ?)

At least we now get a proper error indication.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

win_chocolatey

@dagwieers dagwieers force-pushed the dagwieers:win_chocolatey-choco_path branch from f9561b1 to c07debf Feb 28, 2019

@ansibot ansibot removed the needs_triage label Feb 28, 2019

@jborean93
Copy link
Contributor

jborean93 left a comment

Added some more comments, also you will want a changelog fragment so we can backport it.

Show resolved Hide resolved lib/ansible/modules/windows/win_chocolatey.ps1
if ($module.CheckMode -and $null -eq $choco_app) {
$module.Result.skipped = $true
$module.Result.msg = "Skipped check mode run on win_chocolatey as choco.exe cannot be found on the system"
$module.ExitJson()
}

if (-not (Test-Path -Path $choco_app.Path)) {
if ($null -eq $choco_app -or -not (Test-Path -LiteralPath $choco_app.Path)) {

This comment has been minimized.

@jborean93

jborean93 Mar 3, 2019

Contributor

This first part might be the actual fix and the changes you've made above really aren't related to the problem.

This comment has been minimized.

@dagwieers

dagwieers Mar 4, 2019

Author Member

Correct, but they made me understand that we did not need $choco_path at all. So not only did I fix the issue, I also improved the readability of the code which deceived me. ANd it deceived you as well, because you also commented at first that we had to use $choco_path further on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.