Syntax problem, if/case in class section for $hostname

460 views
Skip to first unread message

Denny Schierz

unread,
Feb 15, 2016, 2:37:20 AM2/15/16
to Puppet Users
hi,

I try to get an if/case thing working, but I always get a syntax error.

We have something  like that for an user:

modules/users/manifests/fbar.pp


class users::fbar (
      $ensure      = present,
      $groups      = [ 'develop' ]
) {
   case $ensure {

      present: {
         users::add_user { foobar:
            comment                    => 'Foo bar',
            uid                     => 1024,
            groups                  => $groups,
            shell                   => '/bin/bash',
            require                 => Group[$groups],
         }
      }
      absent: {
         users::del_user { ['fbar' ]:
            managehome              => true,
         }

      }
   }
}


which is included on a node ...

environments/dev/manifests/developpc.pp

[...]

   # distribute users
   class { 'users::fbar':
     ensure                       => present,
   }


The only thing I want, is to change the group on a special node with $hostname =~ /regex$/

I tried a lot to change from      
$groups      = [ 'develop' ]
to

$groups      = [ 'admins' ]

with if/else and with case but ended up with syntax error on '}' ... expected ... (if i remember right).

So, what I have done wrong ?

cu denny

Henrik Lindberg

unread,
Feb 15, 2016, 8:25:23 AM2/15/16
to puppet...@googlegroups.com
Impossible to guess when not seeing the entire failing example.
- henrik


--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

Denny Schierz

unread,
Feb 15, 2016, 8:33:47 AM2/15/16
to Puppet Users
hi,

in the last 5 min I was able to solve my problem. The problem was that I wanted to override a parameterized class .. my solution is is now:

class users::fbar::params {

if ($::hostname =~ /^devpc21+(\d+)./) {
      $groups      = [ 'admin' ] }
else {

      $groups      = [ 'devel' ] }

}

class users::fbar (
      $ensure      = present,
      $groups      = $users::fbar::params::groups
)
      inherits  users::fbar::params

 {
   case $ensure {

      present: {
         users::add_user { fbar:
            comment                    => 'Foo Bar',

            uid                     => 1024,
            groups                  => $groups,
            shell                   => '/bin/bash',
            yubikeyid               => 'cccccxxxxxx',

            require                 => Group[ $groups ],
         }
      }
      absent: {
         users::del_user { ['fbar' ]:
            managehome  => true,
         }

      }
   }
}

It seems to be impossible to use if/case/whatever as selector for a parameter.

cu denny

R.I.Pienaar

unread,
Feb 15, 2016, 8:38:27 AM2/15/16
to puppet-users

jcbollinger

unread,
Feb 15, 2016, 9:47:53 AM2/15/16
to Puppet Users


On Monday, February 15, 2016 at 7:33:47 AM UTC-6, Denny Schierz wrote:
 
It seems to be impossible to use if/case/whatever as selector for a parameter.


The 'if' and 'case' statements are statements, not expressions.  They do not produce a value.  As R.I. observed, if you need a conditional expression then there are selectors.


John

Reply all
Reply to author
Forward
0 new messages