ansible管理Windows

1,安装相关软件
yum install epel-release
yum install ansible
yum install python-pip
pip install pywinrm

 

2,定义windows客户端连接信息
编辑/etc/ansible/hosts,添加客户端主机信息.

[testhost]
192.168.0.2 ansible_ssh_user="administrator" ansible_ssh_pass="Passw0rd" ansible_ssh_port=5986 ansible_connection="winrm" ansible_winrm_server_cert_validation=ignore

●自动设置Windows远端管理(WS-Management,WinRM)下载脚本:
https://github.com/ansible/ansible/blob/devel/examples/scripts/ConfigureRemotingForAnsible.ps1,
下载至本地,右击后选择“使用PowerShell运行”,执行结果没有返回错误即为正常。
※如执行出现“由于此计算机上的网络连接类型之一设置为公用,因此 WinRM防火墙例外将不运行”类似报错,
可在PowerShell中执行命令Enable-PSRemoting – SkipNetworkProfileCheck –Force解决。
 
★管理windows主机,重启系统使用win_reboot模块。
系统重启后,可以继续后续处理逻辑。
- name: Reboot Windows Server
win_reboot:
msg: "Restart the server 10 seconds later" 
post_reboot_delay: 120 
pre_reboot_delay: 10 
test_command: whoami

★ansible中windows文档:
https://docs.ansible.com/ansible/latest/modules/win_regedit_module.html
https://docs.ansible.com/ansible/latest/modules/win_reg_stat_module.html?highlight=win_reg_stat#win-reg-stat-module
win_reboot:https://docs.ansible.com/ansible/latest/modules/win_reboot_module.html
win_psexec:https://docs.ansible.com/ansible/latest/modules/win_psexec_module.html?highlight=win_psexec
posted @ 2019-04-18 22:39  山的那一边  阅读(676)  评论(0)    收藏  举报