WARNING! This article has been written a long time ago. It may no longer represent the current views of the author!

Notes: Using Packer for Vagrant libvirt boxes

What is Packer exactly?

There are number of good resources giving the rationale for Packer. Short answer is tool for automatic building of images. From my perspective the best overview can be found in the book:

which gives the historical insight to the problem of keeping your server space as homogeneous as it is possible, and how Packer solves some of the pain points with that.

Customizing a Vagrant image for libvirt

Among others, Packer has ability to take existing Vagrant box, customize it using various technologies (shell script, Ansible, Chef, Puppet) and turn into a new box that fits the needs of the person customizing it.

Here is a simple template for customizing a CentOS box with inline shell provisioner.

{
    "builders": [
        {
            "type": "vagrant",
            "source_path": "centos/7",
            "box_name": "centos_webserver",
            "provider": "libvirt"
        }
    ],
    "provisioners": [
        {
            "type": "shell",
            "inline": [
                "sudo yum groupinstall 'Basic Web Server' -y"
            ]
        }
    ]
}

The result is a new vagrant box inside output-vagrant/ provisioned with needed software.

Links