There is no way to have non executable files in a recursive file definition since directories must have execute permissions.
That's not quite true. If you set the mode to 0640 for the initial directory, then puppet will make sure all directories are also executable. For example given:
class recurse { |
file { '/tmp/recurse': |
ensure => directory, |
mode => '640', |
recurse => true, |
source => 'puppet:///modules/recurse', |
} |
}
|
Where the module contains:
# tree -p /etc/puppetlabs/code/environments/production/modules/recurse/files |
/etc/puppetlabs/code/environments/production/modules/recurse/files |
└── [drwxr-xr-x] dir |
└── [drwxr-xr-x] dir |
└── [-rw-r-----] file
|
Will produce:
# puppet agent -t |
Info: Using configured environment 'production' |
Info: Retrieving pluginfacts |
Info: Retrieving plugin |
Info: Retrieving locales |
Info: Loading facts |
Info: Caching catalog for localhost |
Info: Applying configuration version '1535560649' |
Notice: /Stage[main]/Recurse/File[/tmp/recurse]/ensure: created |
Notice: /Stage[main]/Recurse/File[/tmp/recurse/dir]/ensure: created |
Notice: /Stage[main]/Recurse/File[/tmp/recurse/dir/file]/ensure: defined content as '{md5}d41d8cd98f00b204e9800998ecf8427e' |
Notice: Applied catalog in 0.09 seconds
|
and the resulting file is read-only, but the directories are executable:
# tree -p /tmp |
/tmp |
└── [drwxr-x---] recurse |
└── [drwxr-x---] dir |
└── [drwxr-x---] dir |
└── [-rw-r-----] file
|
You can also declare an explicit resource whose mode will be merged with the generated resource:
class recurse { |
file { '/tmp/recurse': |
ensure => directory, |
mode => '640', |
recurse => true, |
source => 'puppet:///modules/recurse', |
} |
file { '/tmp/recurse/dir/dir': |
ensure => directory, |
mode => '777', |
} |
}
|
Will set the permission of the recursively generated directory to 777:
# puppet agent -t |
Info: Using configured environment 'production' |
Info: Retrieving pluginfacts |
Info: Retrieving plugin |
Info: Retrieving locales |
Info: Loading facts |
Info: Caching catalog for localhost |
Info: Applying configuration version '1535562162' |
Notice: /Stage[main]/Recurse/File[/tmp/recurse/dir/dir]/mode: mode changed '0750' to '0777'
|
# tree -p /tmp |
/tmp |
└── [drwxr-x---] recurse |
└── [drwxr-x---] dir |
└── [drwxrwxrwx] dir |
└── [-rw-r-----] file
|
|