1

I am getting the following error during directory creation using file resource

Error: Cannot create /data/tomcat/${dirsname}/conf; parent directory /data/tomcat/${dirsname} does not exist Error: /Stage[main]/App/File[/data/tomcat/${dirsname}/conf]/ensure: change from absent to directory failed: Cannot create /data/tomcat/${dirsname}/conf; parent directory /data/tomcat/${dirsname} does not exist` Error: Cannot create /data/tomcat/$dirsname/config; parent directory /data/tomcat/$dirsname does not exist Error: /Stage[main]/App/File[/data/tomcat/$dirsname/config]/ensure: change from absent to directory failed: Cannot create /data/tomcat/$dirsname/config; parent directory /data/tomcat/$dirsname does not exist` 

But technically the directories are getting created as can can be seen from the puppet command output

Notice: /Stage[main]/App/File[/data/tomcat/$dirsname/conf/]/ensure: created Notice: /Stage[main]/App/File[/data/tomcat/jacplus8/conf/context.xml]/ensure: defined content as '{md5}ba798c2de6dd554035c05352891a0d07' Notice: /Stage[main]/App/File[/data/tomcat/jacplus8/conf/server.xml]/ensure: defined content as '{md5}6298e53557ead6855cef9bcbb082a074'` Notice: /Stage[main]/App/File[/data/tomcat/$dirsname/config/]/ensure: created Notice: /Stage[main]/App/File[/data/tomcat/jacplus8/config/runtime.settings]/ensure: defined content as '{md5}2e2596f0f9107c8cfc783da3d5004dae'` 

I checked the directory structure , the directories are available but not sure why it is showing the error messages. My manifests rule are as follows

class app { $dirsname=myapp8 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/" } } 

1 Answer 1

3
file { '/data/tomcat/$dirsname/conf': 

Replace the single quotes with double quotes, then the variable will be interpolated. Do this on all lines with single quotes and variables (there are four).

As you can see from the log, it's creating directories with the variable name in it, not the directory with the variable replaced:

Notice: /Stage[main]/App/File[/data/tomcat/$dirsname/conf/]/ensure: created 
4
  • If I reply single quotes with double quotes , it gives me "Already defined error" like below: Failed to apply catalog: Cannot alias File[/data/tomcat/$dirsname/conf/] to ["/data/tomcat/myapp/conf"] at /etc/puppetlabs/code/environments/production/manifests/classes/app.pp:66; resource ["File", "/data/tomcat/myapp/conf"] already declared at /etc/puppetlabs/code/environments/production/manifests/classes/app.pp:20 Commented Apr 19, 2017 at 7:18
  • Also for the manifests as in original description, I can see that the directories are physically created on the system . Only issue was the error message Commented Apr 19, 2017 at 7:20
  • That's a different problem then, which you already filed at serverfault.com/questions/844830. You shouldn't manage the same directory multiple times. Commented Apr 19, 2017 at 7:29
  • Thanks. After creating the directory , I am pushing files to that directory using two different file resources Commented Apr 19, 2017 at 7:32

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.