Groups
Groups
Sign in
Groups
Groups
Puppet Users
Conversations
About
Send feedback
Help
Ternary operator in puppet ?
2,196 views
Skip to first unread message
Albert Shih
unread,
Jan 16, 2019, 5:09:36 AM
1/16/19
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to puppet...@googlegroups.com
Hi,
Is they are something like the ruby ternary operator ?: in puppet ?
I would like to do something like
$value = $hash.has_key('key') ? $hash('key') : $default_value
instead of
if $hash.has_key('key') {
$value = $hash('key')
}
else
{
$value = $default_value
}
to not get a lot of if.
Regards
--
Albert SHIH
DIO bātiment 15
Heure local/Local time:
Wed Jan 16 12:06:15 CET 2019
Karsten Heymann
unread,
Jan 16, 2019, 5:19:08 AM
1/16/19
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to puppet...@googlegroups.com
Hi Albert,
Am Mi., 16. Jan. 2019 um 11:09 Uhr schrieb Albert Shih <
Alber...@obspm.fr
>:
> Is they are something like the ruby ternary operator ?: in puppet ?
Sort of, it's called selectors:
https://puppet.com/docs/puppet/5.3/lang_conditional.html#selectors
Unfortunately one of the most useful cases (inside class declarations)
of selectors is disregarded according to puppet-lint:
http://puppet-lint.com/checks/selector_inside_resource/
Best regards
Karsten
Henrik Lindberg
unread,
Jan 16, 2019, 5:47:52 AM
1/16/19
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to puppet...@googlegroups.com
On 2019-01-16 11:18, Karsten Heymann wrote:
> Hi Albert,
>
> Am Mi., 16. Jan. 2019 um 11:09 Uhr schrieb Albert Shih <
Alber...@obspm.fr
>:
>> Is they are something like the ruby ternary operator ?: in puppet ?
>
> Sort of, it's called selectors:
>
https://puppet.com/docs/puppet/5.3/lang_conditional.html#selectors
>
You can also use an if-expression - for example:
$x = if $somevar == 'foo' { 'it is foo' } else { 'it is not foo' }
- henrik
--
Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/
Reply all
Reply to author
Forward
0 new messages