Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vagrant : how to get hostonly ip address from within chef recipe?

I am trying to retrieve the hostonly ip address specified in the Vagrantfile:

config.vm.network :hostonly, "33.33.33.33"

in a recipe file :

mycookbook/files/default/xdebug.ini

[xdebug]
zend_extension = "/usr/lib/php/modules/xdebug.so"
xdebug.remote_enable = 1
xdebug.remote_handler = "dbgp"
xdebug.remote_host = "***HERE***"
xdebug.trace_output_dir = "/tmp"
xdebug.max_nesting_level = 200
like image 764
Alexandre Mélard Avatar asked Jan 25 '13 08:01

Alexandre Mélard


2 Answers

node[:network][:interfaces][:eth1][:addresses].detect{|k,v| v[:family] == "inet" }.first

Actually you can find out all the node attributes by logging into the VM (with vagrant ssh) and running shef. And inspect there the node object.

like image 131
Draco Ater Avatar answered Oct 02 '22 13:10

Draco Ater


If you want to retrieve the IP of the Host machine, you can use this:

in your recipe:

your/cookbook/path/recipes/default.rb

ip = node[:network][:interfaces][:eth1][:addresses].detect{|k,v| v[:family] == "inet" }.first
remote_ip = ip.gsub /\.\d+$/, '.1'

template "/etc/php.d/xdebug.ini" do
  source "xdebug.ini.erb"
  owner "root"
  group "root"
  mode 0644
  variables({
              "remote_host" => remote_ip
            })
end

and in the template: your/cookbook/path/templates/default/xdebug.ini.erb

[xdebug]
zend_extension = "/usr/lib/php/modules/xdebug.so"
xdebug.profiler_append = 0
xdebug.profiler_enable = 0
xdebug.profiler_enable_trigger = 0
xdebug.profiler_output_dir = "/tmp"
xdebug.profiler_output_name = "cachegrind.out.%t-%s"
xdebug.remote_enable = 1
xdebug.remote_handler = "dbgp"
xdebug.remote_host = <%= @remote_host %>
xdebug.trace_output_dir = "/tmp"
xdebug.max_nesting_level = 200
like image 31
Alexandre Mélard Avatar answered Oct 02 '22 12:10

Alexandre Mélard