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
link|improve this question
feedback

1 Answer

up vote 1 down vote accepted

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

link|improve this answer
In this case, you don't need to go through all those machinations -- most Puppet providers/types will collapse nested arrays by themselves if nested arrays don't make sense in context. All you should need is something like: $additional_env = [$default_env, 'b=c']. – jgoldschrafe Feb 20 at 6:39
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.