我编写了一个简单的剧本,用于从运行 Windows10 的虚拟机 (VM) 中卸载 Firefox。我是 ansible/chocolatey 的新手,所以这里是代码:
- name: Test win_chocolatey module
hosts: win1
tasks:
- name: Uninstall firefox
win_chocolatey:
name: firefox
state: absent
在我的机器上执行此代码后,Windows VM 上安装的巧克力包中不再出现 Firefox。但是 Firefox 仍然安装在 Windows 虚拟机上并且可以正常运行。
我查找了卸载命令的 ansible 文档,发现了一条注释:
“....仅当软件包维护者提供脚本 ChocolateyUninstall.ps1 时,choco uninstall 才会从系统中删除软件包”。
因此,我修改了之前的剧本以包含我下载的 powershell 脚本 ( 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
Firefox 在我的 Windows 虚拟机上仍然没有消失。 我使用的是ansible 2.0.0.2,chocolatey 0.9.9.11
有什么帮助吗?谢谢
最佳答案
Chocolatey.org 上的每个包都需要它自己的 ChocolateyUninstall.ps1 文件。您不能使用另一个包的 ChocolateyUninstall.ps1 文件并希望它卸载另一个包,这根本不是它的设计工作方式。
如您所见here Chocolatey.org 上的 Firefox 软件包确实没有卸载文件,因此 ansible 无法调用它。
您可能想要尝试使用 Chocolatey 中提供的"new"自动卸载功能。您可以使用以下方式找到有关此内容的更多信息:
choco 功能 -h
启用该功能后,再次安装 Firefox,然后尝试卸载它,看看是否有预期的结果。
此外,在等式中没有 ansible 的情况下,可能值得对此进行测试。直接用 Chocolatey 测试它,确保它有效,然后添加 ansible。
关于powershell - 如何使用 Ansible 卸载 Chocolatey 软件包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35407799/