5

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,
  }
8

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.

  • Sorry, I just realized I had my nginx class declaration commented out when I tried that, looks like I'm still getting the error with the trailing slash. – quickshiftin Sep 20 '13 at 16:38
  • Thanks for your explanation, very helpful. I think I'll stick with my current solution. The multiple definitions approach isn't really suitable for me; one piece I haven't shown in the question is that I'm building the list of files dynamically. – quickshiftin Sep 30 '13 at 17:22
  • What way did you discover to do this, @quickshiftin? I'm not sure I understand which one you ended up choosing, and I'm trying to do something similar on my end. – Ehtesh Choudhury Oct 2 '14 at 21:39
  • It's been a while since I've worked on this project. Looking back at the code it seems I do pass an array to the source argument. I've just put up the relevant chunk of code on pastebin, but again have not looked at it in a while so YMMV. Hope it helps. – quickshiftin Oct 2 '14 at 23:36
  • I wish it would work, but no dice. I can't set parser=future in my puppet.conf either... I wonder if we're using different puppet versions? Mine is 3.7.1 – Ehtesh Choudhury Oct 3 '14 at 2:21
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

  • This solution would work if I wanted to push all the subdirectories, but as I said in my last comment to @Danila, I'm conditionally including certain directories based on parameters to the class. – quickshiftin Sep 30 '13 at 22:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.