1.确认powershell的版本,必须是3.0以上
$PSVersionTable.PSVersion
2.确认winrm是否开启
命令:winrm quickconfig
3.在windows配置winrm
执行命令:
winrm set
winrm
/config/service/auth
'@{Basic="true"}'
winrm set
winrm
/config/service
'@{AllowUnencrypted="true"}'
4.在ansible主机上安装pywinrm模块:
首先安装pip(centos7上)
安装epel源:yum -y install epel-release
安装pip:yum -y install python-pip
直接更新pip版本:pip install --upgrade pip
利用pip安装pywinrm:pip install
http:
//github
.com
/diyan/pywinrm/archive/master
.zip
验证是否成功:pip list | grep pywinrm
5.测试ansible能否控制windows
配置ansible的hosts文件:vim /etc/ansible/hosts
增加一个新的组
[win]
192.168.7.118
编辑yml文件vim
/etc/ansible/group_vars/win
.yml
ansible_user: administrator
ansible_password:
"123456"
ansible_ssh_port: 5986
ansible_connection: winrm
ansible_winrm_server_cert_validation: ignore
执行ansible命令,测试是否能通:
ansible win -m win_ping