[英]puppet: Why is the file resource not created?
我在清单上有以下代码:
$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']
}
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
文件资源没有被创建,但是我找不到原因。 我尝试使用--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
任何帮助,将不胜感激。 谢谢
这里实际上存在一些问题,但是让我们按顺序解决它们。
ensure => file
file
资源应指定file
的ensure
,而不是现有file
。 这会更具体地指示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}"
exec
资源要么需要命令的完整路径,要么可以使用path
属性指定查找路径。 在这种情况下,最简单的解决方案是提供完整路径:
exec { 'chkconfig':
command => "/sbin/chkconfig --add ${shutdown_script}",
require => File['shutdown-script']
}
这实际上是您在这里的根本原因。 由于存在编译错误,因此Puppet代理从未真正应用您的目录,因此未创建该文件:
错误:无法应用目录:验证Exec [chkconfig]失败:'chkconfig --add /etc/init.d/puppet-report-shutdown'不合格且未指定路径。 请限定命令或指定路径。 在/etc/puppet/environments/dev02/modules/puppet_agent/manifests/init.pp:50
service
您可以使用service
资源中的enable
属性添加并启用它,而不是使用exec
添加service
。 我还建议您更改require
以进行subscribe
,因为否则您对服务脚本的更改将不会被系统的服务管理器接收。 使用subscribe
,如果脚本更改,Puppet将指示系统识别并重新配置服务。 这也是您当前的exec
资源的问题。
service { 'puppet-report-shutdown':
enable => true,
subscribe => File['shutdown-script'],
}
错误消息明确指出了问题所在。
木偶需要命令“ 完全合格或必须提供命令的搜索路径 ”。
可以像这样完全限定您的命令:
command => "/usr/sbin/chkconfig --add ${shutdown_script}",
或指定这样的路径(通常在不确定命令所在的位置):
path => [ '/bin', '/sbin', '/usr/bin', '/usr/sbin' ],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.