Reputation: 1198
I have written a simple playbook to uninstall firefox from a virtual machine (VM) running windows10. I am new to ansible/chocolatey so here is the code:
- name: Test win_chocolatey module
hosts: win1
tasks:
- name: Uninstall firefox
win_chocolatey:
name: firefox
state: absent
After I execute this code on my machine firefox does not appear anymore among the chocolatey packages installed on windows VM. However firefox is still installed and it works properly on the windows VM.
I looked up the ansible documentation for the uninstall command and I have found a note:
".... choco uninstall removes the package from your system only if the script chocolateyUninstall.ps1 is provided by the package maintainer".
So, I have modified my previous playbook in order to include the powershell script I downloaded (https://github.com/Iristyle/ChocolateyPackages/blob/master/HipChat/tools/chocolateyUninstall.ps1):
- name: Test win_chocolatey module
hosts: win1
tasks:
- name: Run PS script
script: /home/ansible_example/chocolateyUninstall.ps1
- name: Uninstall firefox
win_chocolatey:
name: firefox
state: absent
Still firefox is not gone on my windows VM. I am using ansible 2.0.0.2, chocolatey 0.9.9.11
Any help? Thank you
Upvotes: 3
Views: 3029
Reputation: 19021
Each package on Chocolatey.org would require it's own chocolateyUninstall.ps1 file. You can't use another package's chocolateyUninstall.ps1 file and hope that it will uninstall another package, that simply isn't how it is designed to work.
As you can see here the Firefox package on Chocolatey.org indeed does not have an uninstall file, therefore, ansible can't call it.
What you might want to try is using the "new" auto-uninstallation feature that is available in Chocolatey. You can find out more information about this using:
choco feature -h
After enabling that feature, install Firefox again, and then try uninstalling it, and see if that has the desired result.
Also, it is probably worth testing this without ansible in the equation. Test it directly with Chocolatey, make sure this works, then add in ansible.
Upvotes: 4