• Home
  • About Us
  • Products
  • Industry
  • Customers
  • Partners
  • Blog

XebiaLabs Blog

 

Come on, vagrant up! Saving Vagrant images that don’t get a NAT address

Posted on April 23, 2012 by Andrew Phillips

As part of testing and demonstrating our advanced deployment automation1 platform Deployit, we at XebiaLabs use a lot of cloud and Devops tooling to be able to handle all the different types of middleware we support and build, CI and Ops tooling with which we integrate2.

I was recently setting up a Vagrant3 environment to demonstrate Deployit's Puppet module, which automatically registers new Puppet-provisioned middleware with your deployment automation platform to enable application-tier deployments to it, and ended up wrestling for quite some time with a tricky VirtualBox problem.

The issue in question has been around for over two years now, and relates to VirtualBox's DHCP server sometimes, under as-yet-undetermined circumstances, failing to allocate an IP address to the NAT interface.
Since all Vagrant-managed images get a NAT interface by default4, this is more than a little inconvenient: Vagrant simply hangs during the VM configuration phase.

Since the problem doesn't occur deterministically, one way to work around this issue is simply to avoid having to reboot the image: play the "NAT lottery" until you get lucky by killing the VBoxManage process if the image is hanging and trying vagrant up again, then run vagrant suspend rather than vagrant halt and you can resume the images when you need them.

That will work, but I wasn't particularly happy with this approach because, aside from me not liking the idea of repeatedly killing hypervisor processes (I'm somewhat of a pacifist in this regard ;-) ), it effectively "cripples" Vagrant: the ease with which you can start, stop and re-configure images is precisely one of the things that makes Vagrant so useful!

One of the things I quickly discovered is that, if you start a Vagrant-created image via the VirtualBox UI and it experiences the problem5, cycling the NAT adapter with ifdown eth0 && ifup eth0 fixes things: this second time, it is able to pick up an IP address from the DHCP server.

Unfortunately, this does't get you far with an image that Vagrant itself is trying to start: Vagrant creates headless sessions, so you can't actually access them through the VirtualBox UI until you've killed Vagrant and the VBoxHeadless process it starts.

Luckily, VirtualBox allows you to execute commands on the guest OS without having to use the UI, via VBoxManage's guestcontrol command. So when Vagrant was again hanging while waiting to connect to the image, the first thing I tried was

/path/to/vboxmanage guestcontrol my-vagrant-image exec "/usr/bin/sudo" --username vagrant --password vagrant --verbose --wait-stdout ifdown eth0
/path/to/vboxmanage guestcontrol my-vagrant-image exec "/usr/bin/sudo" --username vagrant --password vagrant --verbose --wait-stdout ifup eth0

That did, as hoped, allow the NAT adapter to pick up an IP address. Unfortunately, it also confused Vagrant, which (presumably thinking that the image had gone offline) quit.

Happily, you don't have to bring down the adapter to request a new IP address: dhclient will do just as well. And indeed

/path/to/vboxmanage guestcontrol my-vagrant-image exec "/usr/bin/sudo" --username vagrant --password vagrant --verbose --wait-stdout dhclient

works: the NAT adapter picks up an IP address and, after a few seconds, Vagrant continues with the image configuration.

Something to hopefully help out even if it indeed takes another couple of years to get to bottom of the actual issue ;-)

Footnotes

  1. Or Application Release Automation (ARA), if you follow Gartner
  2. Check the platform support page for details
  3. For those not familiar with Vagrant, it's a powerful tool (written in Ruby) that allows you to declaritively define multiple related virtual images based on templates called 'boxes'. Vagrant orchestrates the interaction with VirtualBox to give you a very simple way of stopping, starting and configuring a cluster of images. In that sense, it's a little lit a VirtualBox-based CloudFormation.
  4. That's how Vagrant communicates with the image while configuring it
  5. You'll know because ifconfig will show that the eth0 adapter does not have an IPv4 address
Share

About Andrew Phillips

VP of Product Management
View all posts by Andrew Phillips →
Tags: Deployit, devops, Puppet, vagrant, virtual box
Filed under: XebiaLabs. Bookmark the permalink.
 
← Prev Post
Next Post →

4 Responses to Come on, vagrant up! Saving Vagrant images that don’t get a NAT address

  1. rafal says:
    July 19, 2012 at 11:43 pm

    thank you!

    Reply
  2. Victor N. says:
    January 12, 2013 at 4:09 am

    thanks !

    Reply
  3. Andrea says:
    January 21, 2013 at 12:05 am

    Thanks Andrew,

    this is really helpful. I’m doing something similar but when I run

    /path/to/vboxmanage guestcontrol my-vagrant-image exec “/usr/bin/sudo” –username vagrant –password vagrant –verbose –wait-stdout dhclient

    I’m getting

    Waiting for guest to start process …
    Waiting for process to exit …
    Exit code=1 (Status=500 [successfully terminated])

    Have you ever experienced this issue? How can I solve it?

    Thanks

    Reply
  4. Andrew Phillips says:
    January 24, 2013 at 9:23 pm

    Have you ever experienced this issue? How can I solve it?

    Hi Andrea!
    Thanks for commenting. As far as I understand, this issue has resolved itself already…phew! ;-)

    Regards

    Andrew

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

How Can We Help?

XebiaLabs USA
  • Live Chat Online
  • Phone:508.983.2515
    508.983.2512
  • 98 N. Washington St.
    Suite 501
    Boston, MA 02114
  • Email:info@xebialabs.com

Blog Authors

Sort by Blog Author
Vincent Partington
CTO
Andrew Phillips
VP of Product Management
Xebia Team

Tags

Agile agile operations Agile Strategy alm Application Deployment Application Lifecycle Management Application Release Automation ARA automation best practices cloud cloudbees Cloud Deployments configuration management Continous Integration Continuous Delivery Continuous Deployment Continuous Deployments Continuous Integration continuous value customization datapower Deployit Deployment deployment automation deployment package Deploy to JBoss. Scale. Deploy to Tomcat Deploy to Weblogic Deploy to WebSphere devops dpadmin DTAP Frameworks ITIL ITSM jenkins Oracle Puppet release automation release management virtual appliance Virtualization websphere Xebia Labs

Archives

  • May 2013 (2)
  • April 2013 (1)
  • March 2013 (3)
  • February 2013 (2)
  • January 2013 (4)
  • December 2012 (1)
  • November 2012 (3)
  • October 2012 (2)
  • September 2012 (1)
  • August 2012 (5)
  • July 2012 (3)
  • June 2012 (1)
  • May 2012 (3)
  • April 2012 (4)
  • March 2012 (1)
  • February 2012 (3)
  • January 2012 (2)
  • November 2011 (6)
  • October 2011 (3)
  • September 2011 (1)
  • August 2011 (3)
  • July 2011 (1)
  • June 2011 (2)
  • May 2011 (6)
  • April 2011 (2)
  • February 2011 (1)
  • January 2011 (4)
  • December 2010 (3)
  • November 2010 (2)
  • October 2010 (1)
  • August 2010 (1)
  • July 2010 (2)
  • June 2010 (3)
  • March 2010 (2)
  • February 2010 (1)
  • December 2009 (1)
  • November 2009 (1)
  • August 2009 (2)
  • July 2009 (1)
  • January 2009 (1)
  • August 2008 (1)
Copyright XebiaLabs B.V. ©.All rights reserved. Disclaimer
Home| About us| Products| Industry| Customers| Partners| News| Blog