From a8fa432096e04678f0d6beeed33bf897f1d6e4fc Mon Sep 17 00:00:00 2001 From: Rostyslav Date: Mon, 25 Nov 2019 00:51:13 +0100 Subject: [PATCH] Add --override-arguments option to win_chocolatey module (#65101) * Add --override-arguments option to win_chocolatey module * Fix version and argument type * Added changelog fragment and tests --- .../win_chocolatey-override_args.yaml | 2 ++ .../modules/windows/win_chocolatey.ps1 | 19 +++++++++++++---- lib/ansible/modules/windows/win_chocolatey.py | 21 ++++++++++++------- .../files/tools/chocolateyinstall.ps1 | 6 ++++++ .../targets/win_chocolatey/tasks/tests.yml | 5 +++++ 5 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 changelogs/fragments/win_chocolatey-override_args.yaml diff --git a/changelogs/fragments/win_chocolatey-override_args.yaml b/changelogs/fragments/win_chocolatey-override_args.yaml new file mode 100644 index 00000000000..596d52b091f --- /dev/null +++ b/changelogs/fragments/win_chocolatey-override_args.yaml @@ -0,0 +1,2 @@ +minor_changes: +- win_chocolatey - Add ``override_args`` option to allow overriding builtin install arguments for a Chocolatey package diff --git a/lib/ansible/modules/windows/win_chocolatey.ps1 b/lib/ansible/modules/windows/win_chocolatey.ps1 index aa7665e01a9..d5cb87f7c0c 100644 --- a/lib/ansible/modules/windows/win_chocolatey.ps1 +++ b/lib/ansible/modules/windows/win_chocolatey.ps1 @@ -19,11 +19,12 @@ $spec = @{ allow_multiple = @{ type = "bool"; default = $false } allow_prerelease = @{ type = "bool"; default = $false } architecture = @{ type = "str"; default = "default"; choices = "default", "x86" } - install_args = @{ type = "str" } + force = @{ type = "bool"; default = $false } ignore_checksums = @{ type = "bool"; default = $false } ignore_dependencies = @{ type = "bool"; default = $false } - force = @{ type = "bool"; default = $false } + install_args = @{ type = "str" } name = @{ type = "list"; elements = "str"; required = $true } + override_args = @{ type = "bool"; default = $false } package_params = @{ type = "str"; aliases = @("params") } pinned = @{ type = "bool" } proxy_url = @{ type = "str" } @@ -46,11 +47,12 @@ $allow_empty_checksums = $module.Params.allow_empty_checksums $allow_multiple = $module.Params.allow_multiple $allow_prerelease = $module.Params.allow_prerelease $architecture = $module.Params.architecture -$install_args = $module.Params.install_args +$force = $module.Params.force $ignore_checksums = $module.Params.ignore_checksums $ignore_dependencies = $module.Params.ignore_dependencies -$force = $module.Params.force +$install_args = $module.Params.install_args $name = $module.Params.name +$override_args = $module.Params.override_args $package_params = $module.Params.package_params $pinned = $module.Params.pinned $proxy_url = $module.Params.proxy_url @@ -101,6 +103,7 @@ Function Get-InstallChocolateyArguments { [bool]$force, [bool]$ignore_dependencies, [String]$install_args, + [bool]$override_args, [String]$package_params, [String]$proxy_url, [String]$proxy_username, @@ -146,6 +149,9 @@ Function Get-InstallChocolateyArguments { $arguments.Add("--install-arguments") > $null $arguments.add($install_args) > $null } + if ($override_args) { + $arguments.Add("--override-arguments") > $null + } if ($package_params) { $arguments.Add("--package-parameters") > $null $arguments.Add($package_params) > $null @@ -469,6 +475,7 @@ Function Update-ChocolateyPackage { [bool]$ignore_checksums, [bool]$ignore_dependencies, [String]$install_args, + [bool]$override_args, [String]$package_params, [String]$proxy_url, [String]$proxy_username, @@ -494,6 +501,7 @@ Function Update-ChocolateyPackage { ignore_checksums = $ignore_checksums ignore_dependencies = $ignore_dependencies install_args = $install_args + override_args = $override_args package_params = $package_params proxy_url = $proxy_url proxy_username = $proxy_username @@ -544,6 +552,7 @@ Function Install-ChocolateyPackage { [bool]$ignore_checksums, [bool]$ignore_dependencies, [String]$install_args, + [bool]$override_args, [String]$package_params, [String]$proxy_url, [String]$proxy_username, @@ -568,6 +577,7 @@ Function Install-ChocolateyPackage { ignore_checksums = $ignore_checksums ignore_dependencies = $ignore_dependencies install_args = $install_args + override_args = $override_args package_params = $package_params proxy_url = $proxy_url proxy_username = $proxy_username @@ -736,6 +746,7 @@ if ($state -in @("downgrade", "latest", "present", "reinstalled")) { ignore_checksums = $ignore_checksums ignore_dependencies = $ignore_dependencies install_args = $install_args + override_args = $override_args package_params = $package_params proxy_url = $proxy_url proxy_username = $proxy_username diff --git a/lib/ansible/modules/windows/win_chocolatey.py b/lib/ansible/modules/windows/win_chocolatey.py index 70876edb36f..6792f59a937 100644 --- a/lib/ansible/modules/windows/win_chocolatey.py +++ b/lib/ansible/modules/windows/win_chocolatey.py @@ -65,13 +65,6 @@ options: made. type: bool default: no - install_args: - description: - - Arguments to pass to the native installer. - - These are arguments that are passed directly to the installer the - Chocolatey package runs, this is generally an advanced option. - type: str - version_added: '2.1' ignore_checksums: description: - Ignore the checksums provided by the package. @@ -86,12 +79,26 @@ options: type: bool default: no version_added: '2.1' + install_args: + description: + - Arguments to pass to the native installer. + - These are arguments that are passed directly to the installer the + Chocolatey package runs, this is generally an advanced option. + type: str + version_added: '2.1' name: description: - Name of the package(s) to be installed. - Set to C(all) to run the action on all the installed packages. type: list required: yes + override_args: + description: + - Override arguments of native installer with arguments provided by user. + - Should install arguments be used exclusively without appending + to current package passed arguments. + type: bool + version_added: '2.10' package_params: description: - Parameters to pass to the package. diff --git a/test/integration/targets/win_chocolatey/files/tools/chocolateyinstall.ps1 b/test/integration/targets/win_chocolatey/files/tools/chocolateyinstall.ps1 index 6f1df5eeb93..ee2c47f6c8e 100644 --- a/test/integration/targets/win_chocolatey/files/tools/chocolateyinstall.ps1 +++ b/test/integration/targets/win_chocolatey/files/tools/chocolateyinstall.ps1 @@ -25,6 +25,11 @@ if ($env:ChocolateyForceX86) { } else { $force_x86 = $false } +if ($env:ChocolateyInstallOverride) { + $override_args = $true +} else { + $override_args = $false +} #$process_env = Get-EnvironmentVariableNames -Scope Process #$env_vars = @{} #foreach ($name in $process_env) { @@ -39,6 +44,7 @@ $package_info = @{ force_x86 = $force_x86 ignore_checksums = $ignore_checksums install_args = $env:ChocolateyInstallArguments + override_args = $override_args package_params = Get-PackageParameters proxy_url = $env:ChocolateyProxyLocation source = $source diff --git a/test/integration/targets/win_chocolatey/tasks/tests.yml b/test/integration/targets/win_chocolatey/tasks/tests.yml index 4a1fa4a5eb5..5eb20163405 100644 --- a/test/integration/targets/win_chocolatey/tasks/tests.yml +++ b/test/integration/targets/win_chocolatey/tasks/tests.yml @@ -55,6 +55,7 @@ - (install_actual_info.stdout|from_json).force_x86 == False - (install_actual_info.stdout|from_json).ignore_checksums == False - (install_actual_info.stdout|from_json).install_args == None + - (install_actual_info.stdout|from_json).override_args == False - (install_actual_info.stdout|from_json).package_params == {} - (install_actual_info.stdout|from_json).proxy_url == None - (install_actual_info.stdout|from_json).source == "normal" @@ -151,6 +152,7 @@ - (install_multiple_package1.stdout|from_json).force_x86 == False - (install_multiple_package1.stdout|from_json).ignore_checksums == False - (install_multiple_package1.stdout|from_json).install_args == None + - (install_multiple_package1.stdout|from_json).override_args == False - (install_multiple_package1.stdout|from_json).package_params == {} - (install_multiple_package1.stdout|from_json).proxy_url == None - (install_multiple_package1.stdout|from_json).source == "normal" @@ -160,6 +162,7 @@ - (install_multiple_package2.stdout|from_json).force_x86 == False - (install_multiple_package2.stdout|from_json).ignore_checksums == False - (install_multiple_package2.stdout|from_json).install_args == None + - (install_multiple_package2.stdout|from_json).override_args == False - (install_multiple_package2.stdout|from_json).package_params == {} - (install_multiple_package2.stdout|from_json).proxy_url == None - (install_multiple_package2.stdout|from_json).source == "normal" @@ -221,6 +224,7 @@ name: '{{ test_choco_package1 }}' state: present install_args: /install_arg 1 /install_arg 2 + override_args: yes package_params: /param1 /param2:value allow_empty_checksums: yes architecture: x86 @@ -248,6 +252,7 @@ - (install_params_info.stdout|from_json).force_x86 == True - (install_params_info.stdout|from_json).ignore_checksums == True - (install_params_info.stdout|from_json).install_args == "/install_arg 1 /install_arg 2" + - (install_params_info.stdout|from_json).override_args == True - (install_params_info.stdout|from_json).package_params.keys()|count == 2 - (install_params_info.stdout|from_json).package_params.param1 == True - (install_params_info.stdout|from_json).package_params.param2 == "value"