From 0f6488bb1520bb450817d716d3ae1ea62c94f379 Mon Sep 17 00:00:00 2001 From: Jez McKinley Date: Thu, 19 Jul 2018 11:15:31 +0100 Subject: [PATCH] JM: allow choco to install 32 bit version (#42946) * JM: allow choco to install 32 bit version * JM: style corrections * Revert style changes in lists * JM: changing from boolean to string choice * JM: updating example --- .../modules/windows/win_chocolatey.ps1 | 20 +++++++++++++++---- lib/ansible/modules/windows/win_chocolatey.py | 14 +++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/windows/win_chocolatey.ps1 b/lib/ansible/modules/windows/win_chocolatey.ps1 index abbf2fdc1a..3262af4636 100644 --- a/lib/ansible/modules/windows/win_chocolatey.ps1 +++ b/lib/ansible/modules/windows/win_chocolatey.ps1 @@ -33,6 +33,7 @@ $skipscripts = Get-AnsibleParam -obj $params -name "skip_scripts" -type "bool" - $proxy_url = Get-AnsibleParam -obj $params -name "proxy_url" -type "str" $proxy_username = Get-AnsibleParam -obj $params -name "proxy_username" -type "str" $proxy_password = Get-AnsibleParam -obj $params -name "proxy_password" -type "str" -failifempty ($proxy_username -ne $null) +$architecture = Get-AnsibleParam -obj $params -name "architecture" -type "str" -default "default" -validateset "default","x86" $result = @{ changed = $false @@ -192,7 +193,8 @@ Function Choco-Upgrade [bool] $allowprerelease, [string] $proxy_url, [string] $proxy_username, - [string] $proxy_password + [string] $proxy_password, + [string] $architecture ) if (-not (Choco-IsInstalled $package)) @@ -202,6 +204,10 @@ Function Choco-Upgrade $options = @( "-y", $package, "--timeout", "$timeout", "--failonunfound" ) + switch ($architecture) { + "x86" { $options += "--x86" ; break} + } + if ($check_mode) { $options += "--whatif" @@ -306,6 +312,7 @@ Function Choco-Upgrade $result.failed = $false } + Function Choco-Install { [CmdletBinding()] @@ -327,7 +334,8 @@ Function Choco-Install [bool] $allowprerelease, [string] $proxy_url, [string] $proxy_username, - [string] $proxy_password + [string] $proxy_password, + [string] $architecture ) if (Choco-IsInstalled $package) @@ -340,7 +348,7 @@ Function Choco-Install -ignorechecksums $ignorechecksums -ignoredependencies $ignoredependencies ` -allowdowngrade $allowdowngrade -proxy_url $proxy_url ` -proxy_username $proxy_username -proxy_password $proxy_password ` - -allowprerelease $allowprerelease + -allowprerelease $allowprerelease -architecture $architecture return } elseif (-not $force) @@ -351,6 +359,10 @@ Function Choco-Install $options = @( "-y", $package, "--timeout", "$timeout", "--failonunfound" ) + switch ($architecture) { + "x86" { $options += "--x86" ; break} + } + if ($check_mode) { $options += "--whatif" @@ -529,7 +541,7 @@ if ($state -in ("downgrade", "latest", "present", "reinstalled")) { -ignorechecksums $ignorechecksums -ignoredependencies $ignoredependencies ` -allowdowngrade ($state -eq "downgrade") -proxy_url $proxy_url ` -proxy_username $proxy_username -proxy_password $proxy_password ` - -allowprerelease $allowprerelease + -allowprerelease $allowprerelease -architecture $architecture } Exit-Json -obj $result diff --git a/lib/ansible/modules/windows/win_chocolatey.py b/lib/ansible/modules/windows/win_chocolatey.py index a17ac2a03d..4e2011d1e8 100644 --- a/lib/ansible/modules/windows/win_chocolatey.py +++ b/lib/ansible/modules/windows/win_chocolatey.py @@ -51,6 +51,15 @@ options: source: description: - Specify source rather than using default chocolatey repository. + architecture: + description: + - Allows installation of alternative architecture packages, for example, + 32bit on 64bit windows. + version_added: '2.7' + choices: + - default + - x86 + default: default install_args: description: - Arguments to pass to the native installer. @@ -154,6 +163,11 @@ EXAMPLES = r''' name: notepadplusplus version: '6.6' +- name: Install notepadplusplus 32 bit version + win_chocolatey: + name: notepadplusplus + architecture: 'x86' + - name: Install git from specified repository win_chocolatey: name: git