3

puppet version 2.7.18 stored configs (not puppetdb)

I my case i have 3 couchbase nodes, which should be concated to an couchbase connection string which looks like that:

192.168.19.12;192.168.19.40;192.168.19.66

so on each couchbase server i do something like this:

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

and on the app server, which should connect to the couchbase server, i want generate a yaml config file looking like this:

  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

all except the host lines are no problem, but the host entry is really tricky

i concat the hosts by collecting them with:

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

so now i have the problem, that i have no ";" calling concat like this

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

will produce:

host:         ;192.168.19.12;192.168.19.40;192.168.19.66

calling concat like that

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

will produce:

host:         192.168.19.12;192.168.19.40;192.168.19.66;

so how to modify the collected content or how do i get the desired result?

host:         192.168.19.12;192.168.19.40;192.168.19.66
c33s
  • 1,515
  • 3
  • 21
  • 39
  • Just a though, but why not use an `inline_template()` with the ruby `join()` function like in http://serverfault.com/a/350418/984 – Zoredache Aug 30 '13 at 23:39
  • inline templates with resource collector? how should this work? – c33s Aug 31 '13 at 00:43
  • Why is `@@concat::fragment { "foo": target => '/tmp/foo', content => "$ipaddress", order => 1, }` not giving you the desired result? - As an aside, it is advisable to prefer functions from the `stdlib` module over `inline_template` for performance reasons. – Felix Frank Jul 02 '14 at 11:46

1 Answers1

0

I achieve this for Zookeeper using PuppetDB to retrieve the nodes, and a custom plugin to join them. The details of using PuppetDB are in the answer to my original question, and the custom plugin looks like this:

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

This should allow you to create a string in your manifest like this:

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

Which will use PuppetDB to find all nodes assigned the couchbase class, and return their IP addresses.

Note that this shoots for eventual consistency - it will take a run for all the nodes to report to PuppetDB that they have the couchbase class assigned, and only on the second run will they all connect. This works fine for my Zookeeper class, but I suppose may not quite suit for the Couchbase one.

shearn89
  • 3,403
  • 2
  • 15
  • 39
  • looks like a good solution, but in my case it is a legacy system which is using puppet 2.7 with stored configs. – c33s Feb 11 '15 at 14:04