On Monday, January 28, 2013 11:07:51 AM UTC-6, Matthew Pounsett wrote:
>
>
>
> On Monday, 28 January 2013 11:14:59 UTC-5, jcbollinger wrote:
>  
>
>> define site::user (
>>>         $comment,
>>>         $ensure,
>>>         $home,
>>>         $name = $title,
>>>
>>
>>
>> Don't do that ($name = $title).  Puppet provides it automatically (both 
>> the parameter and the default).
>>
>
> In this case, $name is the login name of the user being created .. it's a 
> valid parameter of the 'user' resource type.  I'm not sure how I'm supposed 
> to do not use it.  I have read the Puppet reference manual.. but not for 
> puppet 3, since I'm not using that.  
>


You are missing the point: Puppet automatically endows every defined type 
with a $name parameter, and automatically defaults its value to the 
$title.  See 
http://docs.puppetlabs.com/puppet/3/reference/lang_defined_types.html#title-and-name.
  
Though Puppet might not complain, it is at best poor form to declare the 
same thing explicitly.

 

>
>  
>
>> Moreover, I am uncertain whether it is safe anyway to use $title as a 
>> resource default.  It certainly *isn't* safe to use explicit resource 
>> properties, regardless of the order in which they are listed.
>
>
> I'n not sure what you mean by that.  Using $title as a default is widely 
> used (see namevar) .. I'm not sure what you mean about explicit resource 
> properties.
>


I answer my own question: the automatic $title and $name parameters are 
documented safe to use as parameter defaults (but I'm not sure whether 
$name remains safe if you (re)declare it explicitly).  No (other) 
parameters you explicitly define are safe for use as default values of 
other parameters.  That is, you must not do this:

site::user ( $uid, $gid = $uid ) {
# ...
}

 

>
>
>> The usual paradigm is this:
>> define mymodule::foo ( $param1 = 'NOTSET' ) {
>>   $real_param1 = $param1 ? {
>>     'NOTSET' => <some-appropriate-value-maybe-undef>,
>>     default => $param1
>>   }
>>   sometype { $name:
>>     param => $real_param1
>>   }
>> }
>> Yes, it's a bit clunky, but it works.
>
>  
>
> This is great if I want to set my own defaults, but I don't.  The 'user' 
> resource already has its own way of handling unspecified parameters, and I 
> don't want to override those unless absolutely necessary.   I think the 
> above would require me to re-implement a bunch of its defaults logic, which 
> would be especially problematic for things like 'gid'.  
>


Note the "maybe-undef" in <some-appropriate-value-maybe-undef>.  I'm 
referring there to the literal keyword 'undef', which should serve your 
needs.  In this case you can also use 'undef' directly as the default, as 
Keith suggested, but that does not allow you to distinguish between the 
case where the user doesn't set a parameter and the one where he explicitly 
sets it to undef.  You may not need that distinction now, but if you 
continue writing Puppet manifests then one day you will.

 

>
>  
>
>> No, Puppet doesn't have anything like that.  The closest would probably 
>> be the create_resources() function, which you can read about in the docs.
>
>
> I'll have a look.. maybe there's some way I can make use of it.
>  
>
>> I'm surprised you didn't find an example like the one above.  It appears 
>> all over the place, not least in the archives of this group.
>>
> Also, have you read the official Puppet DSL docs (at 
>> http://docs.puppetlabs.com/puppet/3/reference/)?  They don't answer your 
>> particular question, but they would have told you about $name, and they 
>> have a lot of other useful information.
>
>
> The only occurrence of the string "name" in the DSL doc at that location 
> is as a placeholder... and it applies to ruby, not puppet manifests.  I 
> don't see anything there about use of $name inside a puppet class.
>
>

You're not talking about a class, you're talking about a definition.  The 
distinction is important.  Anyway, I gave a direct link above to the docs 
for $name and $title in defined types.


John

-- 
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+unsubscr...@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.


Reply via email to