【问题标题】:ansible win exe install 32/64 bitansible win exe 安装 32/64 位
【发布时间】:2019-04-16 05:39:33
【问题描述】:

有人可以请教。 我正在做的是在远程 Windows 机器上下载 phpstorme 并安装它,但它安装了 32 位,我如何强制 ansible 安装 64 位? 先感谢您。下面的剧本。

---
- hosts: win
  gather_facts: true
#  ansible_connection: winrm
  tasks:
    name: Download  application
    win_get_url:
      url: https://download-cf.jetbrains.com/webide/PhpStorm-2018.2.5.exe
      dest: 'C:\Users\administrator\Downloads'
    name: Install application
    win_package:
      path: 'C:\Users\administrator\Downloads\PhpStorm-2018.2.5.exe'
      product_id: "PhpStorm"
      arguments: /S /install
      state: present

【问题讨论】:

    标签: windows automation ansible installation exe


    【解决方案1】:

    Ansible 自己不知道在哪里下载 32 位版本或 64 位版本。如果您只有 64 位目标机器,只需指定 64 位可执行文件的路径即可。

    如果你有这两种架构,你可以编写两个单独的任务,并使用与ansible_architecture变量关联的when关键字,其值可以是32 bits64 bits,见下文。

    此外,您可能不需要进行两次单独的下载和安装操作,因为 win_package 可以同时完成这两项操作。

    ---
    - hosts: win
      gather_facts: true
    #  ansible_connection: winrm
      tasks:
    
        name: Download and install application, 32 bit case
        win_package:
          path: 'https://download-cf.jetbrains.com/[path-of-the-32-bits-edition].exe'
          product_id: "PhpStorm"
          arguments: /S /install
          state: present
        when: ansible_architecture == "32 bits"
    
        name: Download and install application, 64 bit case
        win_package:
          path: 'https://download-cf.jetbrains.com/[path-of-the-64-bits-edition].exe'
          product_id: "PhpStorm"
          arguments: /S /install
          state: present
        when: ansible_architecture == "64 bits"
    

    为了更简单,你也可以使用Chocolatey,它提供了一个phpstorm包,见https://chocolatey.org/packages/phpstorm

    Ansible 能够使用 win_chocolatey 安装 Chocolatey 包,请参阅 https://docs.ansible.com/ansible/latest/modules/win_chocolatey_module.html

    使用 Chocolatey 包的优点是多方面的,例如依赖关系管理、自动更新版本(如果需要,也可以保持在指定版本)……

    在这里,您的 playBook 可以简化为:

    ---
    - hosts: win
      gather_facts: true
    #  ansible_connection: winrm
      tasks:
        - name: choco install phpstorm
          win_chocolatey:
            name: phpstorm
            state: latest
    

    【讨论】:

      猜你喜欢
      • 2013-06-22
      • 2016-01-29
      • 2017-08-26
      • 1970-01-01
      • 1970-01-01
      • 2013-01-23
      • 1970-01-01
      • 1970-01-01
      • 2014-03-14
      相关资源
      最近更新 更多