Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
share|improve this question

1 Answer 1

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

share|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 '12 at 6:39
    
@jgoldschrafe Doesn't seem to be working on puppet 3.1 using cron itself. –  François Beausoleil Apr 17 '13 at 15:47
    
If this is causing issues, the Puppet Labs stdlib does contain a flatten() function that's probably the simplest way to approach this. –  jgoldschrafe Apr 21 '13 at 18:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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