Hi everyone, Is there a way to handle default setting easily, let me explain, I want to create a user but if the uid is specified I would to use it as follow: --- class user::create ($uid='''' ) { user { "$name": ensure => present, uid => "$uid", } --- Or am I forced to used the following code: --- class user::create ($uid='''' ) { user { "$name": ensure => present, } if $uid { User["$name"] { uid => "$uid", } --- In the first case, does the uid set to ''''? Regards, JM -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On Jan 17, 4:34 am, Antidot SAS <antidot...@gmail.com> wrote:> Hi everyone, > > Is there a way to handle default setting easily, let me explain, I want to > create a user but if the uid is specified I would to use it as follow: > > --- > class user::create ($uid='''' ) { > user { "$name": > ensure => present, > uid => "$uid",} > > --- > > Or am I forced to used the following code: > > --- > class user::create ($uid='''' ) { > user { "$name": > ensure => present, > > } > > if $uid { User["$name"] { uid => "$uid", } > > --- > > In the first case, does the uid set to ''''? > > Regards, > JM-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On Jan 17, 4:34 am, Antidot SAS <antidot...@gmail.com> wrote:> Hi everyone, > > Is there a way to handle default setting easily, let me explain, I want to > create a user but if the uid is specified I would to use it as follow: > > --- > class user::create ($uid='''' ) { > user { "$name": > ensure => present, > uid => "$uid",} > > --- > > Or am I forced to used the following code: > > --- > class user::create ($uid='''' ) { > user { "$name": > ensure => present, > > } > > if $uid { User["$name"] { uid => "$uid", } > > ---Unless you want to limit your self to a maximum of one managed User per node, you''ll want a definition rather than a class. You also need to understand that the empty string is a string value like any other, and assigning it as a resource property is very different from assigning no value. The latter is expressed via the keyword "undef", which must be written without the quotes to have that meaning. Also, I''m not sure whether this is true in the latest Puppet versions, but it used to be that you could not set undef as a parameter''s default value. For cases such as yours, then, one would typically use code similar to this: define user::create ($uid = '''') { user { "$name": ensure => present, uid => $uid ? { '''' => undef, default => $uid } } } John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
OK thanks, this helped a lot, and finally with puppet 2.7.9 the ''undef'' as a default value worked. On Tue, Jan 17, 2012 at 3:59 PM, jcbollinger <John.Bollinger@stjude.org>wrote:> > > On Jan 17, 4:34 am, Antidot SAS <antidot...@gmail.com> wrote: > > Hi everyone, > > > > Is there a way to handle default setting easily, let me explain, I want > to > > create a user but if the uid is specified I would to use it as follow: > > > > --- > > class user::create ($uid='''' ) { > > user { "$name": > > ensure => present, > > uid => "$uid",} > > > > --- > > > > Or am I forced to used the following code: > > > > --- > > class user::create ($uid='''' ) { > > user { "$name": > > ensure => present, > > > > } > > > > if $uid { User["$name"] { uid => "$uid", } > > > > --- > > > Unless you want to limit your self to a maximum of one managed User > per node, you''ll want a definition rather than a class. You also need > to understand that the empty string is a string value like any other, > and assigning it as a resource property is very different from > assigning no value. The latter is expressed via the keyword "undef", > which must be written without the quotes to have that meaning. > > Also, I''m not sure whether this is true in the latest Puppet versions, > but it used to be that you could not set undef as a parameter''s > default value. For cases such as yours, then, one would typically use > code similar to this: > > define user::create ($uid = '''') { > user { "$name": > ensure => present, > uid => $uid ? { '''' => undef, default => $uid } > } > } > > > John > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.