I am trying to create multiple directories and then copy files to each of the directories . For that I have created the following resource
$dirs=myapp
$appdirs = [ "/data/tomcat/$dirs/conf", "/data/tomcat/$dirs/config" ]
file { $appdirs:
ensure => "directory",
owner => "root",
group => "root",
}
file { "Copy Directory":
path => "/data/tomcat/$dirs/conf",
ensure => "present",
recurse => "true",
source => "puppet:///modules/tomcat8/conf/"
}
}
But I am getting the error already defined as shown below
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error:
Evaluation Error: Error while evaluating a Resource Statement, Cannot alias File[Copy Directory] to
["/data/tomcat/jacplus8/conf"] at /etc/puppetlabs/code/environments/production/manifests/classes/app.pp:20;
resource ["File", "/data/tomcat/jacplus8/conf"] already declared at /etc/puppetlabs/code/environments/production
/manifests/classes/app.pp:14 at /etc/puppetlabs/code/environments/production/manifests/classes/app.pp:20:1
on node Node-003.example.com
I need to copy files using the second resource file { "Copy Directory":} to the destination directory after it is created using the first resource file { $appdirs:} but it is giving me already defined error although the resource names are different . I am looking for workarounds so that I can create the directories and then copy files in it .
I resolved it like this by rewriting my manifests rules . For creating the directories , I remove the arrays and created each of the directory by using a single file resource .Also removed the path variable from filename and the directory to be created was provided as a resource name.
}
I had a situation like this:
with an error like
resource ["File", "/app/logs/archive"] already declared
Turns out,
$instance_name
was empty, so it was indeed, trying to declare/app/logs/archive
twice.