Tim Harper
2008-Nov-03 18:44 UTC
[Puppet Users] How to duplicate the ''parameter absent'' behavior of user
I have a define that acts as a convenience wrapper around the user
type and a few other things.
With the ''user'' type, if don''t pass the uid
parameter, it will default
to let the system auto-assign it. However, passing uid => null,
false, -1, etc all try and set a specific uid, which is obviously wrong.
Am I up a creek without a paddle :)? Anybody have any idea how to do
this?
Here''s what I have so far (it sucks, but it''s the best I could
do to
work around):
define normal_user ( $ensure = present, $comment = "Puppet created
user", $groups = [], $default_password = false, $key_type =
"ssh-rsa",
$key_name = "puppet-installed-key", $key = false, $uid = false, $gid =
false) {
# how do you pass in a variable as undefined???
if $uid {
user { $title:
ensure => $ensure,
comment => $comment,
home => "/home/$title",
managehome => true,
groups => $groups,
gid => $gid,
uid => $uid
}
} else {
user { $title:
ensure => $ensure,
comment => $comment,
home => "/home/$title",
managehome => true,
groups => $groups,
}
}
if $key {
ssh_authorized_key { $title: ensure => $ensure, type =>
$key_type, user => $title, name => $key_name, key => $key }
}
if $default_password {
default_password { $title: password => $default_password }
}
}
Thanks!
Tim
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Marcin Owsiany
2008-Nov-03 18:48 UTC
[Puppet Users] Re: How to duplicate the ''parameter absent'' behavior of user
On Mon, Nov 03, 2008 at 11:44:08AM -0700, Tim Harper wrote:> > I have a define that acts as a convenience wrapper around the user > type and a few other things. > > With the ''user'' type, if don''t pass the uid parameter, it will default > to let the system auto-assign it. However, passing uid => null,If memory serves me, it should be uid => nil -- Marcin Owsiany <marcin@owsiany.pl> http://marcin.owsiany.pl/ GnuPG: 1024D/60F41216 FE67 DA2D 0ACA FC5E 3F75 D6F6 3A0D 8AA0 60F4 1216 "Every program in development at MIT expands until it can read mail." -- Unknown --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Paul Lathrop
2008-Nov-04 01:47 UTC
[Puppet Users] Re: How to duplicate the ''parameter absent'' behavior of user
You want uid => undef --Paul On Mon, Nov 3, 2008 at 11:44 AM, Tim Harper <timcharper@gmail.com> wrote:> > I have a define that acts as a convenience wrapper around the user > type and a few other things. > > With the ''user'' type, if don''t pass the uid parameter, it will default > to let the system auto-assign it. However, passing uid => null, > false, -1, etc all try and set a specific uid, which is obviously wrong. > > Am I up a creek without a paddle :)? Anybody have any idea how to do > this? > > Here''s what I have so far (it sucks, but it''s the best I could do to > work around): > > define normal_user ( $ensure = present, $comment = "Puppet created > user", $groups = [], $default_password = false, $key_type = "ssh-rsa", > $key_name = "puppet-installed-key", $key = false, $uid = false, $gid > false) { > # how do you pass in a variable as undefined??? > if $uid { > user { $title: > ensure => $ensure, > comment => $comment, > home => "/home/$title", > managehome => true, > groups => $groups, > gid => $gid, > uid => $uid > } > } else { > user { $title: > ensure => $ensure, > comment => $comment, > home => "/home/$title", > managehome => true, > groups => $groups, > } > } > if $key { > ssh_authorized_key { $title: ensure => $ensure, type => > $key_type, user => $title, name => $key_name, key => $key } > } > if $default_password { > default_password { $title: password => $default_password } > } > } > > > > Thanks! > > Tim > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Aj
2008-Nov-04 03:46 UTC
[Puppet Users] Re: How to duplicate the ''parameter absent'' behavior of user
Can''t undef only be used with the inheritance syntax?
The closest we have to initializing to undefined is an empty string
('''') - you can compare this quite easily in .6 - check the
language
tut - but you need to do a case/selector for comparism pre-.6
E.g.;
case $uid {
'''': {
user { ''..'':
other_params => whatever
}
}
default: {
user { ''..'':
uid => $uid
}
}
}
On 4/11/2008, at 2:47 PM, "Paul Lathrop"
<paul@tertiusfamily.net> wrote:
>
> You want uid => undef
>
> --Paul
>
> On Mon, Nov 3, 2008 at 11:44 AM, Tim Harper <timcharper@gmail.com>
> wrote:
>>
>> I have a define that acts as a convenience wrapper around the user
>> type and a few other things.
>>
>> With the ''user'' type, if don''t pass the uid
parameter, it will
>> default
>> to let the system auto-assign it. However, passing uid => null,
>> false, -1, etc all try and set a specific uid, which is obviously
>> wrong.
>>
>> Am I up a creek without a paddle :)? Anybody have any idea how to do
>> this?
>>
>> Here''s what I have so far (it sucks, but it''s the
best I could do to
>> work around):
>>
>> define normal_user ( $ensure = present, $comment = "Puppet created
>> user", $groups = [], $default_password = false, $key_type =
"ssh-
>> rsa",
>> $key_name = "puppet-installed-key", $key = false, $uid =
false,
>> $gid >> false) {
>> # how do you pass in a variable as undefined???
>> if $uid {
>> user { $title:
>> ensure => $ensure,
>> comment => $comment,
>> home => "/home/$title",
>> managehome => true,
>> groups => $groups,
>> gid => $gid,
>> uid => $uid
>> }
>> } else {
>> user { $title:
>> ensure => $ensure,
>> comment => $comment,
>> home => "/home/$title",
>> managehome => true,
>> groups => $groups,
>> }
>> }
>> if $key {
>> ssh_authorized_key { $title: ensure => $ensure, type =>
>> $key_type, user => $title, name => $key_name, key => $key }
>> }
>> if $default_password {
>> default_password { $title: password => $default_password }
>> }
>> }
>>
>>
>>
>> Thanks!
>>
>> Tim
>>
>>>
>>
>
> >
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Tim Harper
2008-Nov-04 19:44 UTC
[Puppet Users] Re: How to duplicate the ''parameter absent'' behavior of user
>> You want uid => undef >> >> --Paul >Thanks Paul - this is the lead I needed to get to at least a work around. Given: === EXHIBIT A ==define user_test() { user { $title: ensure => present, uid => undef } } node "server" { user_test { ''boogy'': } } === EXHIBIT B ==define user_test(uid = undef) { user { $title: ensure => present, uid => $uid } } node "server" { user_test { ''boogy'': } } === EXHIBIT C ==define user_test(uid = undef) { user { $title: ensure => present, uid => $uid ? { undef => undef, default => $uid } } } node "server" { user_test { ''boogy'': } } === EXHIBIT D ==define user_test(uid = false) { user { $title: ensure => present, uid => $uid ? { false => undef, default => $uid } } } node "server" { user_test { ''boogy'': } } === END EXHIBITS == === OUTPUT FROM EXHIBIT B ==puppetd --test info: Caching catalog at /var/puppet/state/localconfig.yaml notice: Starting catalog run err: //Node[server]/User_test[boogy]/User[boogy]/uid: change from 511 to failed: Could not set uid on user[boogy]: Execution of ''/usr/sbin/ usermod -u boogy'' returned 4: usermod: uid 0 is not unique notice: Finished catalog run in 5.80 seconds === END OUTPUT == Results: EXHIBIT A: works (except I can''t specify uid, naturally) EXHIBIT B: fails (see OUTPUT FROM EXHIBIT B) EXHIBIT C: fails (similar to OUTPUT FROM EXHIBIT B) EXHIBIT D: works! So, apparently you can''t assign undef to a variable. I''m thinking this is a bug. Thoughts, anyone? Thanks, Tim --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Aj
2008-Nov-04 20:54 UTC
[Puppet Users] Re: How to duplicate the ''parameter absent'' behavior of user
As my reply soriginally tated, undef is part of the override syntax and as such is only valid in an inherited, overridden resource. I.e.; not a bug. Perhaps a feature request, although I personally believe that empty string assignment is sufficient. On 5/11/2008 at 8:44 AM, Tim Harper <timcharper@gmail.com> wrote:> >>> You want uid => undef >>> >>> --Paul >> > > > Thanks Paul - this is the lead I needed to get to at least a work > around. > > Given: > > === EXHIBIT A ==> define user_test() { > user { $title: > ensure => present, > uid => undef > } > } > > node "server" { > user_test { ''boogy'': } > } > > === EXHIBIT B ==> define user_test(uid = undef) { > user { $title: > ensure => present, > uid => $uid > } > } > > node "server" { > user_test { ''boogy'': } > } > > === EXHIBIT C ==> define user_test(uid = undef) { > user { $title: > ensure => present, > uid => $uid ? { undef => undef, default => $uid } > } > } > > node "server" { > user_test { ''boogy'': } > } > > === EXHIBIT D ==> define user_test(uid = false) { > user { $title: > ensure => present, > uid => $uid ? { false => undef, default => $uid } > } > } > > node "server" { > user_test { ''boogy'': } > } > === END EXHIBITS ==> > > > > === OUTPUT FROM EXHIBIT B ==> puppetd --test > info: Caching catalog at /var/puppet/state/localconfig.yaml > notice: Starting catalog run > err: //Node[server]/User_test[boogy]/User[boogy]/uid: change from 511 > to failed: Could not set uid on user[boogy]: Execution of ''/usr/sbin/ > usermod -u boogy'' returned 4: usermod: uid 0 is not unique > > notice: Finished catalog run in 5.80 seconds > === END OUTPUT ==> > > > Results: > > EXHIBIT A: works (except I can''t specify uid, naturally) > EXHIBIT B: fails (see OUTPUT FROM EXHIBIT B) > EXHIBIT C: fails (similar to OUTPUT FROM EXHIBIT B) > EXHIBIT D: works! > > So, apparently you can''t assign undef to a variable. I''m thinking this > is a bug. Thoughts, anyone? > > Thanks, > > Tim > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Tim Harper
2008-Nov-04 21:10 UTC
[Puppet Users] Re: How to duplicate the ''parameter absent'' behavior of user
On Nov 4, 2008, at 1:54 PM, Aj wrote:> > As my reply soriginally tated, undef is part of the override syntax > and as such is only valid in an inherited, overridden resource. I.e.; > not a bug. > > Perhaps a feature request, although I personally believe that empty > string assignment is sufficient.Thanks for the reply, Aj :) I can agree that it''s not a bug, though being unable replicate the parameter behavior of core Type''s without resulting to ruby is a bit of a gotcha. I''ll continue with the workaround achieved by EXHIBIT D> > On 5/11/2008 at 8:44 AM, Tim Harper <timcharper@gmail.com> wrote: >> === EXHIBIT D ==>> define user_test(uid = false) { >> user { $title: >> ensure => present, >> uid => $uid ? { false => undef, default => $uid } >> } >> } >> >> node "server" { >> user_test { ''boogy'': } >> } >>:) Tim --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Luke Kanies
2008-Nov-12 22:58 UTC
[Puppet Users] Re: How to duplicate the ''parameter absent'' behavior of user
On Nov 4, 2008, at 12:54 PM, Aj wrote:> As my reply soriginally tated, undef is part of the override syntax > and as such is only valid in an inherited, overridden resource. I.e.; > not a bug. > > Perhaps a feature request, although I personally believe that empty > string assignment is sufficient.Undef is a valid rvalue just about anywhere; works fine outside of overrides. -- An expert is a person who has made all the mistakes that can be made in a very narrow field. - Niels Bohr --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---