我想动态安装共享文件夹,以从YAML文件中获取数据。
我尝试了不同的方法,但似乎都不合适。
这是相关代码:
Vagrant.configure("2") do |config|
config.vm.synced_folder 'site/project/templates/' , '/tmp/vagrant-puppet/templates'
config.vm.synced_folder 'site/project/lib/facter', '/var/lib/puppet/lib/facter', create: 'true'
config.vm.synced_folder 'site/project/lib/puppet/parser/functions', '/var/lib/puppet/parser/functions', create: 'true'
config.vm.synced_folder '.', '/vagrant', create: 'true', owner: 'root', group: 'root'
config.vm.synced_folder '~/projects', '/root/projects'
{
:'onebox' => {
:os => 'Ubuntu1404',
:puppetmode => 'apply',
:ip => "192.168.56.120",
:public_network => false,
:manifest_file => 'site.pp',
:autostart => true
},
}.each do |name,cfg|
config.vm.define name , autostart: cfg[:autostart] do |local|
vagrantconfig = YAML.load(File.open(File.join(File.dirname(__FILE__), "vagrantconfig.yaml"), File::RDONLY).read)
if vagrantconfig
cfg[:ram] = vagrantconfig["ram"]
cfg[:cpus] = vagrantconfig["cpus"]
cfg[:public_network] = vagrantconfig["public_network"]
else
puts "no vagrantconfig.yaml found, skipping custom local settings"
end
我想替换
config.vm.synced_folder '~/projects', '/root/projects'
使用
if cfg[:synced_folder]
config.vm.synced_folder cfg[:synced_folder], '/root/projects'
end
或类似的东西。
我已经尝试加入if vagrantconfig
语句,但是没有用