Ansible批量远程管理Windows主机(部署与配置)

Ansible批量远程管理Windows主机(部署与配置)

一、Linux管理服务器需安装pip、pywinrm插件

(1)配置阿里镜像源
[[email protected] Desktop]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[[email protected] yum.repos.d]# sed -i ‘s/$releasever/7/’ CentOS-Base.repo
[[email protected] yum.repos.d]# yum clean all

(2)安装ansible软件包
[[email protected] ~]# yum install - y ansible

(3)安装pip和pywinrm
[[email protected] ~]# yum install -y epel-release
[[email protected] ~]# yum install python-pip
[[email protected] ~]# pip install pywinrm

(4)配置host文件
[[email protected] ~]# vim /etc/ansible/hosts
[win]
192.168.10.15 ansible_ssh_user=“Administrator” ansible_ssh_pass=“Linqi777” ansible_ssh_port=5985 ansible_connection=“winrm” ansible_winrm_server_cert_validation=ignore

二、windows客户端配置

(1)查看powershell的版本 大于3.0以上就可以
get-host
Ansible批量远程管理Windows主机(部署与配置)
(2)开启winrm server
winrm quickconfig
Ansible批量远程管理Windows主机(部署与配置)
(3)查看状态
winrm enumerate winrm/config/listener
Ansible批量远程管理Windows主机(部署与配置)
(4)为winrm server 配置auth和配置加密方式为允许非加密
winrm set winrm/config/service/auth ‘@{Basic=“true”}’

winrm set winrm/config/service ‘@{AllowUnencrypted=“true”}’
Ansible批量远程管理Windows主机(部署与配置)

三、测试

(1)Ping模块测试如下:
Ansible批量远程管理Windows主机(部署与配置)
(2)copy 模块测试如下:
[[email protected] pip-8.1.0]# ansible win -m win_copy -a “src=/etc/passwd dest=C:\passwd”
Ansible批量远程管理Windows主机(部署与配置)
验证:
Ansible批量远程管理Windows主机(部署与配置)