I would like to create/ensure a directory exists and recursively copy many files to it using native Puppet methods if possible. The file modes are same for all files but differ from the directory.
I am using Puppet6 version 6.10.0 on CentOS 6.10
This code will create/ensure my directory exists and copy all the files to it but sets the access rights and ownership exactly the same.
file { "/opt/dir1":
ensure => "directory",
owner => "user1",
group => "root",
mode => "0700",
recurse => true,
source => "puppet:///modules/mymodule/dir1",
}
What I get:
ls -la /opt/dir1"
drwx------ 2 user1 root 4096 Sep 23 20:31 .
drwxr-xr-x 7 user1 root 4096 Oct 6 15:20 ..
-rwx------ 1 user1 root 72 Oct 5 17:15 file1
What I want:
ls -la /opt/dir1"
drwx------ 2 user1 root 4096 Sep 23 20:31 .
drwxr-xr-x 7 user1 root 4096 Oct 6 15:20 ..
-rw-r--r-- 1 user1 root 72 Oct 5 17:15 file1
2
Answers
The Puppet
file
resource can’t set different modes for the apex directory and its files when usingrecurse
. https://puppet.com/docs/puppet/5.5/types/file.html#file-attribute-modeWould you be able to use an
archive
resource instead? With anarchive
resource, you can specify atar
file as the source, and the permissions will be set following those in thetar
file.If you are able to manage the permissions and mode in the source you can use this parameter
source_permissions => use
. Note, depending on your version you may get a deprecated warning:This would allow you do manage the mode in the
source
but still override the owner and group. you could also drop the owner and group params above and manage them in the source as well. However I’m not sure how this works if you have windows clients and a linux puppet master, or a missmatch in users/groups on the master vs agent