5

I've been using vagrant for provisioning virtual machines (Linux only) and so far I've been happy with it. The two things I dislike about it - the hardcoded dependency on the user vagrant as well as making the very first interface a virtual box NAT - this causes some routing problems when communicating outside my LAN - it has eth0 created by vagrant and eth1 in bridged mode. As far as I understand, this was a design decision so there is no way around it.

I currently use vagrant

  • To create a Virtual Box virtual machine,
  • Set Static IP/MAC addresses
  • Create my own secondary user, and then treat it as a standalone "physical" host. I then use this user for any additional provisioning.

I can delete the user vagrant - the problem is that if I do vagrant up (or vagrant halt I believe to gracefully shutdown) it tries to ssh and the command hangs while it retries. The other problem is that I need to delete it each time I spin up a VM and I cannot when doing the first time provisioning because I am logged in as user vagrant.

I've been wondering if there is any other similar software/tool that just does a one time provision, sets up a static IP/MAC address, and allows for easy start/resume/shutdown when testing/deploying/maintaining.

I've been looking at Hashicorp's packer but I don't think it is possible to automatically configure IP/MAC addresses.

I am mainly looking for creating a virtual machine from scratch as if it was installed on a bare metal desktop computer by hand using a ISO on a CD.

In the end, using packer to provision and then using VirtualBox command line tools to recreate some of the functionality that vagrant does will suffice (sett IP/MAC address) - but I wonder if there are any other tools used for creating secure (no vagrant user and ssh only with private key) vms.

  • I'm tempted to say no, as no one does production on virtualbox but only development and as such the matter you describe is not a problem for a local test box. – Tensibai Apr 19 '18 at 7:52
  • Makes sense - what is used for production vms then? VM Ware? What is the best way to spin up a secure production VM with a static IP (only one user that can only ssh with private key) For now, I am trying to avoid deploying in the cloud so I am trying to avoid AWS (for instance). I am looking to manage my own VMs in a bare-metal server(s) that I would rent (or house in a Datacenter) – keyboard Apr 19 '18 at 14:51
  • I just mean you don't handle a production machine lifecycle with vagrant, so cleaning up the vagrant user at end of provisioning is the usual thing to do. The vsphere plugin for vagrant handle qetting up the IP properly. – Tensibai Apr 19 '18 at 15:22
  • Got it - so I assume you meant "dont handle a production lifecycle with [user] vagrant". what I am trying out now is using packer to create a virtual machine with my own user, (not vagrant), installing a public key during the vm installation, and then supplying a corresponding private key so that vagrant up know where to ssh. Although not really sure whether it will work the way I think it will – keyboard Apr 21 '18 at 2:14
  • I mean with vagrant, either you need to provision and destroy machines for test purpose and vagrant is OK, or you want to hande a longer life cycle and then vagrant is brittle and doesn't scale well to handle future destruction/re provisionning. – Tensibai Apr 21 '18 at 7:14
1

Have you considered to use Ansible?

You have some resources about using Ansible with VirtualBox and also vagrant

  • Yes, I am already heavily using ansible to provision the virtual machine once it is up. I am trying to see what is the best option to get the virtual machine to a state so that I can use ansible to provision it – keyboard Apr 19 '18 at 14:49
  • Oks, in case you want to change from vagrant and virtualbox maybe I can help you more, I'm currently using Google Cloud Platform and is very easy to create a custom image and launch with the API, then you don't need Ansible unless you want some extra customisation – wolmi Apr 19 '18 at 14:53
  • I am willing to change from vagrant/virtual box but I am currently trying to avoid deploying in the cloud (see reply #2 in original question) – keyboard Apr 19 '18 at 14:55
  • Instead of relying on custom images for individual VMs, I would rather have 1 base VM for a platform (like Ubuntu 16.04) and then use ansible to provision them differently - instead of having 3 custom Ubuntu 16.04 images. – keyboard Apr 19 '18 at 14:58
  • According to your last comment, you may wish to have a look at packer – Tensibai Apr 19 '18 at 15:23
1

I've been wondering if there is any other similar software/tool that just does a one time provision, sets up a static IP/MAC address, and allows for easy start/resume/shutdown when testing/deploying/maintaining.

Sure... a virtualbox VM is simply a XML file. You can copy/modify it as such easily. Use vboxmanage to clone the hdd images as necessary.

So, I don't think it would be too far fetched to just create a template VM in virtualbox once, and then use a little script to do the rest. This way, you have complete control over everything. As you are using Ansible to provision the fresh VM anyway, you don't lose that much by ditching Vagrant.

0

This is targeted for something a little more industrial strength, but have you looked at Foreman? I use the Foreman bootdisk plugin to provision my VMs and bare metal machines via kickstart using iPXE. You will need a DHCP server for that though...

  • Kind of nuclear weapon to kill a bug in my opinion, as you need to replace vbox dhcp server, pxe server and host foreman. This could be a single machine but still, that's a large oberhead over a vagrantfile. Again, that's just my opinion :) – Tensibai Jun 7 '18 at 18:10
  • Yeah... Reading between the lines, I figured this was probably overkill, but I don't actually host PXE/TFTP for my foreman bootdisk implementation. I also figured his home router probably serves DHCP... So it really just ends up being a foreman install? You can use it to manage bare metal, so you can therefore use it to manage vbox guests too. Just not quite so automagically - unless you use foreman-hooks – James Shewey Jun 7 '18 at 18:57
  • I mostly wanted to include it for completeness. It might be overkill for the OP, but perhaps not for the next person who stumbles upon this question with a similar problem. – James Shewey Jun 7 '18 at 18:59
  • Fair enough, I get the point even if I doubt someone searching about something solved by foreman will hit this question. But that's just my feeling :) – Tensibai Jun 7 '18 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.