Ask Your Question
0

Ruby code in Puppet if statements

asked 2014-12-01 08:00:58 -0500

kemra102 gravatar image

I am trying to implement a check in a module that checks for two variables being set and if they are then to fail. SO far I've come up with this:

if !$users.empty? and !$group.empty? {
  fail 'You cannot define both a list of users and a group. Choose one.'
}

However this fails with the following error:

Error: Could not parse for environment production: Syntax error at '.'; expected ')'

Is there a way to make this work?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2014-12-03 07:06:34 -0500

kemra102 gravatar image

Seems that lorcutt's answer was the clue.

After ensuring both variables were undef by default then changing the check to:

if $users != undef and $group != undef {
    fail 'You cannot define both a list of users and a group. Choose one.'   
}

fixed the issue.

edit flag offensive delete link more
0

answered 2014-12-01 17:08:41 -0500

lorcutt gravatar image

I assume that $users and $group are array variables and you want to check if they are populated? See http://grokbase.com/p/gg/puppet-users/147d6h4cys/checking-a-variable-is-not-undef for information on the definition of whether a variable is defined

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-12-01 08:00:58 -0500

Seen: 140 times

Last updated: Dec 03 '14