[英]How do I uninstall a Chocolatey package with Ansible?
我写了一个简单的剧本,从运行Windows10的虚拟机(VM)卸载firefox。 我不熟悉ansible / chocolatey,因此代码如下:
- name: Test win_chocolatey module
hosts: win1
tasks:
- name: Uninstall firefox
win_chocolatey:
name: firefox
state: absent
在我的机器上执行此代码后,在Windows VM上安装的Chocolatey软件包中,firefox不再出现。 但是,仍然安装了firefox,它在Windows VM上可以正常工作。
我查看了有关卸载命令的Ansible文档,并发现了一条注释:
“ ....仅当软件包维护者提供脚本ChocolateyUninstall.ps1时,choco卸载才会从系统中删除软件包”。
因此,我修改了我以前的剧本,以包括我下载的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
我的Windows VM上仍然没有firefox。 我正在使用ansible 2.0.0.2,巧克力味0.9.9.11
有什么帮助吗? 谢谢
Chocolatey.org上的每个软件包都需要它自己的ChocolateyUninstall.ps1文件。 您不能使用另一个程序包的ChocolateyUninstall.ps1文件,并希望它会卸载另一个程序包,这根本不是它设计的工作方式。
正如你可以看到这里的火狐包上Chocolatey.org确实没有卸载文件,因此,ansible不能调用它。
您可能想尝试的是使用Chocolatey中提供的“新”自动卸载功能。 您可以使用以下方法找到有关此信息的更多信息:
choco feature -h
启用该功能后,再次安装Firefox,然后尝试将其卸载,然后查看是否达到了预期的效果。
同样,可能值得在方程中没有ansible的情况下对此进行测试。 直接用Chocolatey进行测试,确保可以正常工作,然后添加ansible。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.