powershell - 如何使用 Ansible 卸载 Chocolatey 软件包?

标签 powershell ansible chocolatey

我编写了一个简单的剧本,用于从运行 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/

相关文章:

c# - 快速生成 Excel

ansible - ansible处理程序发生错误后如何运行命令

javascript - 如何修复 'npm ERR! Cannot read property ' startsWith' of null'

powershell - 为什么不支持 URI 格式作为包名称?

powershell - Powershell-从具有AD属性的组中删除成员

powershell - 使用 powershell 合并多个 CSV 文件

powershell - 在 PowerShell 版本 2 中检查进程和进程状态并根据单个进程或多个进程获得两个不同的输出?

json - Ansible:如何在 JSON 中打印数字而不是字符串 - 模块 uri

spring - Docker错误解决了http://es.example/oauth/check_token的POST请求上的主机和I/O错误拒绝连接

powershell - 如何使用巧克力创建和安装 powershell 命令包?