pipe理启用 – 禁用Hiera puppet禁用nginx网站?

我得到了执行hiera puppet脚本来pipe理nginx的sites_enabled的任务。

这是我的木偶剧本:

common.yaml

--- classes: - nginx nginx: enabled: abc.com xyz.com disabled: test.com test2.com 

init.pp

 class nginx{ create_resources("site_enabled", hiera("nginx"), {}) } define site_enabled($name){ file { '/etc/nginx/sites_enabled/${name}': ensure => 'link', target => '/etc/nginx/site_available/${name}', } } 

但是,当傀儡执行时我得到了错误:

err:无法从远程服务器检索目录:SERVER上的错误400:无法将string转换为Integer,位于节点XX上的/etc/puppet/modules/nginx/manifests/init.pp:7

当我试图通过命令行查询hiera时:

$ hiera nginx

{“enabled”=> [“abc.com”,“xyz.com”]}

我知道我错了一些地方。 请善待我。 我不太了解,hiera如何查询和处理数组数据。 如果可能的话,请给我一些有用的文件。

非常感谢。

你的问题非常类似于为create_resources创buildHiera散列的问题 ,它有一个答案。 我会在这里提供一个回顾。

根据create_resources的文档 ,散列必须采用{title => {parameters} } 。 您应该编辑您的hiera数据来设置参数。 既然没有,我想它可能是这样的:

common.yaml

 --- classes: - nginx nginx::enabled: abc.com: {} xyz.com: {} nginx::disabled: test.com: {} test2.com: {} 

接下来,您需要实际加载来自hiera的正确数据。 你想加载nginx::enabled ,而不是所有的nginx

init.pp

 class nginx{ create_resources("site_enabled", hiera("nginx::enabled")) } define site_enabled($name){ file { '/etc/nginx/sites_enabled/${name}': ensure => 'link', target => '/etc/nginx/site_available/${name}', } } 

谢谢你的快速回复。

我可以问这个问题吗? 我想用这种格式来制作我的yaml数据:

nginx的:

 enabled: abc.com xyz.com disabled: test.com test2.com 

我不想要这样的格式:

nginx的启用:::

 abc.com: {} xyz.com: {} 

nginx的禁用:::

 test.com: {} test2.com: {} 

我如何使我的木偶脚本按预期工作。 我也读过Hiera文档,据我所知,它也支持三种查找数据:hiera,hiera_hash和hiera_array。 但我不能让我的预期遵循我上面的yaml文件格式

对不起,我是非常新的hiera。

先谢谢了。