ansible控制windows 2019

网友投稿 1420 2022-10-08

ansible控制windows 2019

ansible控制windows 2019

1.在ansible端安装pywinrm

[root@ansible ansible]# wget -O /etc/yum.repos.d/epel.repo ansible]# yum -y install python-pip[root@ansible ansible]# pip install pywinrm

2.配置/etc/ansible/hosts文件,加入需要被接管的windows系统

[windows]192.168.56.105 ansible_ssh_user="Administrator" ansible_ssh_pass="S@34eapt12" ansible_ssh_port=5985 ansible_connection="winrm" ansible_winrm_server_cert_validation=ignore

3.在windows服务器设置winrm在windows开启winrmwinrm service 默认都是未启用的状态,先查看状态;如无返回信息,则是没有启动;

winrm enumerate winrm/config/listener

针对winrm service 进行基础配置:

winrm quickconfig

查看winrm service listener:

winrm e winrm/config/listener

为winrm service 配置auth:

winrm set winrm/config/service/auth @{Basic=“true”}

为winrm service 配置加密方式为允许非加密:

winrm set winrm/config/service @{AllowUnencrypted=“true”}

4.测试ansible是否可用Ping通windowsansible]# ansible windows -m win_ping192.168.56.105 | UNREACHABLE! => { "changed": false, "msg": "plaintext: the specified credentials were rejected by the server", "unreachable": true}

5.使用ansible执行命令拷贝/etc/hosts文件至windows C盘​

[root@ansible ansible]# ansible windows -m win_copy -a "src=/etc/hosts dest=c:/ owner=administrator"192.168.56.105 | CHANGED => { "changed": true, "checksum": "c57fa92967f442aefae1b01f907318e9f658b271", "dest": "c://hosts", "operation": "file_copy", "original_basename": "hosts", "size": 181, "src": "/etc/hosts"}

6.使用ansible获取ipconfig信息

[root@ansible ansible]# ansible -i hosts windows -m win_shell -a "ipconfig /all"192.168.56.105 | CHANGED | rc=0 >>Windows IP Configuration Host Name . . . . . . . . . . . . : WIN-SU8A4VM4R4L Primary Dns Suffix . . . . . . . : Node Type . . . . . . . . . . . . : Hybrid IP Routing Enabled. . . . . . . . : No WINS Proxy Enabled. . . . . . . . : NoEthernet adapter 锟斤拷太锟斤拷: Connection-specific DNS Suffix . : Description . . . . . . . . . . . : Intel(R) PRO/1000 MT Desktop Adapter Physical Address. . . . . . . . . : 08-00-27-8C-15-66 DHCP Enabled. . . . . . . . . . . : No Autoconfiguration Enabled . . . . : Yes Link-local IPv6 Address . . . . . : fe80::ad24:705f:d4ba:6eef%9(Preferred) IPv4 Address. . . . . . . . . . . : 192.168.56.105(Preferred) Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : 192.168.56.1 DHCPv6 IAID . . . . . . . . . . . : 67633191 DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-29-0F-11-3B-08-00-27-8C-15-66 DNS Servers . . . . . . . . . . . : fec0:0:0:ffff::1%1 fec0:0:0:ffff::2%1 fec0:0:0:ffff::3%1 NetBIOS over Tcpip. . . . . . . . : Enabled

7.使用ansible获取hotname信息

[root@ansible ansible]# ansible -i hosts windows -m win_shell -a "hostname"192.168.56.105 | CHANGED | rc=0 >>WIN-SU8A4VM4R4L

ansible

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Pcs安装
下一篇:垃圾分类小程序
相关文章

 发表评论

暂时没有评论,来抢沙发吧~