在Ansible中,如何连接到Windows主机?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在Ansible中,如何连接到Windows主机?相关的知识,希望对你有一定的参考价值。

我一直坚持使用Ansible窗口模块。我只是想ping Windows机器。但我得到'连接超时'

主机

[windows]
192.168.1.13

group_vars / windows.yaml

ansible_user: raja
ansible_password: myPassword
ansible_port: 5986
ansible_connection: winrm
ansible_winrm_server_cert_validation: ignore

当我跑:ansible windows -vvv -i hosts -m win_ping

Using /etc/ansible/ansible.cfg as config file
<192.168.1.13> ESTABLISH WINRM CONNECTION FOR USER: raja on PORT 5986 TO 192.168.1.13
192.168.1.13 | UNREACHABLE! => {
"changed": false,
"msg": "ssl: HTTPSConnectionPool(host='192.168.1.13', port=5986): Max retries exceeded with url: /wsman (Caused by ConnectTimeoutError(<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7fcb12024a90>, 'Connection to 192.168.1.13 timed out. (connect timeout=30)'))",
"unreachable": true
}

但是我可以使用ping 192.168.1.13 ping那个windows机器

答案

您需要准备Windows机器以进行PowerShell远程管理,否则ansible将无法连接到它。要使大多数功能正常工作,您至少需要PowerShell 3.0 installed(仅在Windows 7 SP1或Windows Server 2008 SP1及更高版本上支持),并且还运行this script,它不仅会启用WinRM,还会为其安装一些必要的证书。与工作的联系。

下载qazxsw poi文件后,命令行中的以下命令应该完成以下任务:

powershell.exe -File ConfigureRemotingForAnsible.ps1

以上是关于在Ansible中,如何连接到Windows主机?的主要内容,如果未能解决你的问题,请参考以下文章