Puppet – How to Merge Puppet Array Variables

puppet

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

Best 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/ )