admin 管理员组文章数量: 887016
1.在ansible端安装pywinrm
[root@ansible ansible]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun/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 默认都是未启用的状态,先查看状态;如无返回信息,则是没有启动;
winrm enumerate winrm/config/listener
针对winrm service 进行基础配置:https://wwwdba/hbhe0316/article/5015
winrm quickconfig
查看winrm service listener:
https://wwwdba/hbhe0316/article/5015winrm 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://wwwdba/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://wwwdba/hbhe0316/article/5015https://wwwdba/hbhe0316/article/5015
https://wwwdba/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://wwwdba/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://wwwdba/hbhe0316/article/5015
https://wwwdba/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
版权声明:本文标题:ansible控制windows 2019 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1728030506h1189945.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论