I was desperate in learning ansible and thus tried to learn some concepts over the internet. When i learned ansible to configure linux hosts through SSH , i was bit demented in understanding.
So i decided to learn them with the way i understand with the technology i already know. I chose VMware.
The task is so simple to add an esxi host to an existing vSphere cluster. This playbook shall help to perform the same.
- hosts: localhost
gather_facts: False
vars:
vcenter_name: "vcsa01.corp.local"
vcenter_user: "administrator@vsphere.local"
vcenter_pass: "**********"
esxi_hostname: "esxi001"
esxi_user: "root"
esxi_pass: "*********"
datacenter: "datacenter01"
cluster: "cluster01"
dnsdomain: "corp.local"
# The ansible code to add ESXi in clusters. The ESXi should not be in the vcenter inventory yet.
tasks:
- name: Add hosts to clusters
community.vmware.vmware_host:
hostname: "{{ vcenter_name }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_pass }}"
datacenter_name: "{{ datacenter }}"
cluster_name: "{{ cluster }}"
esxi_hostname: "{{ esxi_hostname }}.{{ dnsdomain }}"
esxi_username: "{{ esxi_user }}"
esxi_password: "{{ esxi_pass }}"
validate_certs: no
state: present
delegate_to: localhost
Requirements:
- Python modules pyvim and pyvmomi
- Ansible module for vmware <community.vmware> from galaxy

I have used the interpreter explicitly because i have selected my default interpreter as Python3 and my ansible is reading Python2 from the ansible.cfg.
just a bit lazy to edit my ansible.cfg !
