Skip to content

(#176) Pass through choco_args on uninstall#190

Open
Windos wants to merge 2 commits intochocolatey:masterfrom
Windos:GH-176/choco_args-on-uninstall
Open

(#176) Pass through choco_args on uninstall#190
Windos wants to merge 2 commits intochocolatey:masterfrom
Windos:GH-176/choco_args-on-uninstall

Conversation

@Windos
Copy link
Member

@Windos Windos commented Jan 21, 2026

Description Of Changes

This PR enables the user to pass through additional parameters to choco.exe when uninstalling a package.

Motivation and Context

Certain features of choco.exe aren't exposed directly via the modules this Ansible collection and choco_args is a method for passing in additional flags when that is the case. It is currently, however, not setup to do so when state is set to absent (i.e. choco uninstall).

By changing this, it enables users to pass through options like --skipautouninstaller when uninstalling a package.

Testing

---
- hosts: vm
  gather_facts: true

  tasks:
  - name: Install Chocolatey Package
    chocolatey.chocolatey.win_chocolatey:
      name: firefox
      state: present

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

  - name: Remove/Not Uninstall Chocolatey Package
    chocolatey.chocolatey.win_chocolatey:
      name: firefox
      state: absent
      choco_args:
          --skipautouninstaller

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

  - name: Assert Firefox uninstall with skipautouninstaller is in the log
    ansible.builtin.assert:
      that:
        - log_text is search('(?i)command line.*uninstall\s+' ~ test_package_1 ~ '.*--skipautouninstaller')
    vars:
      log_text: "{{ choco_log_content['content'] | b64decode }}"
      test_package_1: 'firefox'
...

Operating Systems Testing

N/A

Change Types Made

  • Bug fix (non-breaking change).
  • Feature / Enhancement (non-breaking change).
  • Breaking change (fix or feature that could cause existing functionality to change).
  • Documentation changes.
  • PowerShell code changes.

Change Checklist

  • Requires a change to the documentation.
  • Documentation has been updated.
  • Tests to cover my changes, have been added.
  • All new and existing tests passed?
  • PowerShell code changes: PowerShell v3 compatibility checked?

Related Issue

Fixes #176

Currently, when using the force flag on the win_chocolatey command the
list of packages is being added to the collection of missing packages as
a single string. This results in the packages being passed to choco.exe
bounded by quote character (e.g. `"package1 package2"`) and so this is
being interpreted as a single (incorrect) package name.

This change iterates over the list of packages and adds them individually.

Additionally, tests have been added to cover this failure case.
choco_args enables the user to pass additional parameters to choco.exe,
however this was not being passed through on uninstalls (state: absent).

This change enables that passthrough on uninstalls, and also adds a test
to ensure that this is the case.
@Windos Windos requested a review from vexx32 January 21, 2026 21:52
@Windos
Copy link
Member Author

Windos commented Jan 21, 2026

This has been branched off of #188 as the tests needed to have a package already installed in order for the uninstall to actually be attempted and that PR adds a force install to the end which reliably makes that the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Not Working-Removing a package from chocolatey without attempting to uninstall the program

1 participant