DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Using Packer to Create Vagrant Boxes

Using Packer to Create Vagrant Boxes

Ariya Hidayat user avatar by
Ariya Hidayat
·
Nov. 16, 13 · Interview
Like (1)
Save
Tweet
Share
17.74K Views

Join the DZone community and get the full member experience.

Join For Free

the 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:

packer

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?

Virtual Machine

Published at DZone with permission of Ariya Hidayat, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • The Enterprise, the Database, the Problem, and the Solution
  • 5 Tips for Optimizing Your React App’s Performance
  • Efficiently Computing Permissions at Scale: Our Engineering Approach
  • Getting Started With JMS-ActiveMQ: Explained in a Simple Way

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: