I am trying to change owner, group and permissions of every file in directories:
%w(/etc/nginx/ /etc/nginx/conf.d/ /var/l0g/nginx/).each do |path|
directory path do
owner "owner1"
group "group1"
mode '0755'
end
end
however it only changes values of directories, specified in %w(), i was expecting this do be recursive especially with directory keyword.
How can i make this script change owner, group and permission of all files in specified dirs including directories themselves?
Thanks for help!
There is a
recursiveproperty for thedirectoryresource which is documented as such:As such, there is no builtin way to recursively set the permissions of all files within a directory. This would also NOT be a good idea in any case as your
modeof755would mark all configuration files as executable for everyone. As nginx configuration files are generally not intended to be executable, this would likely do the wrong thing!Still, if you absolutely want to do this, you could write a bit of Ruby in a
ruby_blockresource, such asA slightly more "correct" version would be:
Here, we use a symbolic mode description instead of the strictly numeric one. This allows us to use the
Xspecification rather than justx. The chmod specification reads here:user (i.e. owner), set theread andwrite bits. If the file is a directory or currently has the execute bit set, the the execute bit.group andothers, set just theread bit. If the file is a directory or currently has the execute bit set, the the execute bit.With this, all directories will have the execute/search bit set, and only those files who previously had the execute bit set will retain it (but no new files fill gain the execute bit).
As some final notes:
/etc/nginx/conf.dis already included in/etc/nginx, you can omit it from the list./var/l0g/nginx/(with a "zero" character in the path), you likely mean/var/log/nginx/(with a small o) instead.