Puppet Error – Resolve Resource Already Defined Error on RHEL6

puppetrhel6

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 .

Best Answer

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.

   class app {
$dirsname=myapp

file { 'directory':
     path => "/data/tomcat/${dirsname}/",
     ensure => "directory",
     owner => "root",
     group => "root",
}

file { '/data/tomcat/${dirsname}/conf':
    ensure => "directory",
    owner => "root",
    group => "root",
    require => File['directory'],
   }

file { '/data/tomcat/$dirsname/config':
    ensure => "directory",
    owner => "root",
    group => "root",
    require => File['directory'],
  }

file { '/data/tomcat/$dirsname/conf/':
path => "/data/tomcat/$dirsname/conf/",
ensure => "present",
recurse => "true",
source => "puppet:///modules/conf/"

}

file { '/data/tomcat/$dirsname/config/':
path => "/data/tomcat/$dirsname/config/",
ensure => "present",
recurse => "true",
source => "puppet:///modules/config/"
 }
}
Related Topic