搭建ansible 环境对windows VM 机器进行批量管理和更新
使用文件管理软件如Windows的'文件资源管理器'进行批量整理 #生活技巧# #收纳整理技巧# #桌面文件管理系统#
在工作中我们有不同的测试机器pool来进行自动化测试,如果vm 需要整体升级来update 一些设置,我们通常会修改 template image file, 重新build all VM machines(more than 1000), 但有时因为测试需要,只需要对一个pool 或一些机器来更新设置或安装包,本来想写一个简单的tool 来做这个事,突然发现现成的工具ansible 能很好解决这个需求。所以就来搭建一套ansbile 环境来试试
Ansible 管理主机:
系统: Linux CentOS 7.4
Note: (先开始用的是CentOS 6.5, 配置完成后发现不能管理Linux server, ping 不通,具体原因好像跟系统有关,所以后来用了CentOS 7.4 就可以了)
首先看Linux 上有没有pip, 如果没有,用下面命令先安装pip
https://bootstrap.pypa.io/get-pip.py -o get-pip.py
安装完Pip 后 用 pip install 相关的package
pip install pywinrm
pip install ansible
此外Linux 还需要安装sshpass build: yum install sshpass
Python 版本2.7.x or above
Ansible 读取配置文件的顺序如下
 ANSIBLE_CONFIG (environment variable if set)
     ansible.cfg (in the current directory)
     ~/.ansible.cfg (in the home directory)
     /etc/ansible/ansible.cfg
所以我们需要手动创建配置文件ansible.cfg 在/etc/ansible 目录下,默认配置如下:
[defaults]
# some basic default values...
 inventory      = /etc/ansible/
 host_key_checking = False
 forks = 5
 remote_port    = 22
 timeout = 30
 log_path = /var/log/ansible.log
此外我们还需要创建hosts file 在/etc/ansible 目录下,配置如下:
[tawin]
 192.168.144.191
 [tawin:vars]
 ansible_user = administrator
 ansible_password =
 ansible_port = 5985
 ansible_connection = winrm
 ansible_winrm_server_cert_validation = ignore
 [talinux]
 talinuxslave00[1:9].eng.com
 [talinux:vars]
 ansible_ssh_user=root
 ansible_ssh_pass=pass
至此,Ansible server 已经基本配置完成。下面开始配置windows
Windows 机器:
Windows 需要更新powershell 版本至少到3.0
Download URL: https://www.microsoft.com/en-us/download/details.aspx?id=34595
此外还要进行些配置,具体可以参考下面文档:
http://blog.51cto.com/7424593/2174156
全部配置完后,开始验证了:
ansible tawin -m win_ping
 最后配置了一个yml /etc/ansible/install-msi.yml 来deploy msi file
- name: Install  an MSI
   hosts: tawin
  tasks:
     - name: Download the msi
       win_get_url:
         url: 'https://t1wdta03.eng.com/app.msi'
         dest: 'C:\app.msi'
     - name: Install MSI
       win_package:
         path: 'C:\app.msi'
         state: present
试了一下没问题, 下面如何按照具体需求使用,就参考官方文档吧:
https://ansible-tran.readthedocs.io/en/latest/docs/intro_inventory.html
网址:搭建ansible 环境对windows VM 机器进行批量管理和更新 https://www.yuejiaxmz.com/news/view/770917
相关内容
Windows Server 2008 服务器内存使用率过高 且任务管理器找不到对应的使用进程Ansible自动化运维与任务执行
【补充】Python的自动化工具Ansible
Windows远程桌面批量管理器(电脑远程控制助手)V2.1
自动化编排工具(Ansible)
通过Windows Server实现高效的批量任务调度与管理
带你了解Linux自动化运维工具——ansible
深入理解CI/CD:构建、测试和部署的完整流程
用 Ansible 自动化系统管理员的 5 个日常任务 | Linux 中国
Ansible 自动化运维工具详解

