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

使用Ansible与WinRM时遇HTTP传输不支持错误求助

解决Ansible WinRM报错"The installed version of WinRM does not support transport(s) ['http']"

问题重现

在Windows 10虚拟机配置了WinRM HTTP监听器和防火墙规则,执行创建桌面文件夹的Playbook时,出现如下错误:

fatal: [192.168.10.42]: FAILED! => {
    "msg": "The installed version of WinRM does not support transport(s) ['http']"
}

相关配置

Playbook内容

---
- name: Create Folder on Windows Desktop Using WinRM
  hosts: winrm
  gather_facts: no
  vars: 
    folder_name: Anisble_Test

  tasks:
    - name: create folder on desktop
      win_file:
        path: "C:\\Users\\Admin\\Desktop\\{{ folder_name }}"
        state: directory
      register: result

    - name: Print Result
      debug:
        vars: result    

Ansible主机配置

[winrm]
192.168.10.42 ansible_connection=winrm ansible_winrm_authentication=basic ansible_winrm_transport=http ansible_winrm_port=5985 ansible_user=Admin ansible_password=

Windows WinRM监听器配置

PS C:\WINDOWS\system32> winrm enumerate winrm/config/Listener
Listener
    Address = *
    Transport = HTTP
    Port = 5985
    Hostname
    Enabled = true
    URLPrefix = wsman
    CertificateThumbprint
    ListeningOn = 127.0.0.1, 169.254.93.238, 192.168.10.42, 192.168.80.42, ::1, fe80::e977:b53a:55ce:71ef%17

已完成排查

  • Linux主机通过nc测试5985端口连通性正常
  • 已安装pywinrm 0.3.0

解决思路

1. 升级pywinrm版本

pywinrm 0.3.0版本较老,对http transport的支持存在兼容性问题。执行以下命令升级到最新稳定版:

pip install --upgrade pywinrm

建议升级到0.4.0及以上版本,该版本修复了多个WinRM传输相关的兼容性问题。

2. 修正ansible_winrm_transport参数配置

在Ansible主机配置中,ansible_winrm_transport=http的写法可能不被旧版pywinrm支持,尝试改用以下两种配置之一:

  • 移除ansible_winrm_transport参数,让Ansible自动协商合适的传输方式
  • 将参数值改为basic(匹配已配置的ansible_winrm_authentication=basic),修改后的主机配置:
[winrm]
192.168.10.42 ansible_connection=winrm ansible_winrm_authentication=basic ansible_winrm_transport=basic ansible_winrm_port=5985 ansible_user=Admin ansible_password=

3. 检查Windows端WinRM服务认证配置

虽然监听器已配置HTTP,但需确认WinRM服务是否允许基本认证:
在Windows虚拟机中执行以下PowerShell命令:

winrm get winrm/config/service/auth

确保Basic = true,如果不是,执行以下命令开启:

winrm set winrm/config/service/auth @{Basic="true"}

4. 检查Ansible版本兼容性

过旧的Ansible版本与新版WinRM服务或pywinrm存在兼容性问题。执行ansible --version查看版本,建议升级到2.10及以上版本:

sudo apt update && sudo apt install --upgrade ansible

5. 直接验证WinRM连接

使用winrm命令直接测试Linux到Windows的连接,排除Ansible层面的问题:

winrm -r:http://192.168.10.42:5985/wsman -u:Admin -p:你的密码 enumerate winrm/config/service

如果该命令能正常返回结果,说明WinRM基础连接正常,问题集中在Ansible或pywinrm的配置/版本上。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 10:00:22