Evaluation Error while using the Hiera hash in puppet

时间:2016-04-25 09:03:39

标签: arrays puppet hiera

I have the following values in my hiera yaml file:

test::config_php::php_modules :
  -'soap'
  -'mcrypt'
  -'pdo'
  -'mbstring'
  -'php-process'
  -'pecl-memcache'
  -'devel'
  -'php-gd'
  -'pear'
  -'mysql'
  -'xml'

and following is my test class:

class test::config_php (
$php_version,
$php_modules = hiera_hash('php_modules', {}),
$module_name,
){

class { 'php':
version => $php_version,
}

$php_modules.each |String $php_module| {
php::module { $php_module: }
}
}

While running my puppet manifests I get the following error:

Error: Evaluation Error: Error while evaluating a Function Call, create_resources(): second argument must be a hash   at /tmp/vagrant-puppet/modules-f38a037289f9864906c44863800dbacf/ssh/manifests/init.pp:46:3 on node testdays-1a.vagrant.loc.vag
I am quite confused on what exactly am I doing wrong. My puppet version is 3.6.2 and I also have parser = future

I would really appreciate any help here.

2 个答案:

答案 0 :(得分:0)

Looks like your YAML was slightly off.

  1. You don't really need quotes in YAML.
  2. Your indentation was two instead of one.
  3. Your first colon on the first time was spaced. This will throw a syntax error.

it should look more like this:

test::config_php::php_modules:
 - soap
 - mcrypt
 - pdo
 - mbstring
 - php-process
 - pecl-memcache
 - devel
 - php-gd
 - pear
 - mysql
 - xml

In the future try and look up YAML parsers like this: link

答案 1 :(得分:0)

问题在于我的puppet版本,不知何故版本3.6在创建资源时表现得很奇怪,例如它在以下行中失败了:

create_resources('::ssh::client::config::user', $fin_users_client_options)

上面的代码片段是来自puppet labs的ssh模块的一部分,我认为它是经过彻底测试的,不应该是异常的原因。

进一步分析导致在配置文件中设置参数parser = future时抛出异常

我不能在不设置将来作为解析器的情况下使用每个迭代,因此我决定更改我的源代码如下:

我创建了一个新类:

define test::install_modules {
php::module { $name: }
}

然后我将配置config_php更改为:

class test::config_php (
$php_version,
$php_modules = [],
){

class { 'php':
version => $php_version,
}

install_modules { $php_modules: }
}

现在一切似乎好多了。