Puppet 希拉:可以';无法将字符串转换为哈希,原因可能是什么?

Puppet 希拉:可以';无法将字符串转换为哈希,原因可能是什么?,puppet,rpm,centos6,hiera,Puppet,Rpm,Centos6,Hiera,我编写了一个模块,它使用rpm-e$package\u name--nodeps删除一个rpm,而不依赖它 我正在使用Hiera,我在Puppet服务器的site.pp文件中设置了Hiera\u include(“classes”,[]) 该模块包括两个配置文件,第一个是init.pp: class rmpkg { $pkg_name = hiera_hash('rpm_name', undef) if $pkg_name != undef { c

我编写了一个模块,它使用
rpm-e$package\u name--nodeps
删除一个rpm,而不依赖它

我正在使用Hiera,我在Puppet服务器的
site.pp
文件中设置了
Hiera\u include(“classes”,[])

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

class rmpkg {
    $pkg_name = hiera_hash('rpm_name', undef)
        if $pkg_name != undef {
            create_resources("rmpack", $pkg_name)
        }
}
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}",
 }
移除\u rpm.pp

class rmpkg {
    $pkg_name = hiera_hash('rpm_name', undef)
        if $pkg_name != undef {
            create_resources("rmpack", $pkg_name)
        }
}
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 ]#

我做错了什么?

尝试使用
$pkg\u name=hiera\u散列('rpm\u name::rpm\u 1::rpm',unde)

rpm_名称本身将加载一个类似

{'rpm_1':{'rpm':'cups'}


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

谢谢。它现在正在继续缓存目录等。。。但并没有被删除。。。你在我的代码中看到了任何可能阻止它工作的东西吗?另外,在这个任务中使用Hiera的整个想法是允许使用泛型变量,如果我指定
“remove\u rpm::rpm1::rpm”
,那么只有这个包可以工作。。我希望能够编写多个要删除的包。我同意,在我看来,您的hiera文件的第二个版本看起来是正确的。在我这里的例子中,有3个(可能不是很明显)与我的工作方式和你的工作方式不同。1) hiera_hash的第三个参数是{}not undef 2)定义的类型的调用类似于create_resources(modulename::function,$hash)3)。在定义的类型中使用$title而不是$name。很抱歉你的建议。顺便说一句,你用的是什么版本的木偶?