Search code examples
puppet

Puppet: manage the recursiveness of owner/group/mode attributes separately


I need to write a Puppet script to manage the directory /foo/bar such that:

  1. the file mode on /foo/bar is 777, but the permissions of everything within the directory are not managed by Puppet.
  2. the owner/group on /foo/bar and everything within it is baz.

That is, the first requirement is non-recursive, but the second attribute is recursive.

Puppet provides a single recursive attribute, which affects the behavior of owner, group, and mode simultaneously. This means that I cannot specify the desired behavior using a single resource declaration.

I tried using two resource declarations, but then I get the error

Error: Duplicate declaration: File[/foo/bar] is already declared in file /my/puppet/file.pp at line XX; cannot redeclare

Solution

  • Yes, this will not work. Mind that Puppet is not a scripting engine, but a tool to model your desired state.

    You will therefor have to decide how you want to manage your directory: As a single file system entry (recurse => false) or a whole tree (recurse => true). In the latter case, Puppet will always manage all properties for which you are passing values.

    In your situation, you will likely have to fall back to the workaround of managing the permissions of the directory itself through a different resource, likely an exec resource that calls chmod, independently of the file resource. The latter must not pass a value for mode in this constellation, otherwise the two resources will always work against one another.

    It's no ideal, but Puppet is not well equipped to deal with your specific requirements.