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.  

 

> 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.


> 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'.  

 

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