Adding VM /etc/host entries that point to host machine with Vagrant and Puphpet -


I know that to add entries to the host's / etc / hosts file, which points to VM, But I'm actually trying to find a dynamic way to move in the other direction. On my machine, I have installed MySQL with a large DB. I do not want to put it inside VM, I need VM so that it can be accessed.

I can easily set it up manually. After being elated, I joined V.M. I can do SSH and edit / etc / hosts there and create an entry like hostmatchine and can point at my IP address on time. However, as I move my host machine from home to work, I must update that entry.

No one Is there any way inside the ARB file or to create a passionate way to create such an entry in the IP host machine and VM host file?

One way to do this is to do this. Since warranty file is a ruby ​​script, we can use some logic to find local hostnames and IP addresses. Then we use those simple script in a script that adds them to the guest / etc / hosts file.

Example Vargrantfile : To set host IP address, host Host IP address set in / etc / hosts # - Some other magic required Can be # (Reference: http://stackoverflow.com/questions/5029427/ruby-get-local-ip-nix) Requires 'socket' def my_first_private_ipv4 Socket.ip_address_list.detect {| intf | Intf.ipv4_private?} End ip = my_first_private_ipv4.ip_address () # Determination of host name - Some other magic may be required Hostname = `hostname` script = & lt; & Lt; SCRIPT echo "# {ip} # {hostname}" | TA / AIT / host script VAGRANTFILE_API_VERSION = "2" warrant. Configure (VAGRANTFILE_API_VERSION). Configure | Config.vm.box = "hashicorp / exact64" config.vm.hostname = "iptest" config.vm.provision: shell, inline = & gt; Script config.vm.provider "virtualbox" do | vb # Vb.gui = true vb.name = "iptest" vb.customize ["modifyvm", id, "--memory", "1000"] end of end

Note: echo | If you are provisioning multiple times (without destroying VM), if you run into it, you need a better solution. Might be possible.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -