如何使用Chef递归更改目录上的所有者和组? [英] How to recursively change the owner and group on a directory with Chef?

查看:102
本文介绍了如何使用Chef递归更改目录上的所有者和组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

资源目录只有两个可用操作:创建删除

the resource_directory has only 2 actions available: create and delete

我需要递归更新目录的所有者和组。

I need to update the owner and group of a directory recursively.

我该怎么办

使用简单的 resource_execute

execute "chown-data-www" do
  command "chown -R www-data:www-data /var/www/myfoler"
  user "root"
  action :run
end


推荐答案

您可以将默认操作设置为不执行任何操作,然后拥有可能使事情搞砸的资源,通知烫发修复程序:

You can set the default action to nothing then have resources that may screw things up notify the perm fixer:

execute "chown-data-www" do
  command "chown -R www-data:www-data /var/www/myfoler"
  user "root"
  action :nothing
end

resource "that may screw up perms" do
  stuff "one two three"
  notifies :run, execute "chown-data-www"
end

使用更多选项,您可以操作:运行,但如果父文件夹已经是正确的权限,则不运行。您可以更改它以包含更深/问题的文件/目录,或者使用类似于

with more options you could have the action :run but not if the parent folder is already the correct perms. You could alter this to include a deeper/problem file/directory, or with a find command similar to this

execute "chown-data-www" do
  command "chown -R www-data:www-data /var/www/myfoler"
  user "root"
  action :run
  not_if '[ $(stat -c %U /var/www/myfolder) = "www-data" ]'
end

编辑:修复以下内容以反映评论

fix to reflect comment below

这篇关于如何使用Chef递归更改目录上的所有者和组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆