1

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

1 Answer 1

0

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.

3
  • 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? Dec 9, 2011 at 16:15
  • As far as I know, no, that is not enough. Dec 9, 2011 at 23:01
  • What about if the default value for groups is an empty array? define user::sys_user(..., $groups = [],...
    – mc0e
    Jul 21, 2015 at 5:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .