本文主要介紹在如何使用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