4

I am using puppet 3.8.4 on debian. I want to recursively set the owner and group on a set directory, but only set permissions on the directory itself ie. I don't want to chmod anything in the dir only chown/chgrp it.

I have tried the following...

file {[
    "/foo/bar" ,
  ] :
  ensure  => directory,
  owner   => root,
  group   => bar,
  recurse => true,
  require       => [
    User[root],
    Group[bar],
  ],
}
file {[
    "/foo/bar" ,
  ] :
  ensure  => directory,
  mode    => 0640,           # +x automatically added to directories
  recurse => false,
}

But of course puppet then complains of a Duplicate declaration: File[/foo/bar] if you do that.

Is there a way in puppet to do this without having to do the top level directory and then all the files and folders under it explicitly?

Vagnerr
  • 1,275
  • 1
  • 15
  • 20

2 Answers2

2

Just to put it as an answer also: you can't.

The namevar parameter is path, so you can't have 2 file resources with the same path.

Check the documentation about file resource.

рüффп
  • 620
  • 1
  • 11
  • 25
cristi
  • 573
  • 4
  • 18
  • I thought perhaps you could get around this by using two slashes at the beginning of the path, since [OSes are allowed to treat `//` and `/` differently at the beginning of an absolute path](https://unix.stackexchange.com/a/12291/135943). But nope, Puppet still considers them to be duplicate paths. – Wildcard Aug 31 '23 at 18:05
-1

Not tested, but this should work:

For the second resource, just name it differently and set an explicit path:

file {"/foo/bar_root":
  path    => "/foo/bar",
  ensure  => directory,
  mode    => 0640,           # +x automatically added to directories
  recurse => false,
}
Sven
  • 98,649
  • 14
  • 180
  • 226
  • 1
    Not quite. The namevar parameter is path, so you can't have 2 file resources with the same path: https://docs.puppetlabs.com/references/latest/type.html#file – cristi Nov 06 '15 at 08:14
  • sadly cristi is right it still knows its a duplicate :-) – Vagnerr Nov 06 '15 at 15:04
  • Unfortunately yes, but thinking again about this tells me this is not a bad thing, as it would be all too easy to create conflicting resource definitions. – Sven Nov 06 '15 at 22:20