Jan 16, 2012
tom

How to merge puppet array variables

Question

Given the following puppet manifest, how can I merge / concatenate the two arrays such that the command will execute with both a=b and b=c ?

Cron{
  environment => ["a=b"]
}class a{
  cron{'test':
    command     => "/usr/bin/true",
    user        => "francois",
    environment => ["b=c"],
  }
}include a

My crontab entry ends up like this:

# Puppet Name: test
b=c
* * * * * /usr/bin/true

Answer

As I recall you can’t do it directly. Something like this might work though:

$default_env = ["a=b"]Cron {
  environment => $default_env
}class a {
  $additional_env = split(inline_template("<%= (default_env).join(',') %>"),',')  cron {"test":
    command => "true",
    user => "me",
    environment => $additional_env
  }
}include a

(the split/inline_template is based off of something from http://www.crobak.org/2011/02/two-puppet-tricks-combining-arrays-and-local-tests/ )

Related posts:

  1. puppet variables
  2. Puppet: Checking sets of variables
  3. Accessing puppet configuration variables from manifests?
  4. How do you configure puppet to add a user to the sudoers group when it varies on different systems (or, how do variables work?)
  5. Differences between local ‘puppet apply’ and ‘puppet agent’ to a puppetmaster

Leave a comment