通过ansible在Windows上安装python

问题描述 投票:0回答:1

我正在尝试通过 ansible 在 Windows 上安装 python 3。我使用以下任务,但安装没有执行任何操作(除了下载安装程序)。

---

# download works OK
- name: Download python3.11
  ansible.windows.win_get_url:
    url: "https://www.python.org/ftp/python/3.11.5/python-3.11.5-amd64.exe"
    dest: "c:/temp/python-3.11.5-amd64.exe"
  register: python_3_11_downloaded
  when: install_python|bool

# this does not work
- name: Install python3.11
  ansible.windows.win_package:
    path: c:\temp\python-3.11.5-amd64.exe
    product_id: "python_3.11"
    arguments:
      - /quiet
      # - /passive
      # - /unsinstall
  when: install_python|bool


# this does not work either
# - name: Install python3.11
#   ansible.windows.win_shell: "c:/temp/python-3.11.5-amd64.exe /quiet"
#   args:
#     chdir: C:/temp
#   when: install_python|bool
python windows installation ansible
1个回答
0
投票

以下内容对我有用。在 Win Server 2022 上测试,应该适用于 Win 10 / 11。

---
- name: Install Python3 on Windows
  hosts: all
  tasks:
    - name: Install Choco using Powershell
      win_shell: powershell -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))"
    - name: Add Choco to PATH
      win_shell: SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
    - name: Install Python3 using Choco
      win_shell: powershell choco install -y python3
    - name: Verify Chocolatey installation
      win_command: choco --version
    - name: Verify Python installation
      win_command: python --version
© www.soinside.com 2019 - 2024. All rights reserved.