ansible控制windows服务器
1.linux服务器操作:
#根据我安装的过程,问题处理大部分都在处理python的库里面,卸载重装更高版本即可解决
#涉及到安装的库有以下几个
pywinrm,requests-ntlm
#涉及到需要调试升级的库有以下几个(python2 和python3都需调试)
requests-ntlm,cryptography,cffi,paramiko
2.windows服务器操作:
#确保被管控用户在admin组里或直接用admin账户
#确保防火墙无问题
#powershell 管理员启动
#2.1配置ExecutionPolicy
Set-ExecutionPolicy RemoteSigned
#查看配置
Get-ExecutionPolicy -List
#2.2 开启winrm(如已开启可忽略)
winrm quickconfig
#2.3 配置winrm
winrm.cmd set winrm/config/service/auth '@{Basic="true"}'
winrm.cmd set winrm/config/service '@{AllowUnencrypted="true"}'
#查看配置
winrm.cmd enumerate winrm/config/listener
#查看http服务是否开启5985
netsh.exe http show servicestate
3.ansible inventory主机配置:
[windows]
1.1.1.1 ansible_ssh_user="域\用户名" ansible_ssh_pass="登录密码" ansible_ssh_port=5985 ansible_connection=winrm ansible_winrm_server_cert_validation=ignore ansible_winrm_transport=ntlm
4.测试连通性:
ansible -i inventory windows -m win_ping
1.1.1.1 | SUCCESS => {
"changed": false,
"ping": "pong"
}