2
好吧,我很新的Ruby(我來自PHP,Symfony2和AngularJS)和相對較新的,當涉及到正確寫Vagrantfiles。我試圖在堅持DRY原則的同時創建一個多機器環境。試圖循環散列Vagrant框,失敗
當我讀到Vagrantfiles理解Ruby語法時,我查找了Ruby定義關聯數組的方式。這很容易,顯然不是。
我Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
#hash for boxes: 'box_name' => 'last_ip_octet'
boxes = {
'frontend' => '10',
'qp' => '11'
}
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "chef/ubuntu-14.04"
#All machines, see the hash defined in top of the Vagrantfile for all the boxes
boxes.each do |key, value|
config.vm.define "#{key}.qp" do |#{key}_qp|
#{key}_qp.vm.network "private_network", ip: "192.168.51.#{value}"
#{key}_qp.vm.provision "shell", path: "../provisioning/agentinstall.sh"
#{key}_qp.vm.synced_folder "./share/#{key}.qp", "/var/www/html"
end
end
end
我的問題如下:
There is a syntax error in the following Vagrantfile. The syntax error
message is reproduced below for convenience:
/Users/Zowie/Documents/vagrant/project/temp/Vagrantfile:30: syntax error, unexpected keyword_end, expecting '|'
end
^
不幸的是,我無法找到使用哈希或任何東西Vagrantfiles類似的任何信息。 我真的希望你能幫助我,因爲寫一個有很多重複的超長流浪文件我感覺不好...
在此先感謝!
Jeeeeeeez,我現在注意到,「#」註釋掉行的文件中。我會在30分鐘內檢查它!如果你正在閱讀,請稍等一下。謝謝! – ZvL 2014-09-30 09:32:26
你是對的 - 這是'config.vm.define'這行中的散列,這是破壞性的。 – 2014-09-30 09:53:37
修正了它!感謝您的確認。回答自己的問題,以幫助有同樣問題的任何人。 – ZvL 2014-09-30 10:43:25