Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing ruby variable to provisioner

I have a Vagrant file that defines a provisioner like this:

config.vm.provision :shell, :path => "set_rmi_hostname.sh", :args => "<ip_address> <target>"

ip_address and target are ruby variables defined in the same file:

ip = Socket.ip_address_list.detect{|intf| intf.ipv4_private?}
ip_address = ip.ip_address if ip
target = "my_target"

How can I expand these two variables and pass them to my script? Thanks

like image 678
sebi Avatar asked Aug 12 '26 07:08

sebi


1 Answers

Use #{variable} to use string expansion in Ruby:

config.vm.provision :shell, :path => "set_rmi_hostname.sh", :args => "#{ip_address} #{target}"

like image 106
cmur2 Avatar answered Aug 16 '26 18:08

cmur2