Consider the following test.pp:
****************************************
biguml@biguml-laptop:~$ cat test.pp
$duck = "quack!"
class dog {
$sound = "woof"
$duck = "woof"
notify { "local dog sound": message => $sound }
notify { "local duck sound": message => $duck }
notify { "top scope duck sound": message => $::duck }
}
class cat {
$sound = "meow"
notify { "local cat sound": message => $sound }
notify { "dog sound from cat class": message => $dog::sound }
}
include dog
include cat
****************************************
And it''s results:
biguml@biguml-laptop:~$ puppet apply test.pp | grep defined
notice: /Stage[main]/Cat/Notify[local cat sound]/message: defined
''message'' as ''meow''
notice: /Stage[main]/Dog/Notify[local dog sound]/message: defined
''message'' as ''woof''
notice: /Stage[main]/Dog/Notify[top scope variable]/message: defined
''message'' as ''quack!''
notice: /Stage[main]/Dog/Notify[local foo]/message: defined
''message'' as
''woof''
notice: /Stage[main]/Cat/Notify[dog sound from cat class]/message:
defined ''message'' as ''woof''
****************************************
You can see how I can reference variables in another class (dog sound in
the cat class) through their "scope" (the name of the class) even
though
there is a local variable named the same thing in the cat class.
You can also see that the local variables takes precedence over the
''global'' top scope ($duck in this case). Top scope variables
are
anything that aren''t defined in a class, so things out of your site.pp,
also some internal Puppet variables are top scope.
Accessing variables in nested classes is simple as well:
$module::subclass1::subclass2::subclass3:variablename
Does that help?
-Luke
On 17/09/12 19:27, Balasubramaniam Natarajan wrote:> On this particular link
> http://docs.puppetlabs.com/learning/variables.html#variables I am a
> bit confused about the following two statement. Could someone explain
> to me as to what is this about, with a simple example ?
>
> Every variable has a short local name and a long fully-qualified name.
> Fully qualified variables look like |$scope::variable|. Top scope
> variables are the same, but their scope is nameless. (For example:
> |$::top_scope_variable|.)
>
> If you reference a variable with its short name and it isn’t present
> in the local scope, Puppet will also check the top scope;^1
> <http://docs.puppetlabs.com/learning/variables.html#fn:dynamic> this
> means you can almost always refer to global variables with just their
> short names.
>
> --
> Regards,
> Balasubramaniam Natarajan
> www.etutorshop.com/moodle/ <http://www.etutorshop.com/moodle/>
>
> --
> 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 Bigum
Senior Systems Engineer
Information Systems
Ph: +44 (0) 20 3192 2520
luke.bigum@lmax.com | http://www.lmax.com
LMAX, Yellow Building, 1A Nicholas Road, London W11 4AN
FX and CFDs are leveraged products that can result in losses exceeding
your deposit. They are not suitable for everyone so please ensure you
fully understand the risks involved. The information in this email is not
directed at residents of the United States of America or any other
jurisdiction where trading in CFDs and/or FX is restricted or prohibited
by local laws or regulations.
The information in this email and any attachment is confidential and is
intended only for the named recipient(s). The email may not be disclosed
or used by any person other than the addressee, nor may it be copied in
any way. If you are not the intended recipient please notify the sender
immediately and delete any copies of this message. Any unauthorised
copying, disclosure or distribution of the material in this e-mail is
strictly forbidden.
LMAX operates a multilateral trading facility. Authorised and regulated
by the Financial Services Authority (firm registration number 509778) and
is registered in England and Wales (number 06505809).
Our registered address is Yellow Building, 1A Nicholas Road, London, W11
4AN.
--
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.