How to recursively change the owner and group on a directory with Chef?

后端 未结 5 2324
情歌与酒
情歌与酒 2021-02-18 15:45

the resource_directory has only 2 actions available: create and delete

I need to update the owner and group of a directory recursi

5条回答
  •  不思量自难忘°
    2021-02-18 16:27

    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
    

    Edit: fix to reflect comment below

提交回复
热议问题