Deploying vSphere Replication with Ansible

Recently, myself and some colleagues where tasked to automate the installation and configuration of a VMware DR solution. This involved the deployment and configuration of SRM and vSphere Replication to be production ready once all automation was complete. This proved a little tricky due to lack of APIs for some of the products, however in this blog post I wanted to show how I deployed vSphere Replication using Ansible, which was the automation tool of choice for this project.

Create Pre-Requisites

If you have deployed vSphere Replication before, then you know that there are some pre-requisites that may be required, depending on your design decisions. I won’t discuss here how we created AD groups, accounts etc as this was all done using another role but these are all pretty easily automated.

The main requirement was to have a separate NIC for replication traffic on my appliances. The new role created was the port groups for replication. This can be done using the OTB vmware_dvs_portgroup Ansible module. Here I am creating creating the port group , assigning the teaming policy and various other requirements.

Next, I wanted to create the VMKernel Adapters on the hosts. In this instance I am extracting an item from group vars called “managementHosts” which contains information on , well, my management hosts 😊. I am looping these and using a regex to change the last octect for the IP address of the adapter. I am attaching the adapter to the newly created port group above and then enabling the replication service.

Deploying vSphere Replication

Now that I have the port group I want to add my 2nd NIC too, I can begin deploying my appliance.  Ansible of course offers an OTB module to deploy VMware appliances, however in this instance is could not be used due to the fact vSR requires the vCenter extension to be registered. To overcome this, I had to use good old OVFTOOL to deploy.

VMware have a nice page showing all the inputs needed at https://docs.vmware.com/en/Site-Recovery-Manager/8.3/com.vmware.srm.install_config.doc/GUID-7FEBF1C4-B7D9-4DC2-8706-0AA0FDB969D0.html

However, if you have manually deployed an appliance you can also check the input values. Click on the VM and click the configure tab

Under settings , click on vApp options and then view OVF environment

Scroll to <PropertySection> and review the inputs needed.

Using the variable {{ ovftool }} which points to the location of the installation, I can kick off the installation.  Note the line vi://'{{ vCenter.user | urlencode }}’:'{{ password | urlencode }}’@”{{ vCenterName }}/{{ dataCenter }}/host/{{ cluster }}/Resources/{{ resourcePool }}” which is registering the appliance.

Add 2nd NIC

Now that I have a fresh appliance deployed, I need to add my 2nd NIC. To do this, i can again take advantange of the OTB  vmware_guest module to add this

Assign IP Address and static routes

Of course, the addition of the 2nd NIC only adds it to the VM. We now need to assign an IP address and add the static routes required to forward replication traffic.

One thing about vSR in 8.2 is that SSH is not enabled by default, nor can you turn if on when deploying the appliance. In order to do this, I need to use the vmware_vm_shell module and execute the enable-sshd.sh script which is in the /usr/bin directory by default.

Once SSH is enabled I can now execute a remote command to add the IP and static routes to the appliance using the blockinfile command. Notice i am using the delegate_to function to call vsr001 which has been added to my hosts file.

Next, I can then assign the IP to the appliance under eth1 and restart the system-networkd service

Configure VAMI

Finally, I need to set the IP for eth1 inside the VAMI configuration of the appliance. To do this I am taking advantage of the inbuild scripts inside the appliance and simply sending a curl command to execute this

At this point, of course there is further configuration required and I will post soon. For now, I hope you found this useful. Any questions or improvements then I am always happy to hear.

Thanks

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.