【问题标题】:How do I uninstall a Chocolatey package with Ansible?如何使用 Ansible 卸载 Chocolatey 包?
【发布时间】:2016-02-15 11:08:52
【问题描述】:

我编写了一个简单的剧本来从运行 windows10 的虚拟机 (VM) 中卸载 firefox。我是 ansible/chocolatey 的新手,所以这里是代码:

- name: Test win_chocolatey module
  hosts: win1
  tasks:
    - name: Uninstall firefox
      win_chocolatey:
        name: firefox
        state: absent

在我的机器上执行此代码后,firefox 不再出现在 Windows VM 上安装的巧克力包中。但是仍然安装了 firefox,并且它在 windows VM 上正常工作。

我查阅了卸载命令的 ansible 文档,发现了一条注释:

".... choco uninstall 仅当包维护者提供脚本 ChocolateyUninstall.ps1 时才会从您的系统中删除包"。

所以,我修改了我之前的剧本,以便包含我下载的 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,chocolatey 0.9.9.11

有什么帮助吗?谢谢

【问题讨论】:

    标签: powershell ansible chocolatey


    【解决方案1】:

    Chocolatey.org 上的每个包都需要它自己的 ChocolateyUninstall.ps1 文件。您不能使用另一个包的 ChocolateyUninstall.ps1 文件并希望它会卸载另一个包,这根本不是它的设计工作方式。

    如你所见here Chocolatey.org 上的 Firefox 包确实没有卸载文件,因此 ansible 无法调用它。

    您可能想尝试使用 Chocolatey 中提供的“新”自动卸载功能。您可以通过以下方式了解更多信息:

    choco feature -h

    启用该功能后,再次安装 Firefox,然后尝试将其卸载,看看是否有所需的结果。

    此外,在等式中没有 ansible 的情况下可能值得测试。直接用 Chocolatey 测试它,确保它有效,然后添加 ansible。

    【讨论】:

    • 我再次安装了 firefox,然后运行:- choco feature enable -n autoUninstaller 然后 -choco uninstall firefox。不幸的是,这并没有帮助:firefox 仍然安装在我的 windows 虚拟机中。
    • 我已经手动卸载了firefox,然后用chocolatey再次安装(当新功能autoUninstaller已经开启时),最后用chocolatey卸载。现在它工作正常!
    • 好吧,我尝试通过 Ansible 运行相同的“安装/卸载”例程,但这不起作用。这可能是因为当我用巧克力运行“安装/卸载”时出现了弹出的 Firefox 窗口。像火狐这样的公社包还没有chocolateyUninstall.ps1文件有什么原因吗?
    • @diegus 是的,这听起来是正确的。请注意,在上面,我提到您应该在启用该功能后重新安装。 Chocolatey 会在安装过程中存储一些所需的信息,并且只有在启用该功能时才会这样做。
    • @diegus 你是说通过 Chocolatey 安装/卸载不是静默的吗?即您必须执行一些交互(单击选项等)。既然 Chocolatey 具有自动卸载功能,则无需安装 ChocolateyUninstall.ps1 文件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-30
    • 1970-01-01
    • 2023-04-05
    • 2019-08-20
    • 2016-08-06
    • 1970-01-01
    相关资源
    最近更新 更多