Ask Your Question

How to collect just strings into array from different classes?

asked 2016-09-27 10:11:46 -0600

Envek gravatar image

Is there any method to collect just array of strings to use it somehow. Just like concat module but for just strings?

I want to do something like this:

# declare string in manifests/one.pp, manifests/two.pp 
# and then:
postgresql::server::config_entry { 'shared_preload_libraries':
  value => join(<| THESE_STRINGS |>, ',')


Is it possible?

Target puppet version: 3.8

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted

answered 2016-09-27 14:28:30 -0600

DarylW gravatar image

I haven't used it myself, but I have heard of the module datacat..

From it's readme

Puppet types for concatenating data via a template The datacat and datacat_fragment types allow you to build up a data structure which is rendered using a template. This is similar to some of the common concatenation patterns though the intent should be clearer as it pushes the boilerplate down into the type.

edit flag offensive delete link more


Thank you for help, but it for files too. But I'm started one more googling round from it and found some useful snippets.

Envek gravatar imageEnvek ( 2016-09-28 11:14:34 -0600 )edit

answered 2016-09-28 11:24:45 -0600

Envek gravatar image

updated 2016-09-28 11:34:50 -0600

Thanks to @DarylW suggestion, I found a module which is for files again, but from its sources I've stolen some helpful snippets and based on them solved my problem (but still unsure, can it be solved better).

So, somewhere in my module I define next two types: one for collecting parts and another to collect and concatenate them into single value.

define smp::db::composable_config_entry_part($target, $content = '') {}

define smp::db::composable_config_entry () {
  Smp::Db::Composable_config_entry_part <| target == $name |> ->
  postgresql::server::config_entry { $name:
    value => inline_template("<%= { |r| r.type == 'Smp::Db::Composable_config_entry_part' && r['target'] == @name }.map { |r| r['content'] }.join(', ') -%>"),

Then I can use smp::db::composable_config_entry_part multiple times in multiple manifests:

# manifests/db/pglogical.pp
smp::db::composable_config_entry_part { 'Add pglogical to shared_preload_libraries':
  target  => 'shared_preload_libraries',
  content => 'pglogical',
  require => Package["postgresql-${smp::db::params::postgres_version}-pglogical"],

# manifests/db/pg_pathman.pp
smp::db::composable_config_entry_part { 'Add pg_pathman to shared_preload_libraries':
  target  => 'shared_preload_libraries',
  content => 'pg_pathman',
  require => Exec["build pg_pathman from sources"],

Then in some main manifest I'm adding this config entry:

# manifests/db/setup.pp
smp::db::composable_config_entry { 'shared_preload_libraries':

And voilá!

$ sudo puppet agent --test
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for smp-dev-db
Info: Applying configuration version '1475078821'
Notice: /Stage[main]/Smp::Db::Setup/Smp::Db::Composable_config_entry[shared_preload_libraries]/Postgresql::Server::Config_entry[shared_preload_libraries]/Postgresql_conf[shared_preload_libraries]/value: value changed '' to 'pg_pathman, pglogical'
edit flag offensive delete link more

answered 2016-09-28 12:58:01 -0600

Marek Maksimczyk gravatar image

I'm not sure what you want to accomplish but for me looks like you want to use hiera ;). It's good practice to separate data and puppet code. Do you consider this solution?

edit flag offensive delete link more


I want to construct some comma-separated string based on what classes are in my catalog (which I include in `site.pp`) and then pass it to another resource as parameter, see my own answer to this question for details how I've handled it (I still not fully satisfied with this solution though).

Envek gravatar imageEnvek ( 2016-09-30 06:45:17 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2016-09-27 10:11:46 -0600

Seen: 157 times

Last updated: Sep 28 '16