How to use a Puppet File Resource to give different permissions on a directory than to it's files?
06:51 20 Aug 2013

I would like to use Puppet to manage a directory. I want the directory to be owned by user root and group admin, with 0770 permissions.

I would like all files in the directory to be owned by user apache and group admin with 0600 permissions.

I have yet to find a way to achieve this using the file resource in Puppet. I have tried using two resources like so:

file { 'phpsessions_files':
    path => '/var/phpsessions',
    ensure => directory,
    owner => 'apache',
    group => 'admin',
    mode => 0600,
    recurse => true,
    before => File['phpsessions_dir'],
}

file { 'phpsessions_dir':
    path => '/var/phpsessions',
    recurse => false,
    owner => 'root',
    group => 'admin',
    mode => 0770,
}

But I am not allowed to create two file resources to the same path and I can't see how to achieve what I want with just one resource.

Your help is much appreciated.

ruby linux puppet