我有一个像这样的定义:
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, } }
在user资源中,我要求用户的默认组。 如果参数$ groups提供,我也想要求补充组。
另外,我是这样做groups => $groups将失败,如果它是空的,或者它只是一个string(即,只定义一个组而不是一个数组)?
是的, groups => $groups可能会失败。 它在这里可能不会失败,但是这种特殊的模式并不安全。
放一个if语句来testing它是否被设置,并且在if和else体上定义user有没有它。