本文主要介绍在如何使用Ansible管理Windows客户端,Ansible官方提供了一个很方便的安装脚本,对于外网用户来讲安装真的很轻松,惋惜我遇到的问题是如何在内网部署,有相同烦恼的小伙伴不妨参考下html
轻轻松松使用Ansible管理Windows客户端
2018年05月21日 - 初稿git
阅读原文 - https://wsgzao.github.io/post...github
扩展阅读shell
Ansible Windows Guides - http://docs.ansible.com/ansib...windows
Ansible在2.3版本以前对于Windows支持的并不算很友好,从2.4版本开始已经可使用原生模块实现不少需求
Because Windows is a non-POSIX-compliant operating system, there are differences between how Ansible interacts with them and the way Windows works. These guides will highlight some of the differences between Linux/Unix hosts and hosts running Windows.bash
Ansible does not support managing Windows XP or Server 2003 hosts. The supported operating system versions are:
Windows Server 2008
Windows Server 2008 R2
Windows Server 2012
Windows Server 2012 R2
Windows Server 2016
Windows 7
Windows 8.1
Windows 10服务器
https://github.com/ansible/an...
https://github.com/ansible/an...ide
Setting up a Windows Host
http://docs.ansible.com/ansib...post
.NET Framework 4.7.2/4.6.2
https://www.microsoft.com/net...测试
Powershell 3.0
https://www.microsoft.com/en-...
Powershell 5.1
https://www.microsoft.com/en-...
我我的目前的建议是Win7/2008升级至Powershell 3.0,.Net Framework升级至4.6.2,其余状况须要能够参考官方文档后作决定
Ansible Windows Guides - http://docs.ansible.com/ansib...
1.客户端配置windows主机,以管理员身份打开powershell, 并查看当前ps版本
get-host
2.系统自带的powershell版本是2.0,须要更新至powershell 3 以上版本
https://www.microsoft.com/net...
https://www.microsoft.com/en-...
3.安装完重启服务器查看powershell版本
.NET Framework 4.6以上版本没法创建到信任根颁发机构的证书链
缘由:系统缺乏信任 Microsoft Root Certificate Authority 2011 根证书
下载:MicrosoftRootCertificateAuthority2011.cer
http://go.microsoft.com/fwlin...
运行 certmgr.msc
导入证书到“受信任的根证书颁发机构”
# 配置winrm mkdir C:\temp cd C:\temp # 下载ConfigureRemotingForAnsible.ps1 https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1 # 开启WinRM服务 powershell -ExecutionPolicy RemoteSigned .\ConfigureRemotingForAnsible.ps1 -SkipNetworkProfileCheck
# 服务端使用pip安装pywinrm pip install pywinrm # 功能测试,配置ansible控制机 vi /etc/ansible/hosts [windows] 192.168.67.139 [windows:vars] ansible_user=Administrator ansible_password=Admin123 ansible_port=5986 ansible_connection=winrm ansible_winrm_server_cert_validation=ignore # 要注意的是端口方面ssl即https方式的使用5986,http使用5985 # 测试ping通讯 ansible windows -m win_ping # 查看ip地址 ansible windows -m win_command -a "ipconfig"
Windows做为客户端所需的软件包我上传到百度网盘,.Net Framework安装失败提示证书错误记得手动导入MicrosoftRootCertificateAuthority2011.cer
https://pan.baidu.com/s/1JNV2...
powershell -ExecutionPolicy RemoteSigned .ConfigureRemotingForAnsible.ps1 -SkipNetworkProfileCheck