Ansible管理Windows
Ansible安装参考:
http://www.360doc.com/content/22/0129/08/65762893_1015313555.shtml
Windows服务器配置:
set-psremoting -force
winrm set winrm/config/service/auth '@{Basic="true"}'
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
Ansible服务器上编写testw,内容如下:
[windows] 10.10.20.20 ansible_ssh_user="test\administrator" ansible_ssh_pass="11@2022" ansible_ssh_port="5985" ansible_connection="winrm" ansible_winrm_transport=ntlm ansible_winrm_server_cert_validation=ignore
另一种写法:
[windows] 10.10.0.9 10.10.0.5 [windows:vars] ansible_user="domain\admin" ansible_password="password" ansible_port=5985 ansible_connection=winrm ansible_winrm_transport=ntlm ansible_winrm_server_cert_validation=ignore
运行ansible命令:
ansible -i testw windows -m win_ping
如果未添加 ansible_winrm_transport=ntlm,则会报错,提示“plaintext: the specified credentials were rejected by the server”
ansible其他命令:
ansible -i testw windows2 -m win_shell -a "hostname"
ansible windows -m win_copy -a "src=/etc/hosts dest=c:/ owner=administrator" #拷贝