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

后端 未结 5 2425
情歌与酒
情歌与酒 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:30

    If this as a one-off to fix permissions your shortest path might be just knife ssh. (I just did that after ending up here on my own search.)

    knife ssh 'name:*' "sudo chown -R $user:$group /full/path/to/directory"

    knife ssh 'name:*' "sudo chmod -R 770 /full/path/to/directory"

    If I were setting this up from scratch I think I'd need to set up the directory path and proper permissions with one line (NOTE: explicitly apply the perms to each parent in the path)

    %w[ /foo /foo/bar /foo/bar/baz ].each do |path|
      directory path do
        owner 'root'
        group 'root'
        mode '0755'
      end
    

    and then create each individual file as a cookbook_file.

提交回复
热议问题