首页 > 解决方案 > Ansible Windows 部署 - '连接中止。',错误(104,'连接被对等方重置')

问题描述

我在使用 Ansible 在 Windows 2008 服务器上进行部署时遇到问题。我有一个詹金斯管道,它有一个 Ansible 部署阶段,我将文件从清单中拖放到目标服务器上。我已经能够为相当多的服务器成功地做到这一点。但是对于某些服务器,我看到上述错误消息。

这是詹金斯管道的输出

TASK [debug] *******************************************************************
ok: [ch3dw026394.mydomain.com] => {
    "msg": "Hello world!"
}

TASK [Testing connection to windows] *******************************************
fatal: [ch3dw026394.mydomain.com]: UNREACHABLE! => {"changed": false, "msg": "ntlm: ('Connection aborted.', error(104, 'Connection reset by peer'))", "unreachable": true}

这是 win_ping 的 Ansible 剧本模块

  #Testing connection with Target
  - debug: 
    msg: "Testing connection to windows {{ inventory_hostname }}"

  - name: Testing connection to windows
    win_ping: null
    any_errors_fatal: true

我对此进行了大量研究,但以下选项均无效

  1. 在 Windows 2008 服务器上关闭 UAC。

  2. 没用 网上有帖子说这个错误是因为inventory文件不包含FQDN,但是包含IP。我的清单文件包含 FQDN(完全合格的域名),但仍然无法工作 另一篇文章说 vars.yml 中的端口号(5986)应该被注释掉,而是在清单文件中包含主机名:5986。仍然没有工作

  3. 我尝试删除服务器上的侦听器并运行 powershell 脚本以启用 WinRM ( https://github.com/ansible/ansible/blob/devel/examples/scripts/ConfigureRemotingForAnsible.ps1 )。这也没有奏效。使用删除了侦听器

    winrm delete winrm/config/Listener?Address=*+Transport=HTTP
    winrm delete winrm/config/Listener?Address=*+Transport=HTTS
    
  4. 将 WinRM 设置为具有基本 Auth = true 和 AllowUncrypted = true(见下文),但仍然无法正常工作。(请注意,我不必在我的其他 Windows 2008 服务器中执行任何此操作,它工作得非常好)。

    winrm set winrm/config/service '@{AllowUnencrypted= "true"}'
    Set-Item -Path "WSMan:\localhost\Service\Auth\Basic" -Value $true
    

请你能帮我克服这个错误。

提前感谢你的帮助!温暖的问候

标签: ansiblejenkins-pipelinewinrm

解决方案


我在尝试对 Windows 10 节点进行 ping 操作时遇到了类似的问题:

examplenode | UNREACHABLE! => {
    "changed": false, 
    "msg": "ssl: ('Connection aborted.', error(104, 'Connection reset by peer'))", 
    "unreachable": true 

重新颁发证书有助于脚本选项-ForceNewSSLCertConfigureRemotingforAnsible.ps1(在目标节点上)

这发生在我的集合中的两个节点上,我注意到两个节点都在 1607 版本的 Windows 10 上

(如果有人想追查问题)


推荐阅读