Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inline if statement for puppet parameters

Tags:

puppet

I have a following puppet module

class base (
  $someBoolean=false,
)
{
  exec { 'Do something':
    command     => '/usr/bin/someStuff',
    timeout     => (someBoolean) ? 100000000 : 300
  }
}

The timeout => () ? : is enssentially what I want to do, but what is the correct syntax to do it? Is it possible at all?

like image 204
Zhen Liu Avatar asked Dec 25 '22 03:12

Zhen Liu


1 Answers

Puppet's version of the ternary operator is the more general "selector". The syntax for your case looks like this:

exec { 'Do something':
  command => '/usr/bin/someStuff',
  timeout => $someBoolean ? { true => 100000000, default => 300 }
}

The control expression ($someBoolean in the above) can in fact be any expression that produces a value, and any number of corresponding cases can be provided.

like image 65
John Bollinger Avatar answered Feb 24 '23 04:02

John Bollinger