Passing ruby variable to provisioner

好久不见. 提交于 2019-12-14 03:49:44

问题


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


回答1:


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

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



来源:https://stackoverflow.com/questions/17745840/passing-ruby-variable-to-provisioner

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!