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)?

link|improve this question

feedback

1 Answer

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.

link|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? – Beaming Mel-Bin 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
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.