Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions chocolatey/plugins/module_utils/Packages.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,11 @@ function Uninstall-ChocolateyPackage {
[Ansible.Basic.AnsibleModule]
$Module = (Get-AnsibleModule),

# Any additional arguments to be passed directly to `choco.exe`
[Parameter()]
[string[]]
$ChocoArgs,

# Set to force choco to reinstall the package if the package (version)
# is already installed.
[Parameter()]
Expand Down Expand Up @@ -1005,6 +1010,8 @@ function Uninstall-ChocolateyPackage {
if ($PSBoundParameters.ContainsKey('Timeout')) { "--timeout", $timeout }
if ($SkipScripts) { "--skip-scripts" }
if ($PackageParams) { "--package-parameters", $package_params }

if ($ChocoArgs) { $ChocoArgs }
)

$command = Argv-ToString -Arguments $arguments
Expand Down
5 changes: 4 additions & 1 deletion chocolatey/plugins/modules/win_chocolatey.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ if ($state -in "absent", "reinstalled") {
$uninstallParams = @{
ChocoCommand = $chocoCommand
Package = $package
ChocoArgs = $choco_args
Force = $force
PackageParams = $package_params
SkipScripts = $skip_scripts
Expand All @@ -209,7 +210,9 @@ if ($state -in @("downgrade", "latest", "upgrade", "present", "reinstalled")) {
$missingPackages = [System.Collections.Generic.List[string]]@()

if ($state -eq "present" -and $force) {
$missingPackages.Add($name)
foreach ($package in $name) {
$missingPackages.Add($package)
}
}
else {
foreach ($package in $packageInfo.GetEnumerator()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,3 +751,41 @@
that:
- ignore_pinned_upgrade is changed
- ignore_pinned_upgrade is not failed

- name: force install multiple packages
win_chocolatey:
name:
- '{{ test_choco_package1 }}'
- '{{ test_choco_package2 }}'
state: present
register: force_install_multiple

- name: assert force install multiple packages
assert:
that:
- force_install_multiple is changed
- force_install_multiple is not failed

- name: clear the Chocolatey log file
ansible.windows.win_file:
path: "{{ ansible_env.ChocolateyInstall }}\\logs\\chocolatey.log"
state: absent

- name: uninstall Chocolatey Package with additional choco_args
chocolatey.chocolatey.win_chocolatey:
name: '{{ test_choco_package1 }}'
state: absent
choco_args:
--skipautouninstaller

- name: read Chocolatey log file
ansible.windows.slurp:
src: "{{ ansible_env.ChocolateyInstall }}\\logs\\chocolatey.log"
register: uninstall_with_args_log_content

- name: assert generated choco command includes provided additional choco_args
ansible.builtin.assert:
that:
- log_text is search('(?i)command line.*uninstall\s+' ~ test_choco_package1 ~ '.*--skipautouninstaller')
vars:
log_text: "{{ uninstall_with_args_log_content['content'] | b64decode }}"
Loading