ansible控制windows 2019

Posted wx62e28ac222a20

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 默认都是未启用的状态,先查看状态;如无返回信息,则是没有启动;

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通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盘​​​

[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. . . . . . . . : 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信息

[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的主要内容,如果未能解决你的问题,请参考以下文章

Ansible控制Windows操作步骤

ansible控制windows主机群批量打补丁

ansible控制windows安装及运行error与解决方法

讲真,Ansible 可以管理Windows?

ansible笔记3--playbook windows基础

使用Ansible+实现Windows自动化运维