I am trying to handle in my user class assigning user to groups, and handling that some groups might not be defined for that node. Example here is handling a non-datase node, "juser" fails with "Error: Failed to apply catalog: Parameter groups failed on User[juser]: Group names must not be empty. If you want to specify "no groups" pass an empty array" even in the notice and logs the correct value ("wheel") is logged? I was inital just planning on passing undef variables, but the dont seems to undefined (see the second example (hsmith) Any suggestions on either fixing the empty groups issue ora better handling groups that are not part of this node would be greatly appreciated. Thanks my user class .... $default_groups = [ ''wheel'' ] # db_user will be "undef" and it need to be a empty string if defined(Class[''mysql'']) { $db_group = $mysql::params::group } else { $db_group = '''' } $all_groups = [ $default_groups, $db_group ] notice "All: <${all_groups}>" # This logs correctly "Scope(Class[User::Users]) (notice): All: <wheel>" #fails, but the "notice" function does correctly log the correct groups value @user::virtual{ ''juser'': groups => $all_groups } #fails, even though mysql::params is never include, it is defined... maybe autoloaded? @user::virtual{ ''hsmith'': groups => [ ''wheel'', $mysql::params::group ] } Here is the virtual class define user::virtual ( $groups = [] ) { $user = hiera($title,nil,"${environment}/user") notice "Virt: <${groups}>" #log correcly Scope(User::Virtual[juser]) (notice): Virt: <wheel> user { $title: ensure => ''present'', uid => $user[''uid''], gid => $title, groups => $groups, # also tried [ $groups ], same result shell => ''/bin/bash'', home => "/home/${title}", comment => $user[''comment''], password => $user[''hash''], managehome => true, require => Group[$title], } ... -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
jcbollinger
2013-Mar-20 13:51 UTC
[Puppet Users] Re: User Groups (hadnling undefine groups)
On Tuesday, March 19, 2013 1:01:04 PM UTC-5, Kubes wrote:> > I am trying to handle in my user class assigning user to groups, and > handling that some groups might not be defined for that node. Example here > is handling a non-datase node, > > > "juser" fails with "Error: Failed to apply catalog: Parameter groups > failed on User[juser]: Group names must not be empty. If you want to > specify "no groups" pass an empty array" even in the notice and logs the > correct value ("wheel") is logged? > > > I was inital just planning on passing undef variables, but the dont seems > to undefined (see the second example (hsmith) > > > Any suggestions on either fixing the empty groups issue ora better > handling groups that are not part of this node would be greatly appreciated. > > > > Thanks > > > my user class > .... > > $default_groups = [ ''wheel'' ] > # db_user will be "undef" and it need to be a empty string > if defined(Class[''mysql'']) { > $db_group = $mysql::params::group > } else { > $db_group = '''' > } > > $all_groups = [ $default_groups, $db_group ] >That line is a problem when $db_group has value '''', because '''' is not a valid group name. It may also be a problem that $default_groups is an array. The value of $all_groups ends up being [ [''wheel''], ''''], whereas you want it to be [''wheel'']. You could possibly solve the problem by setting $db_group to an array, either [$mysql::params::group] or [], and then flattening [ $default_groups, $db_group ] to get the value for $all_groups. PuppetLabs'' ''stdlib'' add-in module has a suitable flatten() function. While I''m at it, however, the use of defined() in the code fragment presents an additional, separate problem by making the code parse-order and/or evaluation-order sensitive. There are pretty much *no* good uses for defined(), and that is likely to bite you eventually. John> > notice "All: <${all_groups}>" # This logs correctly > "Scope(Class[User::Users]) (notice): All: <wheel>" > > #fails, but the "notice" function does correctly log the correct groups > value > @user::virtual{ ''juser'': groups => $all_groups } > > #fails, even though mysql::params is never include, it is defined... > maybe autoloaded? > @user::virtual{ ''hsmith'': groups => [ ''wheel'', $mysql::params::group ] } > > > > Here is the virtual class > > define user::virtual ( $groups = [] ) { > > $user = hiera($title,nil,"${environment}/user") > > notice "Virt: <${groups}>" #log correcly > Scope(User::Virtual[juser]) (notice): Virt: <wheel> > > user { $title: > ensure => ''present'', > uid => $user[''uid''], > gid => $title, > groups => $groups, # also tried [ $groups ], same result > shell => ''/bin/bash'', > home => "/home/${title}", > comment => $user[''comment''], > password => $user[''hash''], > managehome => true, > require => Group[$title], > } > ... > > > > > > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.