1

我编写了一个模块,用于rpm -e $package_name --nodeps删除没有依赖关系的单个 RPM。

我正在使用 Hiera,我已经hiera_include("classes", [])在 Puppet 服务器的site.pp文件中设置了。

该模块包括两个配置文件,第一个是init.pp

class rmpkg {
    $pkg_name = hiera_hash('rpm_name', undef)
        if $pkg_name != undef {
            create_resources("rmpack", $pkg_name)
        }
}

并且remove_rpm.pp

define rmpack ($rpm_name) {
exec { 'remove_rpm_${name}':
        command => "/bin/rpm -e ${rpm_name} --nodeps",
        path => "/bin/rpm",
        onlyif => "/bin/rpm -q --quiet ${rpm_name}",
 }

相关的 hiera 文件如下所示:

classes:
  - rmpkg

rpm_name:
    rpm_1: cups

我也试过:

classes:
  - rmpkg

rpm_name:
    rpm_1:
      rpm: cups

当我puppet agent -t在受影响的客户端上运行时,我收到以下错误:

[root@itaitest ]# puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: can't convert String into Hash at /etc/puppet/environments/production/modules/rmpkg/manifests/init.pp:4 on node itaitest.nj.company.com
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run
[root@itaitest ]#

我究竟做错了什么?

4

1 回答 1

2

尝试使用$pkg_name = hiera_hash('rpm_name::rpm_1::rpm', undef)

rpm_name 自己会加载类似的哈希值

{“rpm_1”:{“rpm”:“杯子”}}

将其传递给您定义的类型将给出您报告的错误

于 2016-02-02T11:39:48.893 回答