Planning an approach to automating the deployment of a Nextcloud installation to an Ubuntu virtual machine hosted on my ESXi-based GeekLab. It takes a few evenings to do this by hand, so this is a task that's ripe for automation and letting me do more important things like wiping out another Core insurgency while I wait.
Introduction
Nextcloud has been working nicely for several months now as a shared Calendar and Contacts server and with the Mail app giving the option of web-based email although my users quite understandably prefer to use mobile or desktop mail clients. Deck is also active and it was testing this that first got me thinking about an automation to build and install sandboxes for experimenting with the various apps and options.
Nextcloud provide pre-configured Virtual Machine and Docker images, snaps, Pi images and links to free and charged Nextcloud hosting from their installation site but I wanted a little more control and of course it's a good excuse to have a play.
Aims
Every project should have a clear goal as to what you're setting out to achieve. Goals can always be changed of course, but it helps to start off with some clue as to where you're going.
"Develop a method and process to deploy, with as little human intervention as possible, an Ubuntu virtual machine into my GeekLab with a Nextcloud installation and all pre-requisites configured and ready to start experimenting on."
A secondary aim is to refresh my skills with automation and hopefully learn some new stuff too since I don't get to be hands-on in my day job any more.
Environment
My live Nextcloud installation is running on my own server (the GeekLab) which sits in a cupboard under the stairs. It runs the free VMware ESXi hypervisor which is great for this sort of thing but as it's free there are some limitations around automation I will need to handle or at least work around.
I have been using Ubuntu 20.04 LTS as a base OS for application servers and since I already have an Ansible playbook to do the initial configuration it makes sense to take that and extend as necessary for this project. While this isn't the latest Ubuntu version, I never got around to updating to Ubuntu 22.04 LTS and with the next LTS release due later this year I can't see the point now.
As mentioned above I have an existing Ansible playbook so it makes sense to build on that as well. This includes a simple bash script to launch playbooks and a git repository to help manage the completed code
Toolset
With the environment and some of the tooling already in place the toolset is pretty much decided. The one thing I don't have is automation around creating the base OS installation, the main approaches being a static OVF template, an infrastructure automation tool such as Terraform or passing customisation info to a base image using something like cloud-init. This is considered in detail in the next article, so at the risk of introducing a spoiler the final list is as follows:
- Ansible playbooks for running automation tasks
- Bash scripts to launch and control playbooks
- git repositories for new and existing Ansible playbooks and roles
- git repository for Ansible inventory
- Editor - vi and Visual Studio Code
- A desktop VM (Mint) for development with local installation of Ansible
- A saved OVF template of the base image Ubuntu VM
- Installation files for Ubuntu 20.04 LTS to build the base image, and Nextcloud 28.0.0
- Access to the repositories for other software we need to install.
Plus of course a fair bit of searching around the internet for hints and clues to make it all work.
Approach
To get the most benefit from automation you need to make things as modular and flexible as possible. Not just to make it easier to add future enhancements, but also to allow what you've created be reused in other situations too. I also found having some defined stages for the the overall process means helps break down the project into deliverable chunks so I can see progress and it also means I can quickly deploy a test VM and get it to a known state in order to test and debug something.
- 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
I already have Ansible playbooks that complete steps 2 and 3 so I can reuse them with some enhancements. Breaking down the rest into three separate steps means I can clearly define interim success criteria, but it should also mean as Nextcloud evolves I should only need to change the playbook for step 6 and maybe some variables in step 5, making maintenance much easier as I shouldn't need to change and retest everything.
Future updates
While this is working as I need it for now (yeah, another spoiler!) I already have some ideas for future updates and in most cases I have an approach in mind and should be relatively easy. And yes, these are all being tracked on Deck cards.
- Ubuntu 24xx when it's released, or more likely just before 20.04 TLS goes out of support
- Validate the Nextcloud.zip installation archive
- Automatically configure LDAP user management
- Automatically enable a standard set of apps for integration testing
- Automate deployment of the initial OVF image
This series will be extended whenever I get around to these.