[转帖]Ansible管理windows集群
Ansible管理windows集群
http://www.cnblogs.com/Dev0ps/p/10026908.html 写的挺好的 我关注点还是不够好呢
最近公司新项目需要安装400+windows server 2012系统的工作站,想着怎么能像linux下运用ansible批量管理,linux就很简单了有ssh服务
但是下却没这么简单,但还是有办法那就是Powershell。
Ansible可用于管理Windows集群,不过管理节点需要部署在Linux机器上,而且需要预装python winrm模块。
同时,Windows机器上的powershell版本需要满足3.0+,且Management Framework也需要满足3.0+版本。
一、首先在Powershell窗口执行get-host命令查看版本
二、配置winrm服务
Windows上winrm服务默认是未启用的,使用如下命令可以查看状态。
1
|
winrm enumerate winrm / config / listener |
使用如下命令配置winrm服务
1
2
3
|
winrm quickconfig winrm set winrm / config / service / auth '@{Basic="true"}' winrm set winrm / config / service '@{AllowUnencrypted="true"}' |
至此,windows主机的配置就完成了,接下来我们配置linux管理节点进行验证。
三、Linux管理节点配置
1.然后需要使用pip安装pywinrm模块。如果没有安装pip,则先参考python分类博文安装并配置pip。
1
|
[root@cmdb - server ansible] # pip install "pywinrm>=0.2.2" |
2.配置hosts文件
1
2
|
[wind] 192.168 . 247.151 ansible_ssh_user = "Administrator" ansible_ssh_pass = "NPS#2018" ansible_ssh_port = 5985 ansible_connection = "winrm" ansible_winrm_server_cert_validation = ignore |
3.然后使用如下命令进行验证,我们看到,此时可以使用win_ping模块连到之前配置的windows主机上了。
1
2
3
4
5
|
[root@cmdb - server ansible] # ansible wind -m win_ping 192.168 . 247.151 | SUCCESS = > { "changed" : false, "ping" : "pong" } |
4.远程推送文件
1
2
3
4
5
6
7
8
9
10
|
[root@cmdb - server ansible] # ansible wind -m win_copy -a 'src=/etc/ansible/PreventCopy.jar dest=C:\' 192.168 . 247.151 | SUCCESS = > { "changed" : true, "checksum" : "c3da689273ec80f8072573b73dd87d3bc68e0395" , "dest" : "'C:\\PreventCopy.jar'" , "operation" : "file_copy" , "original_basename" : "PreventCopy.jar" , "size" : 62463090 , "src" : "/etc/ansible/PreventCopy.jar" } |
5.删除远程文件
1
2
3
4
|
[root@cmdb - server ansible] # ansible wind -m win_file -a "path=C:\PreventCopy.jar state=absent" 192.168 . 247.151 | SUCCESS = > { "changed" : true } |
更多模块及详细功能介绍:https://docs.ansible.com/ansible/latest/modules/list_of_windows_modules.html除win开头的模块外,scripts,raw,slurp,setup模块在Windows 下也可正常使用。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
Windows下可用模块虽不及Linux丰富,但基础功能均包括在内,以下几个模块为常用模块: win_acl (E) —设置文件 / 目录属主属组权限; win_copy—拷贝文件到远程Windows主机; win_file —创建,删除文件或目录; win_lineinfile—匹配替换文件内容; win_package (E) —安装 / 卸载本地或网络软件包; win_ping —Windows系统下的ping模块,常用来测试主机是否存活; win_service—管理Windows Services服务; win_user —管理Windows本地用户。 window的通信检测为:ansible testwin - m win_ping 复制文件到window: ansible windows - m win_copy - a "src=/etc/passwd dest=E:filepasswd" 删除文件: ansible windows - m win_file - a "path=E:filepasswd state=absent" 新增用户: ansible windows - m win_user - a "name=stanley password=magedu@123 groups=Administrators" 重启服务: ansible windows - m win_service - a "name=spooler state=restarted" 获取window主机信息: ansible windows - m setup 执行ps脚本: ansible windows - m script - a "E://test.ps1" 获取IP地址: ansible windows - m win_command - a "ipconfig" 查看文件状态: ansible windows - m win_stat - a "path='C://Windows/win.ini'" 移动文件: ansible windows - m raw - a "cmd /c 'move /y d:\issue c:\issue'" 创建文件夹: ansible windows - m raw - a "mkdir d:\tst" 重启: ansible windows - m win_reboot 结束程序: 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 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,否则提示无效路径,源使用反斜杠结果将递归传输目录下所有文件,源不一反斜杠结尾将整个目录传输到目标目录下。 |
[转帖]Ansible管理windows集群的更多相关文章
- 厉害—Ansible管理windows集群
最近公司新项目需要安装400+windows server 2012系统的工作站,想着怎么能像linux下运用ansible批量管理,linux就很简单了有ssh服务 但是下却没这么简单,但还是有办法 ...
- 使用Chef管理windows集群
但凡服务器上了一定规模(百台以上),普通的ssh登录管理的模式就越来越举步维艰.试想Linux发布了一个高危漏洞的补丁,你要把手下成百上千台机器都更新该补丁,如果没有一种自动化方式,那么至少要耗上大半 ...
- 使用Chef管理windows集群 | 运维自动化工具
但凡服务器上了一定规模(百台以上),普通的ssh登录管理的模式就越来越举步维艰.试想Linux发布了一个高危漏洞的补丁,你要把手下成百上千台机器都更新该补丁,如果没有一种自动化方式,那么至少要耗上大半 ...
- 如何在本地数据中心安装Service Fabric for Windows集群
概述 首先本文只是对官方文档(中文,英文)的一个提炼,详细的安装说明还请仔细阅读官方文档. 虽然Service Fabric的官方名称往往被加上Azure,但是实际上(估计很多人不知道)Service ...
- windows集群简单介绍
windows集群简单介绍仔细看过以前网友发表的一些文章,总觉得对windows集群没有详细介绍,我也是借花献佛,引用了一些技术性文档.目前应用最为广泛的集群计算技术可以分为三大类:高可用性集群技术. ...
- 将自己写的windows服务加入到windows集群中
最近发现windows集群能进行很多自定义,比如在集群中加入自己编写的服务. 能自定义的可不少,截个图: 本次演示中,只想用“通用服务”这个类型. 先列下步骤 编写一个记录时间的Windows服务,这 ...
- 使用Cloudera部署,管理Hadoop集群
Hadoop系列之(三):使用Cloudera部署,管理Hadoop集群 http://www.cnblogs.com/ee900222/p/hadoop_3.html Hadoop系列之(一):Ha ...
- VLAN 模式下的 OpenStack 管理 vSphere 集群方案
本文不合适转载,只用于自我学习. 关于为什么要用OpenStack 管理 vSphere 集群,原因可以有很多,特别是一些传统企业,VMware 的使用还是很普遍的,用 OpenStack 纳管至少会 ...
- 《Apache kafka实战》读书笔记-管理Kafka集群安全之ACL篇
<Apache kafka实战>读书笔记-管理Kafka集群安全之ACL篇 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 想必大家能看到这篇博客的小伙伴,估计你对kaf ...
随机推荐
- Spring Boot 中的静态资源到底要放在哪里?
当我们使用 SpringMVC 框架时,静态资源会被拦截,需要添加额外配置,之前老有小伙伴在微信上问松哥Spring Boot 中的静态资源加载问题:"松哥,我的HTML页面好像没有样式?& ...
- 4.3dotnet watch run「深入浅出ASP.NET Core系列」
希望给你3-5分钟的碎片化学习,可能是坐地铁.等公交,积少成多,水滴石穿,谢谢关注. dotnet run的麻烦 如果您使用的是vs code进行跨平台开发,那么dotnet watch run对你的 ...
- 玩转Spring Cloud之配置中心(config server &config client)
本文内容导航: 一.搭建配置服务中心(config server) 1.1.git方式 1.2.svn方式 1.3.本地文件方式 1.4.解决配置中包含中文内容返回乱码问题 二.搭建配置消费客户端( ...
- .Net移动开发平台 ,基于VisualStudio的可视化开发——Smobiler平台入门教程
通过以下步骤,可以简单了解到如何下载Smobiler Designer(设计器).Client(客户端),以及如何通过设计器进行开发和调试移动应用,并在服务端部署.Cloud打包.访问您所开发的移动应 ...
- DSAPI 远程协助之获取当前鼠标指针坐标及样式
在编写远程协助类软件时,除了获取屏幕画面外,还需要获取鼠标当前的坐标以及当前的指针样式,以便让远程屏幕知道当前的操作状态. 使用DSAPI内置的鼠标指针类,可轻松获取. 代码如下: Imports D ...
- 筛选出和该元素相交的元素之BoundingBoxIntersectsFilter
//假设元素为ee BoundingBoxXYZ box = ee.get_BoundingBox(doc.ActiveView); //创建outline,通过boundingboxintersec ...
- 解析高德地图api获取省市区,生成最新三级联动sql表
前言: 最近项目中用到了全国省市区三级信息,但是网上找到的信息都是比较旧的信息.与现在最新的地区信息匹配不上.后来想到高德地图上可能有这些信息.所以解析了一下api接口,生成了相关省市区的sql信息. ...
- java--基本数据类型的转换(强制转换)
强制类型的转换 规则: 1.执行算术运算时,低类型(短字节)可以转换为高类型(长字节):例如: int型转换成double型,char型转换成int型等等. 就是用强制类型来实现. 3.强制类型转换语 ...
- CAD 在ARCGIS中的坐标系问题
近期在使用服务(文本写入dxf方式)导出CAD的时候发现导出的CAD文件和原始数据在ArcMap中叠加后不能重合,出现了错位的现象. 查看CAD文件后发现CAD的坐标系及投影和数据不一致导致的.遇到这 ...
- 数据加密算法--详解DES加密算法原理与实现
DES算法简介 DES(Data Encryption Standard)是目前最为流行的加密算法之一.DES是对称的,也就是说它使用同一个密钥来加密和解密数据. DES还是一种分组加密算法,该算法每 ...