I reached the part where I wanted to demo a few things with Ansible and VMware. I so far like Ansible and what it can do within a few days time. In this part I want to show how to deploy a vCenter automatically using Ansible.
As long as you have followed a long with the things I did earlier it should be quite simple. Of course the main part is that you get Ansible installed and do the post-installation tasks. You can find all the Info here.
Once that is done we need to download the vCenter iso. This is done from my.vmware.com and once downloaded you should mount it and then copy the .ova file from inside the /vcsa/ folder on the iso to a location where it can be reached by Ansible. In my case I put it in a folder on my Ansible server for the ease of the installation:
You can open this file with a zip tool (or unarchiver if using MacOS). Inside this file you get a number of files (mostly vmdks):
Next we need to build the YAML file.
It starts the usual way with three – and then it is time to dig out parameters and information and variables that you want to use for the installation. Many of these variables are stored inside the .ovf file. The .ovf file is basically as you might recognise an xml file:
For sure one thing we need is the “Network 1” Name. There are certain other parts that are helpful during the installation and will be added to the playbook file. We also need to use a module, in this case I will make use of the “vmware_deploy_ovf” Module. You can find the parameters for that here:
So for a start here is the file as it looks at first:
--- - hosts: localhost name: Deploy the VCSA to an ESXi Host gather_facts: false vars: esxi_address: 'aocs1esx01.aocit.local' esxi_username: 'root' esxi_password: 'P@ssword10' vcenter_password: 'P@ssword10' vcenter_hostname: 'aocvc07' vcenter_address: '192.168.1.30' net_prefix: '25' net_gateway: '192.168.1.2' dns_servers: '192.168.1.2,192.168.1.3' domain: 'aocit.local' searchpath: "aocit.local" vcsa_size: 'tiny' vcsa_ova_file: '/home/ansibleadm/repo/VMware-vCenter-Server-Appliance-7.0.0.10600-16620007_OVF10.ova' tasks: - vmware_deploy_ovf: hostname: '{{ esxi_address }}' username: '{{ esxi_username }}' password: '{{ esxi_password }}' name: '{{ vcenter_hostname }}' ovf: '{{ vcsa_ova_file }}' wait_for_ip_address: true validate_certs: no inject_ovf_env: true datastore: 'aoc-s1-mg-nas-01-class-B' networks: "{u'Network 1':u'Servernet'}" properties: DeploymentOption.value: '{{ vcsa_size }}' guestinfo.cis.appliance.net.addr.family: 'ipv4' guestinfo.cis.appliance.net.mode: 'static' guestinfo.cis.appliance.net.addr: '{{ vcenter_address }}' guestinfo.cis.appliance.net.pnid: "{{ vcenter_hostname }}.{{ domain }}" guestinfo.cis.appliance.net.prefix: '{{ net_prefix }}' guestinfo.cis.appliance.net.gateway: '{{ net_gateway }}' guestinfo.cis.appliance.net.dns.servers: '{{ dns_servers }}' guestinfo.cis.appliance.root.passwd: '{{ vcenter_password }}' guestinfo.cis.ceip_enabled: "False" guestinfo.cis.deployment.autoconfig: 'True' guestinfo.cis.vmdir.password: '{{ vcenter_password }}' domain: '{{ domain }}' searchpath: '{{ searchpath }}' delegate_to: localhost - name: Wait for vCenter vmware_about_facts: hostname: '{{ vcenter_address }}' username: 'administrator@vsphere.local' password: '{{ vcenter_password }}' validate_certs: no delegate_to: localhost retries: 20 delay: 60 register: result until: result is succeeded
And once it is executed it looks like this when it’s done. Keep in mind it can take up 20-25 minutes to execute in a slow environment. In a prod environment I have done this in 7 minutes.
So we are done and can log into the new vCenter.
That is it for now, next it is time to look a bit at what can be modified via Ansible.