Puppet - copy several files to directory
I'd like to copy a number of files from puppet:// urls to a directory on an agent. I'm not sure if I'm doing something wrong here, but it seems like puppet doesn't like this
file { '/etc/nginx/conf.d':
path => '/etc/nginx/conf.d',
ensure => directory,
require => File['/etc/nginx/nginx.conf'],
source => ['puppet:///modules/nginx/app1.conf',
'puppet:///modules/nginx/app2.conf'],
sourceselect => all,
}
Here's what I get when trying to run the agent
Error: Could not rename temporary file /etc/nginx/conf.d.puppettmp_9046 to /etc/nginx/conf.d: Is a directory
If I change things around a tiny bit by creating directories in the module, and pointing the resource at them it works
mkdir module/files/app1 module/files/app2
mv module/files/app1.conf module/files/app1
mv module/files/app2.conf module/files/app2
new resource
file { '/etc/nginx/conf.d':
path => '/etc/nginx/conf.d',
ensure => directory,
require => File['/etc/nginx/nginx.conf'],
source => ['puppet:///modules/nginx/app1',
'puppet:///modules/nginx/app2'],
sourceselect => all,
recurse => true,
}
It just seems a little silly to have to create directories to copy over a list of single files.
Edit
I tried adding a trailing slash on the path, but jumped the gun thinking this was the solution. The reason was I had my nginx class declaration commented out in the node definition. Trying it though I get the same error from above.
file { '/etc/nginx/conf.d/':
path => '/etc/nginx/conf.d/',
ensure => directory,
require => File['/etc/nginx/nginx.conf'],
source => ['puppet:///modules/nginx/app1.conf',
'puppet:///modules/nginx/app2.conf'],
sourceselect => all,
}
Solution 1:
missing a trailing / on your destination.
Well a few things first of all:
Why are you ensuring directory and having content (source param)? Make two resources one for the directory and one for the two files in the directory.
It gives you an error because you're sourcing a file to a directory, not sourcing a file into a directory. A directory can only have a directory as a source.
So, you can either create individual definitions, since you are defining only two files you want sourced into the directory. The other is to create a directory under module/files and put the files in there. Then when you do the source definition you specify the directory not the files.
Hope this helps. The execution you already do yourself.
Solution 2:
what is wrong with
file { '/etc/nginx/conf.d':
path => '/etc/nginx/conf.d',
ensure => directory,
require => File['/etc/nginx/nginx.conf'],
source => 'puppet:///modules/nginx',
recurse => true,
}
? this solution keeps whole directories in sync