Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

1 Answer 1

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

Your Answer

 
discard

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.