Everything up to this point has been theory and preparation. Now we get to make the first real progress towards our goal of quickly deploying a Nextcloud server on the GeekLab by using our customised Ubuntu OVF template to create a virtual machine with Ubuntu prepared and ready for Ansible to get to work on.
Process Overview
If you refer back to the Automation Approach I broke the process for deploying a Nextcloud VM down into six steps:
- Create a virtual machine with the operating system installed and ready for Ansible to start configuration
- Ansible playbook for initial OS configuration to prepare for the main automation execution. This should be the last step that needs human input or intervention too.
- Ansible playbook to complete OS configuration and install standard utilities and applications
- Ansible playbook to configure Nextcloud-specific pre-requisites such as filesystems, PHP and MariaDB
- Ansible playbook to create the database and deploy Nextcloud itself
- Ansible playbook to do the initial configuration of Nextcloud
In this step we're going to take the template we created in VM Template Creation part 1 - 3 and use it to create a VM which we'll then install Nextcloud on.
Deploy Template via Script
Having the Ansible Playbooks deploy the VM would be the ideal way to proceed. Unfortunately the free edition of the ESXi hypervisor is not supported by Ansible's community.vmware collection so we can't do this directly.
VMware have released the command line ovftool and this looks very promising and as soon as I get some time I'll update this section with the results. It will of course mean I'll need to install the ovftool onto my playbook launcher and have the OVF template we created placed somewhere they can also access so there's more to it that just getting the tool to work.
Deploy Template Manually
For now we'll fall back to deploying the template manually. Since we used the ESXi Host Client to export the OVF template, we an also use it to build a new VM from the template. This will upload the saved OVF Template files each time so they need to be available as local files or via a network share.
Log in to the ESXi Host Client

Select Create/Register VM and the New virtual machine wizard will start

Select the 2nd option "Deploy a virtual machine from an OVF or OVA file" and the summary on the left will change to show 7 steps which is where we'll apply some customisations. Click Next when ready.
The wizard will then prompt for the VM name and the template files.

The VM name is the name used within VMware ESXi, not the hostname that Ubuntu will report when it starts. As directed by the wizard either click the blue box top open a dialog and locate the template files or drag & drop them into the blue box itself. Make sure sure to select all six files from our template, even though it won't list the .mf file. When ready click Next.
We then get prompted for which datastore to use for our new VM.

Select the most appropriate one for your server and click Next.
We now get to customise a few more settings on our new VM.

I created the VM used to create the template on my sandpit network, so it needs to know which network on the new VM will connect to, which in this case is also going to be sandpit again but it could be my test or live networks. If you had multiple interfaces it will ask for each one to be mapped.
I also created all disks on the source VM as thin provisioned, so we also get the choice of whether to retain them as thin provisioned or convert them to thick. Since this is a sandpit machine and performance isn't critical I'm going to leave them as thin provisioned. It is also possible to convert individual disks to thick provisioned once the VM is build too.
When you're ready click Next.

And this is interesting. I suspect it might be complaining about the .mf file it didn't recognise earlier, but it doesn't actually appear to cause a problem so I suspect this is a false alarm. As long is it has the correct number of .vmdk files listed click the Finish button to start the import.

The three empty disks import in 2 seconds, the first disk with the Ubuntu OS takes just over 3 minutes to import and then another minute to complete the rest of the template import process and start the VM.

Our new VM starts with the same hostname that was set in the template source and providing DHCP and DNS do their jobs properly it's accessible on the network, which is good.
It's also the drawback of using this template-based approach in that I can only deploy a single VM at a time otherwise we'll get naming collisions. On a lab scale this won't be a problem, and if I ever get to the point of needing to deploy a group of VMs from the same template there's a couple of approaches I could take to automate a deploy-and-rename loop.
Wrap up
So this pretty much wraps up the first half of this series. We can now deploy identical virtual machines in under 5 minutes ready to be turned into Nextcloud servers. And using similar techniques I could also build any other application server that I want to play with.
For the rest of the series I'll be working through the Ansible playbooks that rename the host and then complete the Nextcloud installation.