ansible控制windows 2019

1.在ansible端安装pywinrm

[root@ansible ansible]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@ansible 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开启winrm
winrm service 默认都是未启用的状态,先查看状态;如无返回信息,则是没有启动;

https://www.cndba.cn/hbhe0316/article/5015
winrm enumerate winrm/config/listener

针对winrm service 进行基础配置:https://www.cndba.cn/hbhe0316/article/5015

winrm quickconfig

查看winrm service listener:

https://www.cndba.cn/hbhe0316/article/5015
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通windowshttps://www.cndba.cn/hbhe0316/article/5015

[root@ansible ansible]# ansible windows -m win_ping
192.168.56.105 | UNREACHABLE! => {
    "changed": false, 
    "msg": "plaintext: the specified credentials were rejected by the server", 
    "unreachable": true
}

5.使用ansible执行命令拷贝/etc/hosts文件至windows C盘https://www.cndba.cn/hbhe0316/article/5015https://www.cndba.cn/hbhe0316/article/5015

https://www.cndba.cn/hbhe0316/article/5015
[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信息https://www.cndba.cn/hbhe0316/article/5015

[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. . . . . . . . : No

Ethernet 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信息https://www.cndba.cn/hbhe0316/article/5015

https://www.cndba.cn/hbhe0316/article/5015
[root@ansible ansible]# ansible -i hosts windows -m win_shell -a "hostname"
192.168.56.105 | CHANGED | rc=0 >>
WIN-SU8A4VM4R4L

版权声明:本文为博主原创文章,未经博主允许不得转载。

ansible

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值