Ask Your Question
0

Fixing resource already defined error

asked 2017-04-14 05:36:37 -0600

queszama gravatar image

updated 2017-04-14 06:45:02 -0600

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 flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
0

answered 2017-04-19 14:18:16 -0600

msavel gravatar image

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/",
      }
edit flag offensive delete link more
0

answered 2017-04-14 06:23:18 -0600

puser gravatar image
  $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.

edit flag offensive delete link more

Comments

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

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

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

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

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

queszama gravatar imagequeszama ( 2017-04-17 04:50:05 -0600 )edit
-1

answered 2017-04-17 02:59:59 -0600

MGN210 gravatar image

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...

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2017-04-14 05:36:37 -0600

Seen: 82 times

Last updated: Apr 17