Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tell Vagrant the ip of the host machine

I am using a vagrant box as a development machine for a project with an odd dependency I can only seem to install on ubuntu.

I created my database and have my app code on my host computer, and I share them with the vagrant instance through the NFS file share and postgres config.

My issue is that, as I move my computer from work to home, the ip for my computer changes and my database.yml becomes invalid. To get my server and console working, I need to update the yaml file with the host's new ip address each time I join a new network.

Since the rails app is running on vagrant (even though it's files are located on my host machine), any attempt for me to grep the ip out of ifconfig will fail because it's looking at the VM and not the host box. So something like this doesn't work:

# database.yml development:   host: <%= `ifconfig en0 | grep "inet " | cut -d" " -f2` %> 

Is there a config in the Vagrant file to pass this info through, or a way to create an ENV variable of the host ip that the ubuntu instance can read?

like image 387
jstim Avatar asked Nov 11 '13 22:11

jstim


People also ask

How do I find my vagrant VM IP?

The IP address can be determined by using vagrant ssh to SSH into the machine and using the appropriate command line tool to find the IP, such as ifconfig .

How do I change my IP address on vagrant?

To configure private or host-only networking in Vagrant with static IP address, open the Vagrantfile, find the following line and uncomment it. Here, 192.168. 121.60 is the IP address of the VM. Replace this with your own IP.

What is a vagrant host?

What Is Vagrant? Vagrant is an open-source (MIT) tool for building and managing virtualized development environments developed by Mitchell Hashimoto and John Bender. Vagrant manages virtual machines hosted in Oracle VirtualBox, a full x86 virtualizer that is also open source (GPLv2).


1 Answers

According to this, you can reach the host through the VM's default gateway.

Running netstat -rn on the guest should give you the relevant info, on my machine changing your code above to the following looks like it would get things going for you:

# database.yml development:   host: <%= `netstat -rn | grep "^0.0.0.0 " | cut -d " " -f10` %> 
like image 91
Matt Cooper Avatar answered Oct 11 '22 23:10

Matt Cooper