Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Basic Packer template to create a custom Vagrant VirtualBox base box

Notifications You must be signed in to change notification settings

artislismanis/packer-template

Repository files navigation

packer-template

What is this?

This is a Packer template to help you generate a custom Vagrant / VirtualBox box image based on the latest release of Ubuntu LTS. It starts with a minimal Ubuntu Server install, enables OpenSSH for remote shell access and then uses provisioning scripts to build up required box templates from leaving minimal Ubuntu server minimal, to installing some useful tooling, to setting up a desktop environment. lubuntu-datadev-vm uses this Packer project as a starting point.

The code has been tested and working using Packer 1.6.2 and VirtualBox 6.1.12 on a Windows 10 machine with Ubuntu Server 20.04.1 LTS ISO.

Why do I need it?

Rolling your own base box gives you full control and transparency over what goes into it - you can optimise your template to your specific needs. It is also an opportunity to lock down your box template from security perspective by not using insecure accounts and secrets used in publicly available downloads.

OK, how do I get started?

  1. Make sure you have a recent version of Packer and VirtualBox installed and working on your system. Command examples provided in the project documentation also assume you are using PowerShell with script execution enabled and have Git installed and configured to work on Windows Command Prompt. You can easily adapt these to your CLI and most will work without any modifications.

  2. Clone or download this repository.

    git clone git://github.com/artislismanis/packer-template.git
  3. Download the relevant Ubuntu Server ISO installation media into the iso folder, make note of the related checksums.

  4. Review the Packer template you want to use (this example uses ubuntu-20.04-server-base.json):

    1. Modify VM specification in vboxmanage section to match your available system resources. These are standard VirtualBox VBoxManage commands - see VirtualBox manual for full reference.
    2. Review user variables in variables section. Make sure vm_iso_image, vm_iso_image_checksum and vm_iso_image_checksum_type have the correct values assigned. Make other adjustments as required. Variables can be set in the template file or managed through runtime overrides like described in these Packer examples. See project wiki for further details on available user variables.
  5. Run packer build in the root of the repository folder.

    packer build ubuntu-20.04-server-base.json

    Check out override-examples for different ways to override default user variables.

  6. Wait for the build to finish. End to end build of minimal Ubuntu Server box using the specified VM configuration takes under 15 minutes, Lubuntu Desktop under 50 minutes. The output is saved in box/virtualbox/ folder and can be used with vagrant box add as described in Vagrant CLI documentation.

What else?

The project provides two templates ubuntu-20.04-server-base.json and lubuntu-20.04.json. lubuntu-20.04.json includes Vagrant Cloud post-processor and will fail if used without specifying valid Vagrant Cloud details & key in user variables section. You can exclude the post-processor form running by triggering build like so:

packer build --except=publish-vc lubuntu-20.04.json

If you do want to build and publish your box to Vagrant Cloud, the template expects you to specify tag, token and version in VC_TAG, VC_TOKEN and VC_VERSION environmental variables respectively.

The project has some rudimentary test build scripts and brief documentation to help with testing - check out the notes on testing for more details.

Over time project wiki will be evolved to include more detail and troubleshooting information. In the meantime check out 'Useful Resources' section below if you get stuck.

Useful Resources

About

Basic Packer template to create a custom Vagrant VirtualBox base box

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published