如何使用木偶存储configuration和concat来生成一个分号分离的IP地址列表?

木偶版本2.7.18存储configuration(不是puppetdb)

我的情况我有3个couchbase节点,应该被连接到一个couchbase连接string,看起来像这样:

192.168.19.12;192.168.19.40;192.168.19.66 

所以在每个couchbase服务器上,我都这样做:

 @@concat::fragment { "foo": target => '/tmp/foo', content => "$ipaddress", order => 1, } 

在应该连接到couchbase服务器的应用程序服务器上,我想生成一个yamlconfiguration文件,如下所示:

  couchbase: class: MyCouchbaseStorage param: connection: MyCouchbaseConnection connection_param: username: myusername password: mypassword bucket: mybucket host: 192.168.19.12;192.168.19.40;192.168.19.66 persist: 1 

除了主机线路都没有问题,但主机条目真的很棘手

我通过收集他们与concat主机:

 Concat::Fragment <<| tag == 'mycbtag' |>> { target => '/tmp/database.yml' } 

所以现在我有这个问题,我没有“;” 像这样调用concat

 @@concat::fragment { "foo": target => '/tmp/foo', content => ";$ipaddress", order => 1, } 

会产生:

 host: ;192.168.19.12;192.168.19.40;192.168.19.66 

像这样调用concat

 @@concat::fragment { "foo": target => '/tmp/foo', content => "$ipaddress;", order => 1, } 

会产生:

 host: 192.168.19.12;192.168.19.40;192.168.19.66; 

所以如何修改收集的内容,或者如何获得期望的结果?

 host: 192.168.19.12;192.168.19.40;192.168.19.66 

我为Zookeeper使用PuppetDB来获取节点以及一个自定义插件来join它们。 使用PuppetDB的细节是在我原来的问题的答案,自定义插件看起来像这样:

 require 'puppet/face' module Puppet::Parser::Functions newfunction(:comma_join_nodes, :type => :rvalue) do |args| query = args[0] fact = args[1] q = Puppet::Face[:query, :current].facts(query) return q.each_value.collect { |facts| facts[fact] }.sort.join(',') end end 

这应该允许你在你的清单中创build一个string,如下所示:

 $nodes = comma_join_nodes('Class[couchbase]', ipaddress) 

这将使用PuppetDB来查找分配了couchbase类的所有节点,并返回它们的IP地址。

请注意, 最终会保持一致 – 所有节点都会向PuppetDB报告已分配了couchbase类,只有在第二次运行时才会连接。 这对我的Zookeeper类正常工作,但我想可能不适合Couchbase之一。