From 1ec376abca6b7e35636e6bad8ff5bc253c117b86 Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Wed, 20 Feb 2019 08:16:48 +1000 Subject: [PATCH] win_chocolatey - fix beta version parsing (#52601) --- changelogs/fragments/win_chocolatey-beta-versions.yaml | 2 ++ lib/ansible/modules/windows/win_chocolatey.ps1 | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/win_chocolatey-beta-versions.yaml diff --git a/changelogs/fragments/win_chocolatey-beta-versions.yaml b/changelogs/fragments/win_chocolatey-beta-versions.yaml new file mode 100644 index 0000000000..5860e79745 --- /dev/null +++ b/changelogs/fragments/win_chocolatey-beta-versions.yaml @@ -0,0 +1,2 @@ +bugfixes: +- win_chocolatey - Fix issue when parsing a beta Chocolatey install - https://github.com/ansible/ansible/issues/52331 diff --git a/lib/ansible/modules/windows/win_chocolatey.ps1 b/lib/ansible/modules/windows/win_chocolatey.ps1 index 234447cfa9..8b5f2e9722 100644 --- a/lib/ansible/modules/windows/win_chocolatey.ps1 +++ b/lib/ansible/modules/windows/win_chocolatey.ps1 @@ -292,7 +292,15 @@ Function Install-Chocolatey { } $actual_version = (Get-ChocolateyPackageVersion -choco_path $choco_app.Path -name chocolatey)[0] - if ([Version]$actual_version -lt [Version]"0.10.5") { + try { + # The Chocolatey version may not be in the strict form of major.minor.build and will fail to cast to + # System.Version. We want to warn if this is the case saying module behaviour may be incorrect. + $actual_version = [Version]$actual_version + } catch { + $module.Warn("Failed to parse Chocolatey version '$actual_version' for checking module requirements, module may not work correctly: $($_.Exception.Message)") + $actual_version = $null + } + if ($null -ne $actual_version -and $actual_version -lt [Version]"0.10.5") { if ($module.CheckMode) { $module.Result.skipped = $true $module.Result.msg = "Skipped check mode run on win_chocolatey as choco.exe is too old, a real run would have upgraded the executable. Actual: '$actual_version', Minimum Version: '0.10.5'"