Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a define that looks like this:

define user::sys_user($fullname, $uid, $groups, $shell='/bin/bash', $authkey, $authkey_type=rsa) {
        $username = "sys_${name}"
        group { $username:
                gid =>  $uid,

        user { $username:
                require => Group[$username],
                ensure => present,
                uid => $uid,
                gid => $uid,
                groups => $groups,
                comment => $fullname,
                shell => $shell,
                managehome => true,
                allowdupe => false,

        ssh_authorized_key { "${username}_authkey":
                user => $username,
                ensure => present,
                key => $authkey,
                type => $authkey_type,

In the user resource, I am requiring the user's default group. I also want to require supplemental groups if provided by the parameter $groups.

Also, is the way I do groups => $groups going to fail if it's empty or if it's just a string (i.e., defines just one group instead of an array)?

share|improve this question
up vote 0 down vote accepted

Yes, groups => $groups is likely to fail. It may not fail here in particular, but this particular pattern is not safe.

Put an if statement testing whether it is set or not, and define user with and without it on the if and else bodies.

share|improve this answer
so just if $groups be enough to check if it's nil? Also can I make the $groups parameter optional by doing define user::sys_user(..., $groups = nil,... in the definition? – Belmin Fernandez Dec 9 '11 at 16:15
As far as I know, no, that is not enough. – Daniel C. Sobral Dec 9 '11 at 23:01
What about if the default value for groups is an empty array? define user::sys_user(..., $groups = [],... – mc0e Jul 21 '15 at 5:48

Your Answer


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.