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

使用Ansible-Tower连接Windows机器遇SSL认证失败及连接方式异常

解决Ansible Tower连接Windows时优先使用SSH而非WinRM的问题

我之前踩过一模一样的坑!你遇到的ssl: the specified credentials were rejected by the server错误,加上系统仍尝试用SSH连接,大概率是WinRM相关变量没正确生效,或者有优先级更高的配置覆盖了你的设置。试试下面这些排查和修复步骤:

1. 确认Inventory变量的作用范围

确保你是在目标主机或者对应主机组的Variables里配置的WinRM参数,而不是全局Inventory的顶层变量。主机级别的变量优先级最高,直接给Windows主机单独配置是最稳妥的方式:

  • 进入Tower的Inventory -> 选择你的主机 -> 切换到Variables标签
  • 确认配置的变量是:
    ansible_connection: winrm
    ansible_winrm_port: 5986
    ansible_winrm_server_cert_validation: ignore
    ansible_winrm_transport: ntlm  # 这个是关键!Windows默认用NTLM认证
    

2. 在Playbook中强制指定连接配置

有时候Tower的Inventory变量可能因为优先级问题没被正确加载,你可以直接在Playbook的hosts块里硬编码这些变量,强制Ansible使用WinRM:

- name: 测试Windows连接
  hosts: your_windows_hosts
  vars:
    ansible_connection: winrm
    ansible_winrm_port: 5986
    ansible_winrm_server_cert_validation: ignore
    ansible_winrm_transport: ntlm
    ansible_user: "{{ your_windows_admin_user }}"
    ansible_password: "{{ your_windows_admin_pass }}"
  tasks:
    - name: 执行WinRM ping测试
      win_ping:

3. 检查Tower主机的独立配置

进入Tower的主机详情页,查看Variables标签里有没有误配置ansible_connection: ssh——主机级别的变量会覆盖组和全局Inventory的配置,如果这里有SSH的配置,肯定会优先走SSH。

4. 先在Tower服务器上手动测试WinRM连通性

排除Tower平台的问题,直接在Tower服务器上用ansible命令测试:

ansible your_windows_host -m win_ping -i /path/to/your/inventory \
  -e "ansible_connection=winrm ansible_winrm_port=5986 ansible_winrm_server_cert_validation=ignore ansible_winrm_transport=ntlm ansible_user=admin ansible_password=your_pass"

如果这个命令能成功,说明WinRM本身是通的,问题出在Tower的变量或凭证配置上;如果失败,就要检查Windows端的WinRM配置:

  • 确认Windows开启了WinRM HTTPS监听(端口5986)
  • 防火墙允许5986端口的入站流量
  • 所用的Windows用户有远程管理权限

5. 检查Tower的凭证类型

一定要选Windows Machine Credential类型的凭证,而不是SSH凭证!如果选错了,Tower会用SSH的凭证去尝试WinRM连接,自然会出现凭证被拒绝的错误。

补充说明

ssl: the specified credentials were rejected by the server这个错误除了连接方式不对,常见原因还有:

  • 未指定正确的WinRM认证方式(比如默认用了basic而Windows没开启)
  • Windows用户密码过期或权限不足
  • WinRM的SSL证书配置有问题(不过你已经加了ignore验证,这个可能性较低)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.22 08:08:48