ansible管理window
設置window以支持遠程執行命令
=======================================
升級powershell到3.0+
----------------------------------
1. 安裝.NET Framework 4.5
http://download.microsoft.com/download/B/A/4/BA4A7E71-2906-4B2D-A0E1-80CF16844F5F/dotNetFx45_Full_x86_x64.exe
2. 更改powershell策略為remotesigned
set-executionpolicy remotesigned
3. 升級powershell為3.0+
執行腳本:upgrade_to_ps3.ps1
4. 查看版本
$PSVersionTable.PSVersion
配置Winrm
------------------------
1.開啟winrm service
執行:winrm enumerate winrm/config/listener
如果沒有返回那winrm service就沒有啟動,默認是不啟動的。
2.對winrm service進行基礎配置
執行:winrm quickconfig
3.查看winrm service listener
執行:winrm e winrm/config/listener
4.為winrm service配置auth
執行:winrm set winrm/config/service/auth ‘@{Basic="true"}‘
5.為winrm service 配置加密方式為允許非加密
執行:winrm set winrm/config/service ‘@{AllowUnencrypted="true"}‘
6. 在cmd下執行:powershell.exe -File ConfigureRemotingForAnsible.ps1
配置winrm及https證書信息
參考:http://www.cnblogs.com/kingleft/p/6391652.html
http://zengestudy.blog.51cto.com/1702365/1865946
ansible主機配置
-----------------------------
1. ansible主機安裝pywinrm模塊
pip install pywinrm
2. vim /etc/ansible/hosts
[windows]
192.168.10.112
3. vim /etc/ansible/group_vars
ansible_user: "Administrator"
ansible_password: "[email protected]"
ansible_ssh_port: 5986
ansible_connection: winrm
ansible_winrm_server_cert_validation: ignore
3. 執行:ansible windows -m win_ping
192.168.10.112 | SUCCESS => {
"changed": false,
"ping": "pong"
}
4. 測試執行命令
ansible windows -m win_command -a "sed -ri "s/app-.*.apk/app-21.apk/" \"D:\www\HECBET Entrance\Entrance.config\" "
Window下使用linux命令
================================
1. 下載gunwin32
https://sourceforge.net/projects/getgnuwin32/
2. 安裝gunwin32
下載完成exe安裝包後,點擊安裝,安裝完成進入安裝目錄,已管理員運行:download.bat
運行完成後,接著運行:install.bat
3. 設置環境變量
在path變量中加入安裝目錄下的bin目錄,如C:\GnuWin32\bin目錄
4. 測試命令
新打開cmd窗口
subst w: "D:\www\HECBET Entrance" && sed -ri "s/app-.*.apk/app-12.apk/" w:\Entrance.config
如果命令執行成功,並查看文件有修改,那麽gunwin32就安裝成功
ansible管理window