Using Packer to Create Vagrant Boxes
Join the DZone community and get the full member experience.
Join For Freethe process of managing a virtual machine is heavily simplifed via the use of vagrant . however, there is still a manual or a semi-automatic process involved for creating the base box itself. there are many tools designed to solve to this problem, the most recent one is packer from @mitchellh , the very same man behind vagrant.
packer allows you to create a personal vagrant base box easily. this means that you don’t need to rely anymore on some random ready-made boxes from the internet. with packer, you know what is being installed into your base box and hence the box can be more trustworthy. while packer supports vagrant, it can also be used to prepare a system for amazon ec2, vmware, and many others .
using packer to create centos and ubuntu boxes is not difficult. if you want to follow along, i have prepared a git repository ariya/packer-vagrant-linux which contains all the necessary bits to create centos 5.4 and/or ubuntu 12.04 lts 64-bit boxes. make sure you have the latest version of virtualbox, vagrant, and packer installed properly in your machine before you follow these step-by-step instructions.
packer works with a template file . in the repository mentioned above, there are two templates, each for centos and ubuntu. as an example, if you want to build the base centos box, you need to invoke the command:
packer build centos-6.4-x86_64.json
this triggers the download of virtualbox guest additions image and the actual centos 5.4 installation image. these two images will be cached, see the subdirectory
packer_cache
, so that any subsequent build does not trigger a full download again. obviously, if you rather create a ubuntu box, just replace the specified file with the one for ubuntu.
using the installation image, packer will prepare a blank temporary virtual machine (clearly visible if you have virtualbox manager running as the machine is called
packer-virtualbox
) and
install
centos into that machine. unless you are running it in a headless mode, a window will show up the actual installation process:
for many sysadmins, unattended linux installation may sound familiar: centos uses kickstart while ubuntu uses preseeding. the configuration files for this automated installation are in the
http
subdirectory (served via http to the installer). you can open the template file,
centos-6.4-x86_64.json
in the above example, to get the understanding of this unattended installation configuration.
once the intended linux distribution is installed, the template file tells packer to do some basic
provisioning
by running several shell scripts (check the subdirectory
scripts
). after this
provisioning
step is completed, packer will export the temporary virtual machine and create a vagrant base box out of it. in this example, it will be stored in the
build
subdirectory. at this point you are ready to use your base box, it is a matter of using
vagrant init
with the path to the box in that build directory.
now, who said packing can’t be fun?
Published at DZone with permission of Ariya Hidayat, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
Using OpenAI Embeddings Search With SingleStoreDB
-
Explainable AI: Making the Black Box Transparent
-
Which Is Better for IoT: Azure RTOS or FreeRTOS?
-
Security Challenges for Microservice Applications in Multi-Cloud Environments
Comments