Puppet 来自外部文件的傀儡迭代

Puppet 来自外部文件的傀儡迭代,puppet,erb,Puppet,Erb,我是配置管理新手,仅供参考 我正在尝试对elasticsearch进行傀儡化,并希望在一个文件中有一个elasticsearch节点的主列表(它可以用于多种用途,而不仅仅是用于此目的) 我想通过ERB模板添加elasticsearch.yml,并将FDQN列表扩展到discovery.zen.ping.unicast.hosts:[]参数中 例如,我在模块/文件中有一个名为es_hosts的外部文件,其中包含: host1.domain.com host2.domain.com host3.

我是配置管理新手,仅供参考

我正在尝试对elasticsearch进行傀儡化,并希望在一个文件中有一个elasticsearch节点的主列表(它可以用于多种用途,而不仅仅是用于此目的)

我想通过ERB模板添加elasticsearch.yml,并将FDQN列表扩展到discovery.zen.ping.unicast.hosts:[]参数中

例如,我在模块/文件中有一个名为es_hosts的外部文件,其中包含:

host1.domain.com 
host2.domain.com 
host3.domain.com 
host4.domain.com
然后,当puppet构建ERB模板时,在参数中包含以下内容:

discovery.zen.ping.unicast.hosts: ["host1.domain.com", "host2.domain.com", "host3.domain.com", "host4.domain.com"]
我试过几件事,但都没办法

我会将此列表用于其他事情,如构建防火墙规则等,因此我希望有一个主列表供参考,可以由我的团队更新


谢谢你的帮助

与其将列表放在文件中,不如将其放在Hiera中,因为定义列表和其他外部数据是Hiera的具体用途

(如果你还没有使用Hiera,你肯定应该仔细阅读。)

所以在希拉,你会:

---
es_hosts:
- host1.domain.com 
- host2.domain.com 
- host3.domain.com 
- host4.domain.com
discovery.zen.ping.unicast.hosts: ["<%= @es_hosts.join('", "') %>"]
在您的清单中,您可以使用Hiera函数从Hiera中读取:

$es_hosts = hiera('es_hosts')
(请注意,我们通常使用Puppet的自动参数查找功能代替hiera函数,将数据从hiera读取到我们的清单中,但您的要求(在多个上下文中使用的ES主机列表)表明您不希望此列表绑定到特定的类输入。如果您认为这没有意义,对吗现在,您将需要了解参数化类和自动参数查找,但这与此答案无关。)

最后,在ERB模板中,您将拥有:

---
es_hosts:
- host1.domain.com 
- host2.domain.com 
- host3.domain.com 
- host4.domain.com
discovery.zen.ping.unicast.hosts: ["<%= @es_hosts.join('", "') %>"]
discovery.zen.ping.unicast.hosts:[“”]
请注意,清单中的
$es_hosts
变量是通过ERB模板中的Ruby实例变量
@es_hosts
访问的


最后,请注意,Puppet Forget上有一个Elasticsearch Puppet模块。您可能会发现,使用该模块比编写自己的模块要好。

与其在文件中包含列表,不如在Hiera中包含它,因为定义列表和其他外部数据是Hiera的具体用途

(如果你还没有使用Hiera,你肯定应该仔细阅读。)

所以在希拉,你会:

---
es_hosts:
- host1.domain.com 
- host2.domain.com 
- host3.domain.com 
- host4.domain.com
discovery.zen.ping.unicast.hosts: ["<%= @es_hosts.join('", "') %>"]
在您的清单中,您可以使用Hiera函数从Hiera中读取:

$es_hosts = hiera('es_hosts')
(请注意,我们通常使用Puppet的自动参数查找功能代替hiera函数,将数据从hiera读取到我们的清单中,但您的要求(在多个上下文中使用的ES主机列表)表明您不希望此列表绑定到特定的类输入。如果您认为这没有意义,对吗现在,您将需要了解参数化类和自动参数查找,但这与此答案无关。)

最后,在ERB模板中,您将拥有:

---
es_hosts:
- host1.domain.com 
- host2.domain.com 
- host3.domain.com 
- host4.domain.com
discovery.zen.ping.unicast.hosts: ["<%= @es_hosts.join('", "') %>"]
discovery.zen.ping.unicast.hosts:[“”]
请注意,清单中的
$es_hosts
变量是通过ERB模板中的Ruby实例变量
@es_hosts
访问的

最后,请注意,Puppet Forget上有一个Elasticsearch Puppet模块。您可能会发现使用该模块比编写自己的模块要好