puppet:为什么没有创建文件资源?
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']
}
执行代码失败,因为找不到脚本:
`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
如有任何帮助,我们将不胜感激。
谢谢
错误消息清楚地说明了问题。
Puppet 需要命令为“either fully qualified or a search path for the command must be provided”。
要么像这样完全限定你的命令:
command => "/usr/sbin/chkconfig --add ${shutdown_script}",
或像这样指定一些路径(通常当您不确定命令所在的位置时):
path => [ '/bin', '/sbin', '/usr/bin', '/usr/sbin' ],
这里其实也有一些问题,但是让我们依次过一遍。
ensure => file
file
资源应该指定 file
的 ensure
而不是当前。这更具体地指示 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 代理从未实际应用您的目录,因为您有编译错误:
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
service
您可以使用 service
资源中的 enable
属性添加并启用服务,而不是使用 exec
添加服务。我还建议将 require
元参数更改为 subscribe
,否则系统的服务管理器将不会接收您对服务脚本的更改。使用 subscribe
,Puppet 将指示系统在脚本更改时识别并重新配置服务。这也是您当前 exec
资源的问题。
service { 'puppet-report-shutdown':
enable => true,
subscribe => 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']
}
执行代码失败,因为找不到脚本:
`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
如有任何帮助,我们将不胜感激。 谢谢
错误消息清楚地说明了问题。
Puppet 需要命令为“either fully qualified or a search path for the command must be provided”。
要么像这样完全限定你的命令:
command => "/usr/sbin/chkconfig --add ${shutdown_script}",
或像这样指定一些路径(通常当您不确定命令所在的位置时):
path => [ '/bin', '/sbin', '/usr/bin', '/usr/sbin' ],
这里其实也有一些问题,但是让我们依次过一遍。
ensure => file
file
资源应该指定 file
的 ensure
而不是当前。这更具体地指示 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 代理从未实际应用您的目录,因为您有编译错误:
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
service
您可以使用 service
资源中的 enable
属性添加并启用服务,而不是使用 exec
添加服务。我还建议将 require
元参数更改为 subscribe
,否则系统的服务管理器将不会接收您对服务脚本的更改。使用 subscribe
,Puppet 将指示系统在脚本更改时识别并重新配置服务。这也是您当前 exec
资源的问题。
service { 'puppet-report-shutdown':
enable => true,
subscribe => File['shutdown-script'],
}