[英]puppet: Why is the file resource not created?
I have the following code on a manifest: 我在清单上有以下代码:
$shutdown_script = '/etc/init.d/puppet-report-shutdown'
file { 'shutdown-script':
ensure => present,
path => $shutdown_script,
owner => 'root',
group => 'root',
mode => '0755',
source => 'puppet:///modules/puppet_agent/puppet-report-shutdown.sh'
}
exec { 'chkconfig':
command => "chkconfig --add ${shutdown_script}",
require => File['shutdown-script']
}
The exec code is failing, because it cannot find the script: exec代码失败,因为它找不到脚本:
`Error: Failed to apply catalog: Validation of Exec[chkconfig] failed: 'chkconfig --add /etc/init.d/puppet-report-shutdown' is not qualified and no path was specified. Please qualify the command or specify a path. at /etc/puppet/environments/dev02/modules/puppet_agent/manifests/init.pp:50
The file resource is not being created, but I can't find why. 文件资源没有被创建,但是我找不到原因。 I tried running the agent with --debug
, but there's nothing useful there (to the best of my knoledge, at least): 我尝试使用--debug
运行代理,但是那里没有任何用处(至少据我所知):
Debug: /File[shutdown-script]/seluser: Found seluser default 'system_u' for /etc/init.d/puppet-report-shutdown
Debug: /File[shutdown-script]/selrole: Found selrole default 'object_r' for /etc/init.d/puppet-report-shutdown
Debug: /File[shutdown-script]/seltype: Found seltype default 'initrc_exec_t' for /etc/init.d/puppet-report-shutdown
Debug: /File[shutdown-script]/selrange: Found selrange default 's0' for /etc/init.d/puppet-report-shutdown
Any help would be appreciated. 任何帮助,将不胜感激。 Thanks 谢谢
There are actually a few problems here, but let us go through them sequentially. 这里实际上存在一些问题,但是让我们按顺序解决它们。
ensure => file
The file
resource should be specifying an ensure
of file
instead of present. file
资源应指定file
的ensure
,而不是现有file
。 That instructs Puppet more specifically as to what the type and content of the file
on the node should be: 这会更具体地指示Puppet有关节点上file
的类型和内容应为:
file { 'shutdown-script':
ensure => file,
path => $shutdown_script,
owner => 'root',
group => 'root',
mode => '0755',
source => 'puppet:///modules/puppet_agent/puppet-report-shutdown.sh'
}
command => "/sbin/chkconfig --add ${shutdown_script}"
The exec
resource either requires a full path to the command, or you can specify lookup paths with the path
attribute. exec
资源要么需要命令的完整路径,要么可以使用path
属性指定查找路径。 In this case, the easiest solution is to provide the full path: 在这种情况下,最简单的解决方案是提供完整路径:
exec { 'chkconfig':
command => "/sbin/chkconfig --add ${shutdown_script}",
require => File['shutdown-script']
}
This is actually your root cause here. 这实际上是您在这里的根本原因。 The file is not being created because the Puppet agent is never actually applying your catalog because you have a compilation error: 由于存在编译错误,因此Puppet代理从未真正应用您的目录,因此未创建该文件:
Error: Failed to apply catalog: Validation of Exec[chkconfig] failed: 'chkconfig --add /etc/init.d/puppet-report-shutdown' is not qualified and no path was specified. 错误:无法应用目录:验证Exec [chkconfig]失败:'chkconfig --add /etc/init.d/puppet-report-shutdown'不合格且未指定路径。 Please qualify the command or specify a path. 请限定命令或指定路径。 at /etc/puppet/environments/dev02/modules/puppet_agent/manifests/init.pp:50 在/etc/puppet/environments/dev02/modules/puppet_agent/manifests/init.pp:50
service
Instead of using exec
to add the service, you can add and enable it with the enable
attribute in the service
resource. 您可以使用service
资源中的enable
属性添加并启用它,而不是使用exec
添加service
。 I would also recommend changing the require
metaparameter to subscribe
, because otherwise your changes to the service script will not be picked up by the system's service manager. 我还建议您更改require
以进行subscribe
,因为否则您对服务脚本的更改将不会被系统的服务管理器接收。 With subscribe
, Puppet will instruct the system to recognize and reconfigure the service if the script changes. 使用subscribe
,如果脚本更改,Puppet将指示系统识别并重新配置服务。 This is also a problem with your current exec
resource. 这也是您当前的exec
资源的问题。
service { 'puppet-report-shutdown':
enable => true,
subscribe => File['shutdown-script'],
}
The error message clearly states the issue. 错误消息明确指出了问题所在。
Puppet needs the command to be " either fully qualified or a search path for the command must be provided ". 木偶需要命令“ 完全合格或必须提供命令的搜索路径 ”。
Either fully qualify your command like this: 可以像这样完全限定您的命令:
command => "/usr/sbin/chkconfig --add ${shutdown_script}",
or specify some path like this (usually when you're not sure where the command lies): 或指定这样的路径(通常在不确定命令所在的位置):
path => [ '/bin', '/sbin', '/usr/bin', '/usr/sbin' ],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.