# Fixing resource already defined error

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", "/data/tomcat/$dirs/libs","/data/tomcat/$dirs/deploy","/data/tomcat/$dirs/webapps","/data/tomcat/$dirs/temp","/data/tomcat/$dirs/work" ] file { "/data/tomcat/$dirs":
path => "/data/tomcat/$dirs", ensure => "directory", owner => "root", group => "root", } file {$appdirs:
ensure => "directory",
owner => "root",
group => "root",
}
file { "/data/tomcat/$dirs/conf/": path => "/data/tomcat/$dirs/conf/",
ensure => "present",
recurse => "true",
source => "puppet:///modules/tomcat8/conf/"
}

file { "/data/tomcat/$dirs/config": path => "/data/tomcat/$dirs/config/",
ensure => "present",
recurse => "true",
source => "puppet:///modules/tomcat8/config/"

}
}


But I am getting the error already defined as shown below

    Error: Failed to apply catalog: Cannot alias File[/data/tomcat/myapp/conf/] to ["/data/tomcat/myapp/conf"] at /etc/puppetlabs/code/environments/production/manifests/classes/app.pp:20; resource ["File", "/data/tomcat/myapp/conf"] already declared at /etc/puppetlabs/code/environments/production/manifests/classes/app.pp:14


My modules directory is as follows:

/etc/puppetlabs/code/environments/production/modules/tomcat8/conf/files/


I need to copy files using the second resource file { "/data/tomcat/$dirs/conf/":to the destination directory after it is created using the first resource file {$appdirs:} but since it is already defined in first case , it is failing for me . I am looking for workarounds so that I can create the directories and then copy files in it .

edit retag close merge delete

Sort by » oldest newest most voted

could you move out a folder and copy the entire structure under it? like the following:

file { "/data/tomcat/$dirs/": ensure => "present", recurse => "true", source => "puppet:///modules/tomcat8/", require => File[$appdirs],
}


Another option might be to do something like the following (I'm trying to do this but getting the same error you are getting now):

  $appdirs = [ "conf", "config", "libs", "deploy", "webapps", "temp", "work" ] file {$appdirs:
path => "/data/tomcat/$dirs/$name/",
ensure => "present",
recurse => "true",
source => "puppet:///modules/tomcat8/$name/", }  more $appdirs = [  "/data/tomcat/$dirs/conf", "/data/tomcat/$dirs/config", "/data/tomcat/$dirs/libs","/data/tomcat/$dirs/deploy","/data/tomcat/$dirs/webapps","/data/tomcat/$dirs/temp","/data/tomcat/$dirs/work" ]  and file { "/data/tomcat/$dirs/conf/":
path => "/data/tomcat/$dirs/conf/", ensure => "present", recurse => "true", source => "puppet:///modules/tomcat8/conf/" }  the first element of$appdirs and this file hae the same path.

more

yeah....I am aware of that...But I need to copy files to the directory....How can I achieve that

( 2017-04-14 06:41:19 -0600 )edit

the name of the file resources something different, leave the paths the same.

( 2017-04-14 07:52:22 -0600 )edit

I changed the resource name , but no luck...

( 2017-04-17 04:50:05 -0600 )edit

Can we just use the full absolute path to the file instead? I mean it crossed my mind that perhaps we make this too complicated than it should be, it's a path to the file for Pete's sake, if it were up to me I would use '/tmp/puppet/tempfiles/myfile.txt' this way it gets cleaned up by itself too..... Just saying... where is puppet:///modules/ on the file system anyway? It seems to change with any new release version, is it /etc/puppetlabs/code/environments/production??? puppet.conf points to /opt/puppetlabs not to /etc/puppetlabs. Sorry for not helping and not answering the question, I guess I face the similar problem. I will dig deeper and share what I find

...OK after while digging - puppet config print modulepath - was my friend, just don't forget about the 'files' directory when using puppet:/// protocol See if this helps, it did help me... https://docs.puppet.com/puppet/4.10/d...

more