其他分享
首页 > 其他分享> > ansible小抄

ansible小抄

作者:互联网

获取window主机信息:
ansible windows -m setup

执行ps脚本:
ansible windows -m script -a "E://test.ps1"

查看文件状态:
ansible windows -m win_stat -a "path='C://Windows/win.ini'"

结束程序:
ansible windows-m raw -a "taskkill /F /IM QQ.exe /T"

如果window主机传回来的中文是乱码,则修改ansible控制机上的python编码:
sed -i "s#tdout_buffer.append(stdout)#tdout_buffer.append(stdout.decode('gbk').encode('utf-8'))#g" /usr/lib/python2.6/site-packages/winrm/protocol.py
sed -i "s#stderr_buffer.append(stderr)#stderr_buffer.append(stderr.decode('gbk').encode('utf-8'))#g" /usr/lib/python2.6/site-packages/winrm/protocol.py

指定配置文件获取win网卡信息
ansible -i win_hosts windows -m raw -a "ipconfig"

使用默认的配置文件获取网卡信息
ansible windows -m raw -a "ipconfig"

拷贝文件到远程Windows主机
ansible windows -m win_copy -a 'src=/etc/passwd dest=F:\file\passwd'

ansible windows -m win_copy -a "src=/usr/local/src/PayChannels20.35.zip dest=D:\Tomcat8630\webapps\PayChannels20.35.zip"

ansible windows -m win_copy -a "src=/usr/local/src/SupplierPay.zip dest=D:\SupplierPay.zip

将.zip解压到远程Windows主机,远程主机上必须存在需要解压的源文件
ansible windows -m win_unzip -a"creates=no src=D:\Tomcat8620\webapps\PayChannels-8630.zip dest=D:\Tomcat8620\webapps"
解压到D盘:ansible windows -m win_unzip -a"creates=no src=D:\SupplierPay.zip dest=D:"


重启远程windows主机的服务
ansible windows -m win_service -a "name=Tomcat8630 state=restarted"

重启node.js(.bat命令)
ansible windows -m win_command -a "chdir=D:\SupplierPay .\http_restart.bat"

执行win_command模块命令
启动redis
ansible windows -m win_command -a "chdir=D:\Redis server-start.bat "

ansible win -m win_command -a "chdir=C:\ a.bat "
ps:"chdir=C:\ a.bat " 之前有空格

删除文件或者目录
ansible windows -m win_file -a "dest=D:\Tomcat8630\log\ state=absent"
ansible windows -m win_file -a "dest=D:\Tomcat8630\logs\ state=absent"

创建用户
ansible windows -m win_user -a "name=aa passwd=123456"

创建一个名叫user1的管理员用户,要求能够远程访问
ansible windows -m win_user -a "name=user1 password=123 groups='Administrators,Remote Desktop Users'"

重启的第一种方式
ansible windows -m win_shell -a "shutdown -r -t 1"

重启的第二种方式
ansible windows -m win_reboot

获取ip地址
ansible windows -m raw -a "ipconfig"

获取身份
ansible windows -m win_command -a "whoami"

移动文件
ansible windows -m raw -a "cmd /c 'move /y D:\Ansible\product\DBFPlus.exe D:\Ansible\back\'"

移动文件目标端也需要制定到文件,而不能只制定到所在目录位置
ansible windows -m raw -a "cmd /c 'move /y D:\Ansible\product D:\Ansible\back'"
移动文件夹源端和目标端目录都不能带反斜杠/。且将源的整个目录移到目的端目录里。

创建文件夹
ansible windows -m raw -a "md d:\Ansible\justin"
ansible 192.168.2.2 -m win_file -a 'path=D:\\test state=directory'

删除文件或目录
ansible windows -m win_file -a "path=d:\Ansible\justin state=absent"

结束某程序
ansible windows -m raw -a "taskkill /F /IM snmp.exe /T"

文件传输
ansible windows -m win_copy -a 'src=/app/svn/127_Client/118919/zjcfg.zip dest=D:\soft\'

修改密码
ansible windows -m win_user -a "name=Administrator update_password=always password="Admin~123""

  

标签:src,zip,windows,win,小抄,raw,ansible
来源: https://www.cnblogs.com/security-guard/p/15748256.html