Ansible管理windows 安装步骤
1、系统要求
1,管理机必须是Linux系统且需预安装Python Winrm 模块(本次使用Linux版本是CentOS Linux release 7.3.1611 (Core))。
2,底层通讯认证一些基于Kerberos ,Windows使用的链接工具为PowerShell而非SSH,我这里测试的Windows版本是win7-32bit专业版。
3,远程主机PowerShell版本为3.0+,Management Framework版本为3.0+。
4,须要安装自动设置Windows远端管理,英文全称WS-Management(WinRM)
2、在服务器端安装ansible和相关的模块
安装前准备的工做:
1,[root@Centos7_3 ~]# yum -y install python-pip python-devel
解决没有安装python-pip故障
首先下载并安装setuptools
[root@Centos7_3 ~]# wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py
[root@Centos7_3 ~]# sudo python ez_setup.py --insecure
[root@Centos7_3 ~]# wget https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz#md5=35f01da33009719497f01a4ba69d63c9
[root@Centos7_3 ~]#tar -xf pip-9.0.1.tar.gz
[root@Centos7_3 ~]#cd pip-8.0.0
[root@Centos7_3 ~]#python setup.py install
[root@Centos7_3 ~]#yum install gcc glibc-devel zlib-devel
[root@Centos7_3 ~]#yum install rpm-build openssl-devel -y
2,正式安装ansible
[root@Centos7_3 ~]#yum -y install ansible
[root@Centos7_3 ~]# ansible --version
3、在windows端先安装.NET3.0及以上版本。
4、检查你的powershell 版本是否是3.0不是请升级到3.0版本。
若是不是能够用脚本进行升级;
https://github.com/cchurch/ansible/blob/devel/examples/scripts/upgrade_to_ps3.ps1
具体作法是,打开上述连接,下载保存在TXT文本后改文件名为upgrade_to_ps3.ps1
而后使用powershell来运行脚原本升级,升级后从新启动windows系统。python
5、设置你的powershell能够远程执行,在注册表改属性值。具体目录以下。
1,修改注册表信息:git
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\ScriptedDiagnostics
2,自动设置Windows远端管理(WS-Management,WinRM)下载补丁脚本:
https://github.com/ansible/ansible/blob/devel/examples/scripts/ConfigureRemotingForAnsible.ps1 ;具体作法是,打开上述连接,下载保存在TXT文本后改文件名为ConfigureRemotingForAnsible.ps1具体操做步骤和上面的相似;
3,每每在上一步操做过程当中有不少问题,你还须要在Poweshell下面配置winrm:github
winrm set winrm/config/service ‘@{AllowUnencrypted="true"}‘
winrm set winrm/config/service/auth ‘@{Basic="true"}‘
6、在Linux配置host文件
1,[root@Centos7_3 ~]#vim /etc/ansible/hosts
在最后一行添加一个windows模块主机组
[windows]
192.168.0.36 ansible_ssh_user="Root" ansible_ssh_pass="123456" ansible_ssh_port=5985 ansible_connection="winrm"
2,在执行命令测试网络连通性
[root@Centos7_3 ansible]# ansible windows -m win_ping
3,测试上传一个WinRAR文件到windows客户端
[root@Centos7_3 ansible]# ansible windows -m win_copy -a 'src=/data/winrar_x64_5.40.0.0.exe dest=D:\ISO\’
7、我在测试的时候遇到2个小问题就一个是配置winrm时候须要时专用网络,若是你的计算机不是专用网络请改成一下域网路和家庭网络只要不是公共网络就能够哦。
还有就是使用ansible windows -m win_ping 链接客户端提示链接被拒绝,这里我是改变了端口来解决的,在编辑vim /etc/ansible/hosts文件下的端口,原来是5986把它改为5985便可使用。shell