设置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: "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:wwwHECBET EntranceEntrance.config" "
Window下使用linux命令
================================
1. 下载gunwin32
https://sourceforge.net/projects/getgnuwin32/
2. 安装gunwin32
下载完成exe安装包后,点击安装,安装完成进入安装目录,已管理员运行:download.bat
运行完成后,接着运行:install.bat
3. 设置环境变量
在path变量中加入安装目录下的bin目录,如C:GnuWin32in目录
4. 测试命令
新打开cmd窗口
subst w: "D:wwwHECBET Entrance" && sed -ri "s/app-.*.apk/app-12.apk/" w:Entrance.config
如果命令执行成功,并查看文件有修改,那么gunwin32就安装成功