使用文件资源创建目录时出现以下错误
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`
但从技术上讲,目录正在创建,可以从puppet
命令输出中看到
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'`
我检查了目录结构,目录可用,但不确定为什么会显示错误消息。我的清单规则如下
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
file { '/data/tomcat/$dirsname/conf':
将单引号替换为双引号,然后变量将被插入。在所有包含单引号和变量的行上执行此操作(共有四行)。
从日志中可以看出,它正在创建包含变量名称的目录,而不是替换变量的目录:
Notice: /Stage[main]/App/File[/data/tomcat/$dirsname/conf/]/ensure: created