👤

重置密码

发送中...
返回登录

使用 Ansible 实现自动化运维VMware vSphere(入门)

Linux 17 浏览 2 分钟阅读

概述:

使用ansible能实现自动化运维,牛刀小试一下,使用 Ansible 来实现自动化运维VMware vSphere ESXi。

配置:

配置inventory主机清单,如下

[vmware]
192.xx.xx.14 ansible_user="youruser" ansible_password="yourpassword"
192.xx.xx.15 ansible_user="youruser" ansible_password="yourpassword"

配置ansible.cfg

[default]
remote_user = root
inventory = /root/ansible/inventory

[privilege_escalation]
become_method = sudo
become_user = root
become_ask_pass = flase

生成公钥和私钥

 ssh-keygen -N ''

将秘钥发给vSphere ESXi主机

ssh-copy-id root@192.xx.xx.14
ssh-copy-id root@192.xx.xx.15

验证:

国际惯例,先检测主机是否在线。

ansible -i inventory vmware -m ping

查看当前VMware ESXi 的版本

ansible -i inventory vmware -m -shell -a 'vmware -v'

再或者,看下网卡列表?

ansible -i inventory vmware -m shell -a 'esxcli network nic list'

总结:

通过简单的shell模块可以直接批量执行任务,由此思路是否可以实现对大量的vSphere 主机进行批量升级?自动升级呢?未完待续。