1

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 .

3 Answers 3

1

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/" } } 
0

I had a situation like this:

 $dirs = [ "/app/logs", "/app/logs/archive", "/app/logs/archive/${instance_name}" ] 

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.

0

As info for those still landing here (search engines show me this result as 1st).

If some resource is already declared (for example in a module) and it conflicts with a declaration in a node or a class that is managed by you, one way to avoid the conflict is.

if !Resource['title'] { #then you manage the resource } 

example

if !Package['centos-release-scl'] { # this is already declared (by the zabbix module) package { 'centos-release-scl': ensure => installed, } } 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.