prep for 2.8: scopes and variables: nodes are not classes

150 views
Skip to first unread message

vagn scott

unread,
Aug 1, 2011, 11:09:19 AM8/1/11
to puppet...@googlegroups.com
prep for 2.8:  scopes and variables: nodes are not classes

I have been preparing for 2.8 by
experimenting with 2.7.X and seeing
what it takes to get rid of the
warnings.  I would like to share my
results in a number of upcoming  posts.

Begin with the simple question of
hard-wiring scopes.  the 'shocking'
revelation is that variables defined
in nodes are no longer visible outside
the node.  So, if you rely on that for
configuration, you should rewrite the
node as a class, and then include that
class in a trivial node.  You can then
get at the variables by explicitly
mentioning the scope of the class.

This post doesn't talk about default
values, inheritance, or specialization.
I will talk about that later.

Attached are three scripts

01_config.pp

        old style
        defines variables in nodes
        relies on dynamic scope

02_config.pp

        broken
        failed attempt to qualify variables
        nodes are not classes
        nodes cannot be named as a scope

03_config.pp

        fixed, new style
        all variables defined in classes
        nodes as containers for classes
        no variables defined in nodes

Of course it is still possible
to define resources and variables
in nodes.  But the variables will
not be visible in any class scope and
cannot be used to implicitly configure
classes.

Comments and corrections welcome.

--vagn


results of running the three scripts:

vagn@nika:~/puppet-nika/patterns$ ./01_config.pp
notice: Scope(Class[main]): puppet version: 2.7.2

notice: Scope(Class[Legacy]): var1_global is global
warning: Dynamic lookup of $var2_base_node at /u0/home/vagn/puppet-nika/patterns/01_config.pp:21 is deprecated.  Support will be removed in Puppet 2.8.  Use a fully-qualified variable name (e.g., $classname::variable) or parameterized classes.

notice: Scope(Class[Legacy]): var2 defined in base node
warning: Dynamic lookup of $var3_node at /u0/home/vagn/puppet-nika/patterns/01_config.pp:22 is deprecated.  Support will be removed in Puppet 2.8.  Use a fully-qualified variable name (e.g., $classname::variable) or parameterized classes.

notice: Scope(Class[Legacy]): var3 defined in default (aka host) node
notice: Finished catalog run in 0.15 seconds

vagn@nika:~/puppet-nika/patterns$ ./02_config.pp
notice: Scope(Class[main]): puppet version: 2.7.2

notice: Scope(Class[Legacy]): var1_global is global

warning: Scope(Class[Legacy]): Could not look up qualified variable 'base::var2_base_node'; class base could not be found at /u0/home/vagn/puppet-nika/patterns/02_config.pp:21

notice: Scope(Class[Legacy]):
warning: Scope(Class[Legacy]): Could not look up qualified variable 'default::var3_node'; class default could not be found at /u0/home/vagn/puppet-nika/patterns/02_config.pp:22

notice: Scope(Class[Legacy]):
notice: Finished catalog run in 0.15 seconds

vagn@nika:~/puppet-nika/patterns$ ./03_config.pp
notice: Scope(Class[main]): puppet version: 2.7.2

notice: Scope(Class[Foo]): var1_global is global
notice: Scope(Class[Foo]): var2 defined in base node
notice: Scope(Class[Foo]): var3 defined in default (aka host) node
notice: Finished catalog run in 0.15 seconds

vagn@nika:~/puppet-nika/patterns$


01_config.pp
02_config.pp
03_config.pp
Reply all
Reply to author
Forward
0 new messages