This repository contains a template and other files necessary to build a Vagrant box for libvirt provider via Packer. At the moment, only libvirt provider is supported. This set of resources was created with the goal of setting up a disposable virtual environment for testing various technologies and tools, that's why the resulting image contains almost no additional packages - so that one could provision it with Vagrant for a more specific purpose. This template was written with isolated corporated environment in mind, hence proxy settings.
The template uses virt-sysprep for cleaning the resulting image of any machine-specific configuration, making it suitable for cloning. It can be installed as following:
sudo apt-get install libguestfs-tools
on Debian 9 and it's derivatives.sudo yum install libguestfs-tools-c
on CentOS 7 and it's derivatives.
virt-sysprep is likely to have problems accessing kernel images on Ubuntu based distributions due to rigid permissions, so if that's the case for you, it can be worked around as the following:
chmod +x /boot/vmlinuz*
- To prevent this issue from bothering you again, create file
/etc/kernel/postinst.d/statoverride
with the following contents:
#!/bin/sh
version="$1"
[ -z "${version}" ] && exit 0
dpkg-statoverride --add root root 0644 /boot/vmlinuz-${version} --update
chmod +x /etc/kernel/postinst.d/statoverride
Run packer build template.json
to build a vagrant box. The template exposes several environment variables with preset defaults you can see by running packer inspect template.json
. Variable's names are self-explanatory.
To spin up the environment from this box via Vagrant, only 3 steps are required:
- Create a Vagrantfile. You may use this as a template.
- Add the box by running
vagrant box add
. - Bring up VM(s) by running
vagrant up
.
You're all set!
The box is provisioned with a pre-created public key, contained in files/authorized_keys
. You can (and should) replace it with your own and make sure you specify the corresponding private key in your Vagrantfile by setting config.ssh.private_key_path.
You might want to change installation and base repository's urls, as well as timezone, in kickstart/centos7-ks.cfg
based on your location.
Tested with all combinations of the following versions of Packer, Vagrant, and Linux flavors: Packer:
- 1.0.4
Vagrant:
- 1.9.7
- 1.9.8
Linux:
- Debian GNU/Linux 9
- Fedora 26
- Linux Mint 18.2.