ansible管理window

設置window以支持遠程執行命令
=======================================html

升級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.exelinux

2. 更改powershell策略爲remotesigned
set-executionpolicy remotesignedshell

3. 升級powershell爲3.0+
執行腳本:upgrade_to_ps3.ps1vim

4. 查看版本
$PSVersionTable.PSVersionwindows


配置Winrm
------------------------
1.開啓winrm service
執行:winrm enumerate winrm/config/listener
若是沒有返回那winrm service就沒有啓動,默認是不啓動的。app

2.對winrm service進行基礎配置
執行:winrm quickconfigssh

3.查看winrm service listener
執行:winrm e winrm/config/listener測試

4.爲winrm service配置auth
執行:winrm set winrm/config/service/auth '@{Basic="true"}'ui

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: "Lishen@123"
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就安裝成功

相關文章
相關標籤/搜索