如何转换files_copy_to_guest
为 Ruby 哈希?
.kitchen.yml
'my_cookbook':
'files_copy_to_guest':
-
'home/kevin/bin/script.sh' : '/vagrant/unix_scripts/script.sh'
'home/kevin/script2.sh' : '/vagrant/unix_scripts/script2.sh'
食谱/my_cookbook/attributes/default.rb
default['kevin']['files_copy_to_guest'] = []
食谱/my_cookbook/recipes/default.rb
files = node['kevin']['files_copy_to_guest'] # how to read attribute as Hash?
if files.nil? | files.empty? then
Chef::Log.warn("node['kevin']['files_copy_to_guest'] is nil or empty!")
end
files.each do |_, value|
value.each do |vm_dest, host_src|
file vm_dest do
owner user
group user
mode 0755
content ::File.open(host_src).read # <<< error on 'value'
end
end
end
我试过了:
files = YAML.load(node['kevin']['files_copy_to_guest']
,
但这没有用。我也读过那files.to_hash
也行不通。