I’ve been using Vagrant for a several years now and love it. One of my few complaints was that each time I wanted to create a new machine I would need to edit my
/etc/hosts file. Then I found the excellent Vagrant plugin named Landrush.
My hosts file went from this:
How to Install Landrush
Installing and using Landrush is really easy.
Step 1: Install the plugin
vagrant plugin install Landrush
Step 2: Add the Landrush configuration to your Vagrantfile
config.vm.hostname = "project1.vagrant.dev" # if not set yet
config.landrush.enabled = true
There are more options you can add which can be found here.
If you don’t want to use the TLD of
vagrant.dev you can change it but keep it mind it will override that TLD on your computer. If you set your box’s hostname to
something.google.com and set
landrush.tld = google.com your searches won’t work very well unless you use Bing…nevermind, your searches still won’t work very well.
Step 3: Start up your vagrant box
That’s it. Landrush does everything else for you.
Test your box,
project1.vagrant.dev should be pointing to the IP address of your vagrant box.
I use Vagrant boxes for almost all of my development work. I recently came across this simple yet incredibly time-saving Vagrant tip. I use NFS to share files between my host computer and Vagrant box. While Vagrant makes this quite trivial to do Vagrant does require elevated permissions to mount the NFS share which means I need to enter my password everytime a Vagrant box starts up. This isn’t a huge deal as I only restart my Vagrant boxes a few times a week but I frequently will start up a box then go do something else while it boots and when I return later I see my box sitting at the password prompt. By adding a few lines to my /etc/sudoers file I just type vagrant up and I’m done.
1. Open up terminal. (CMD+SPACE, type in terminal)
2. Type in:
3. Enter your password.
4. Add these lines to the bottom of the file.
Cmnd_Alias VAGRANT_EXPORTS_ADD = /usr/bin/tee -a /etc/exports
Cmnd_Alias VAGRANT_NFSD = /sbin/nfsd restart
Cmnd_Alias VAGRANT_EXPORTS_REMOVE = /usr/bin/sed -E -e /*/ d -ibak /etc/exports
%admin ALL=(root) NOPASSWD: VAGRANT_EXPORTS_ADD, VAGRANT_NFSD, VAGRANT_EXPORTS_REMOVE
In case you aren’t familiar with vim, press i to insert text, when done, press ESC, then : followed by wq then press enter.
Your done! Wait 5 minutes (because you just typed in your password like 30 seconds ago). Then type vagrant up from your project root and don’t enter your password.
I’ve played with a few of Vagrant’s support provisioners: Puppet, Chef and Ansible. They all are very powerful and have tons of options but of course with options comes complexity. It took me hours to learn each provisioner and get it to do what I wanted and I had to fight with each one at each step.
When I first started using Vagrant I simply dismissed the simple shell provisioner. What serious developer would use such a simple tool? Real developers use real provisioners.
Anyway, long story short, I spent less than 1 hour today with the shell provisioner and got it to do exactly what I wanted. I guess I like to pretend that my provisioning needs were a lot more complicated than they actually were.