1

I am working trying to give user group permissions on subfolders in a Linux environment. In Linux that would be:

chown -R user:group /var/lib/temp/*

How can I acheive the same in Chef with Ruby? I have tried this:

directory '/opt/jenkins/plugins' do
  owner 'jenkins'
  group 'jenkins'
  mode '0755'
  recursive true
  action :create
end

By specifying recursive it does not help.

  • You can refer :- http://stackoverflow.com/questions/23921708/how-do-i-change-recursively-the-owner-and-group-on-a-directory-with-chef – Mrigesh Priyadarshi Oct 19 '16 at 08:28
  • Possible duplicate of [How do I change recursively the owner and group on a directory with Chef?](http://stackoverflow.com/questions/23921708/how-do-i-change-recursively-the-owner-and-group-on-a-directory-with-chef)? – Amadan Oct 19 '16 at 08:28

1 Answers1

0

From the chef docs:

recursive
    Ruby Types: TrueClass, FalseClass

    Create or delete parent directories recursively. For the owner, group, and mode properties, the value of this attribute applies only to the leaf directory. Default value: false.

User and group permissions won't recurse, you'll have to set them on each sub-directory manually.

You could make this slightly easier by doing something like the following:

plugins = %w(plugin1 plugin2)
plugins.each do |plugin|
  directory "/opt/jenkins/plugins/#{plugin}" do
    owner 'jenkins'
    group 'jenkins'
    mode '0755'
    action :create
  end
end
Jack Bracken
  • 1,233
  • 12
  • 23
  • I do not want to define each subfolder. Since there are a bunch of them and a long hierarchi of folders. –  Oct 19 '16 at 08:55