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

raj*_*alx 6 ansible ansible-2.x

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

主机

[windows]
192.168.1.13
Run Code Online (Sandbox Code Playgroud)

group_vars/windows.yaml

ansible_user: raja
ansible_password: myPassword
ansible_port: 5986
ansible_connection: winrm
ansible_winrm_server_cert_validation: ignore
Run Code Online (Sandbox Code Playgroud)

我跑的时候: 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
}
Run Code Online (Sandbox Code Playgroud)

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

Szt*_*upY 13

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

下载ConfigureRemotingForAnsible.ps1文件后,命令行中的以下命令应该完成以下任务:

powershell.exe -File ConfigureRemotingForAnsible.ps1