You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Salt状态文件中定义Windows平台Python安装包的名称以避免执行失败?

Fixing Salt State Failure After Successful Python 3 Installation on Windows

The issue you're facing stems from Salt's pkg.installed state relying on exact matches with Windows' "Add/Remove Programs" registry entries—and Python 3's installer splits the installation into multiple discrete components, each with its own unique name and version entry. Even when you pick one of these components, subtle formatting or naming mismatches can cause Salt to incorrectly flag a failure, even though Python installed successfully.

Here are two reliable solutions to resolve this:

Solution 1: Exact Match with a Guaranteed Core Component

First, confirm the exact DisplayName and DisplayVersion directly from the Windows registry (this is the source Salt uses to verify installation):

  1. On your target Windows node, open Registry Editor (regedit.exe).
  2. For 64-bit Python on a 64-bit system, navigate to HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall; for 32-bit Python, use HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall.
  3. Locate the registry keys tied to Python 3.8.3, then copy the exact DisplayName and DisplayVersion from a core component like Python 3.8.3 Executables (64-bit)—this component is always installed with the base Python package.

Update your SLS file with these precise values:

{% set version = "3.8.3150.0" %}
{% set SOURCE_PATH = 'http://local-nas/' %}
{% if grains['cpuarch'] == 'AMD64' %}
{% set PROGRAM_FILES = "%ProgramFiles(x86)%" %}
{% set full_name = "Python 3.8.3 Executables (64-bit)" %}
{% else %}
{% set PROGRAM_FILES = "%ProgramFiles%" %}
{% set full_name = "Python 3.8.3 Executables" %}
{% endif %}
python3:
  '{{ version }}':
    full_name: '{{ full_name }}'
    installer: '{{ SOURCE_PATH }}/python-3.8.3-amd64.exe'
    install_flags: '/quiet InstallAllUsers=1 PrependPath=1'
    uninstaller: '{{ PROGRAM_FILES }}\Python 3.8\uninstall.exe'
    uninstall_flags: '/quiet'
    msiexec: False

Solution 2: Custom Verification (Bypass Pkg Registry Checks)

If exact registry matching still fails, skip Salt's built-in pkg verification and use a custom check to confirm Python is installed correctly. This method is more robust for split-component installers like Python:

{% set SOURCE_PATH = 'http://local-nas/' %}
{% if grains['cpuarch'] == 'AMD64' %}
{% set PROGRAM_FILES = "%ProgramFiles(x86)%" %}
{% set installer = 'python-3.8.3-amd64.exe' %}
{% set python_exe = 'C:\\Program Files (x86)\\Python 3.8\\python.exe' %}
{% else %}
{% set PROGRAM_FILES = "%ProgramFiles%" %}
{% set installer = 'python-3.8.3.exe' %}
{% set python_exe = 'C:\\Program Files\\Python 3.8\\python.exe' %}
{% endif %}
python3_install:
  pkg.installed:
    - name: Python 3.8.3
    - installer: '{{ SOURCE_PATH }}/{{ installer }}'
    - install_flags: '/quiet InstallAllUsers=1 PrependPath=1'
    - uninstaller: '{{ PROGRAM_FILES }}\\Python 3.8\\uninstall.exe'
    - uninstall_flags: '/quiet'
    - msiexec: False
    # Skip Salt's default pkg version check
    - skip_verify: True
    # Custom check: Confirm python.exe exists and reports the correct version
    - unless: |
        {{ python_exe }} --version 2>&1 | findstr /C:"3.8.3"

This approach first checks if python.exe exists and returns the correct version. If the check passes, Salt skips the installation entirely—avoiding false failure reports even if the registry entries don't match Salt's expectations.

内容的提问来源于stack exchange,提问作者Yukpun

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 22:58:09