我在Chef中有一段红宝石代码,以递归方式创建一些目录
# Deploy config files from files
unless instance[:directories].nil?
instance[:directories].each do |dir|
unless File.directory?("#{dir[:source_dir]}")
remote_directory "#{dir[:path]}" do
source "#{dir[:source_dir]}"
owner "#{config[:owner]}"
group "#{config[:group]}"
recursive true
notifies :run, "execute[change permissions]", :immediately
notifies :restart, "service[#{instance[:name]}]"
end
end
end
end
根据规范,remote_directory资源仅将所有者/组权限应用于指定路径中的叶节点,但不应用于创建的中间节点。
我计划在创建路径时通知执行命令并递归地应用权限。如何传递参数(在本例中为#{dir [:path]})以执行如下命令。
execute "change permissions" do
command "chown -R #{config[:owner]}:#{config[:group]} #{path}"
user "root"
action :nothing
end
答案 0 :(得分:5)
你没有。将执行资源包含在远程目录资源中:
unless instance[:directories].nil?
instance[:directories].each do |dir|
unless File.directory?("#{dir[:source_dir]}")
path = dir[:path]
remote_directory path do
source dir[:source_dir]
owner config[:owner]
group config[:group]
recursive true
notifies :run, "execute[change-permission-#{path}]", :immediately
notifies :restart, "service[#{instance[:name]}]"
end
execute "change-permission-#{path}" do
command "chown -R #{config[:owner]}:#{config[:group]} #{path}"
user "root"
action :nothing
end
end
end
end