On Wednesday, September 25, 2013 7:12:29 AM UTC-5, John Simpson wrote:
>
> Greetings. 
>
> When defining a "file" resource, why does the ${name} variable sometimes 
> expand to the filename being maintained, and sometimes to the module name?



It doesn't.  The ${name} variable always resolves to the name of the class 
or definition instance in which it appears, including when (as is often the 
case) it is used therein inside a resource declaration, such as of a File.  
Examples:

# Class definition:
class demo_class {
  # resource declaration:
  notify { 'demonstration resource1':
    message => "The name of my class is ${name}"
  }
}
 
# Type definition
define demo_resource() {
  # resource declaration:
  notify { 'demonstration resource2':
    message => "The name of my instance is ${name}"
  }
}

# Class declaration
class { 'demo_class': }
# Will emit a notify message "The name of my class is demo_class"

# Class declaration
include  'demo_class'
# Equivalent to the previous, so it will emit a notify message
# "The name of my class is demo_class" (but only one such if both
# declarations appear).

# Resource declaration
demo_resource { 'instance1': }
# Will emit a notify message "The name of my instance is instance1"


Do not be confused by the curly braces of a resource declaration: they do 
not establish a new scope, so variable references appearing inside them 
mean the same thing that they do immediately outside.


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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to