2018-04-26

Ansible Week - Bonus - Automating OpenBSD Installs

Manually setting up your OpenBSD VMs is for chumps.

The recent release of OpenBSD 6.3 gave me an excuse to finally sit down and start teaching myself how to use the builtin OS autoinstall feature.

OpenBSD had supported installation templates for a few years now, but I was always mired in the artisanal mindset. I believed that setting up a new machine was a labor of love and in spite of the simplicity of the install wizard felt one needed to spend at least that long minute or two crafting the hard and fast rules by which the system will live forever.

ZFS sure would be nice to have on the platform, but no. There's no way in hell that's gonna happen.

You may want to take that time thinking about the disk layout of your next mail server or firewall or whatever, but when it comes to a VM image you want to run at scale in the cloud, there are advantages to finding ways to streamline the process after you've made those decisions the first time.

The central tool of autoinstallation of OpenBSD is the "install.conf" file, which contains answers to every question that the install wizard would normally ask you interactively.

An example install.conf would look like this:

System hostname = mymachine
Which network interface do you wish to configure = hvn0
IPv4 address for hvn0 = dhcp
IPv6 address for hvn0 = none
Which network interface do you wish to configure = done
Password for root = $2b$08$sjHcRpZW2Jg7ryPxeHEBNu7DsyA3Fg8FrDvqLSqkx7TFmbUST9z/C
Public ssh key for root account = none
Start sshd(8) by default = no
Do you expect to run the X Window System = no
Do you want the X Window System to be started by xenodm(1) = no
Change the default console to com0 = no
Setup a user = no
Allow root ssh login = no
What timezone are you in = UTC
Which disk is the root disk = sd0
Use (W)hole disk MBR, whole disk (G)PT, (O)penBSD area or (E)dit = Whole
Use (A)uto layout, (E)dit auto layout, or create (C)ustom layout = A
URL to autopartitioning template for disklabel = none
Location of sets = cd
Set name(s) = done
Directory does not contain SHA256.sig. Continue without verification = yes
Location of sets = done

This is enough to set up a machine in short order. You can customize it to your wishes, and there's even a disklabel template format you can provide in a separate file:

/  250M 
swap  80M-256M 10% 
/tmp  120M-4G 8%

This is really nice, because you can put this disklabel template online and set its URL in the "URL to autopartitioning template for disklabel" line of install.conf and get a very-close-to-hands-free OpenBSD install just using two config files on a trusted internal webserver and the default OpenBSD installXX.iso.

You can even embed the install.conf into custom install media to make it totally automated if you want.

So, in conclusion, OpenBSD autoinstallation features, plus an Ansible system setup playbook, and scriptable Azure utilities can combine to create a very nice cloud service platform. Reshape the world as you see fit.

No comments: