puppet:为什么不创建文件资源?
我在清单上有以下代码:puppet:为什么不创建文件资源?,puppet,Puppet,我在清单上有以下代码: $shutdown_script = '/etc/init.d/puppet-report-shutdown' file { 'shutdown-script':
$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
任何帮助都将不胜感激。
谢谢错误消息清楚地说明了问题 傀儡需要得到命令 或者完全限定您的命令,如下所示:
command => "/usr/sbin/chkconfig --add ${shutdown_script}",
或者在不确定命令的位置时,通常指定如下路径:
path => [ '/bin', '/sbin', '/usr/bin', '/usr/sbin' ],
这里实际上有一些问题,但让我们按顺序讨论一下 确保=>文件 文件资源应该指定一个文件,而不是当前文件。这将更具体地指示Puppet节点上文件的类型和内容:
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\u 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”未限定且未指定路径。请限定命令或指定路径。at/etc/puppet/environments/dev02/modules/puppet_agent/manifests/init.pp:50
服务
您可以使用服务资源中的enable属性添加并启用服务,而不是使用exec来添加服务。我还建议将require元参数更改为subscribe,因为否则系统的服务管理器将无法获取对服务脚本所做的更改。使用subscribe,Puppet将指示系统在脚本更改时识别并重新配置服务。这也是当前exec资源的一个问题
service { 'puppet-report-shutdown':
enable => true,
subscribe => File['shutdown-script'],
}
非常感谢。这是一个非常有用的答案。尽管根本原因是查找路径,正如您和@SamK所建议的,我也编辑了清单以遵循您的建议。我还是一个木偶新手,所以一点“良好实践”的建议总是值得赞赏的