Search code examples
vagrantpuppet

Puppet - How do I move the contents of a directory to another existing directory?


I have a directory full of .data files and .config/.config.example files. I need to move all of the .data files to a different existing directory on my system using puppet. The puppet code I currently have is incorrect I believe - what am I doing wrong?

file { 'Owasp .data files':
  ensure  => directory,
  path    => '/etc/nginx/',
  source  => '/usr/src/SpiderLabs-owasp-modsecurity-crs-0475e92/',
  recurse => true,
  ignore  => ['*.conf', '*.conf.example'],
}  

I was hoping this would copy everything except for the .conf and .conf.example files to /etc/nginx. However, I get the following error:

box: Error: Cannot alias File[Owasp .data files] to ["/etc/nginx"] at /vagrant/modules/nginx_test/manifests/test.pp:112; resource ["File", "/etc/nginx"] already declared at /usr/share/puppet/modules/nginx/manifests/config.pp:193


Solution

  • So your problem is actually that you have a file { '/etc/nginx': } declared somewhere else in your catalog. You need to only declare that resource once per catalog. That will fix your error. You also cannot declare two file resources with different titles that both have the same path parameter as Puppet tests that parameter for resource uniqueness.

    Regarding your specific question though, you would use the file URI in the source parameter: https://docs.puppet.com/puppet/latest/reference/type.html#file-attribute-source

    So for your situation, you would do:

    file { 'Owasp .data files':
      ensure  => directory,
      path    => '/etc/nginx/',
      source  => 'file:///usr/src/SpiderLabs-owasp-modsecurity-crs-0475e92/',
      recurse => true,
      ignore  => ['*.conf', '*.conf.example'],
    }