I have a cube of code in Chef that recursively creates some directories
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
According to the specification, the remote_directory resource applies the owner / group rights only to the node sheet in the specified path, and not to the created intermediate nodes.
I plan to notify the execute command when a path is ever created and permissions are applied recursively. How to pass an argument (in this case # {dir [: path]}) to execute the command, as shown below.
execute "change permissions" do
command "chown -R #{config[:owner]}:#{config[:group]} #{path}"
user "root"
action :nothing
end
source
share