Looking for a way to automate the entire OS setup and install packages like Chrome, Dropbox, and Flatpak apps? Want an easy way to auto-configure vim, Kodi, firewall ports, sestatus, and $PATH for all those custom tools and setup everything just as you like? This is possible with Hashicorp's Packer and Redhat's Ansible, I'll show you how to get started.

packer is a tool to automate the install and configuration of machine images. It supports starting with a silent install of e.g. Fedora or Ubuntu, then fully-customize with Ansible playbooks and scripts. The image is shareable with friends/teammates and can be deployed as Vagrant boxes, VMware, or cloud providers.

Incremental machine images...

It takes a long time to do a silent install and a long time to install hundreds of GNOME packages. packer can modify already-existing images so to save test time and keep us sane, it's easiest to build images stepwise instead of doing the full ISO install + customization in one shot. Breaking the build into steps, my approach is: ISO -> desktop-installed -> desktop-customized.

Create the machine images

Packer creates images based on data in a template file. There's a lot to the template file so look at the documentation. The most difficult part is getting the silent install working -- google around and there are plenty of examples to base your builds on.

For a full example of a Fedora 25 kickstart and customization, see my packer-template-builder project and my short writeup on how to create incremental OVA images using packer. There are similar projects for performing a Debian preseed install.

After you have your first OVA image it's very easy to write Ansible playbooks to customize the OS. Write some playbooks or borrow some from Ansible Galaxy, and my demo project linked above shows how to use the playbooks as part of the packer template. So go out and do some customization! After you have a customized and tested OS, we can take the OVA, burn to a drive, and boot.

Write the OVA to a disk

Writing and booting from a physical drive is just a few more steps and it's exciting to see the first time.

  1. Extract the OVA tar: tar -xf *.ova.
  2. Convert the OVA to raw: qemu-img convert -f vmdk -O raw image.vmdk image.img.
  • WARNING this creates a very large output file (40GiB in my case).
  • You can convert to raw and burn it at the same time by replacing "image.img" with the output device.
  1. Put it on the drive: dd bs=32M if=image.img of=/dev/<theDevice>

After the above, the disk is ready to use! Kudos to packer for making this so easy.