I want to have a parametrized class with lookup from params.pp but I keep getting into problems. init.pp: class foo ( $bar = $foo::params::bar, $foofoo = $foo::params::foofoo ) inherits foo::params { file {''/tmp/foobar'': content => template("foo/foobar.erb"), } } params: class foo::params { $bar = true if $foo::bar { $foobar = ''yes'' $foofoo = ''foo'' } else { $foobar = ''no'' $foofoo = ''bar'' } } foobar.erb: <% if scope.lookupvar(''foo::boo'') -%> <%= scope.lookupvar(''foo::foofoo'') %> <% end -%> <%= scope.lookupvar(''foo::params::foobar'') %> <%= scope.lookupvar("foo::foofoo") %> When I run puppet on the class I get: puppet apply --modulepath=/modules/ foo/test/init.pp warning: Scope(Class[Foo::Params]): Could not look up qualified variable ''foo::bar''; class foo has not been evaluated at /modules/foo/manifests/params.pp:3 warning: Scope(Class[Foo::Params]): Could not look up qualified variable ''foo::bar''; class foo has not been evaluated at /modules/foo/manifests/params.pp:3 notice: Finished catalog run in 0.02 seconds and the file looks like: /tmp/foobar: bar no bar If I use include params.pp instead of inherits puppet gives: puppet apply --modulepath=/modules/ foo/test/init.pp warning: Scope(Class[Foo]): Could not look up qualified variable ''foo::params::bar''; class foo::params has not been evaluated at /modules/foo/manifests/init.pp:2 warning: Scope(Class[Foo]): Could not look up qualified variable ''foo::params::bar''; class foo::params has not been evaluated at /modules/foo/manifests/init.pp:2 warning: Scope(Class[Foo]): Could not look up qualified variable ''foo::params::foofoo''; class foo::params has not been evaluated at /modules/foo/manifests/init.pp:3 warning: Scope(Class[Foo]): Could not look up qualified variable ''foo::params::foofoo''; class foo::params has not been evaluated at /modules/foo/manifests/init.pp:3 and the file looks like. /tmp/foobar: undef no undef What I want it to look like is of cause: bar yes bar -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/5v355b9Eo0QJ. 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.
When you inherit from a class the class you inherit from is evaluated first, which is why it is able to set the parameter defaults for the "subclass". So when those if statements in foo::params are evaluated the class foo simply haven''t been evaluated yet, so you can''t reference any variables in it. Neither class parameters or normal variables. If you replace $foo::bar with just $bar in the if statement it should work. On 13 August 2012 08:51, Svein <svein@soleim.at> wrote:> I want to have a parametrized class with lookup from params.pp but I keep > getting into problems. > > > > init.pp: > class foo ( > $bar = $foo::params::bar, > $foofoo = $foo::params::foofoo > ) inherits foo::params { > file {''/tmp/foobar'': > content => template("foo/foobar.erb"), > } > > } > params: > class foo::params { > $bar = true > if $foo::bar { > $foobar = ''yes'' > $foofoo = ''foo'' > } > else { > $foobar = ''no'' > $foofoo = ''bar'' > } > } > > foobar.erb: > <% if scope.lookupvar(''foo::boo'') -%> > <%= scope.lookupvar(''foo::foofoo'') %> > <% end -%> > <%= scope.lookupvar(''foo::params::foobar'') %> > <%= scope.lookupvar("foo::foofoo") %> > > When I run puppet on the class I get: > puppet apply --modulepath=/modules/ foo/test/init.pp > warning: Scope(Class[Foo::Params]): Could not look up qualified variable > ''foo::bar''; class foo has not been evaluated at > /modules/foo/manifests/params.pp:3 > warning: Scope(Class[Foo::Params]): Could not look up qualified variable > ''foo::bar''; class foo has not been evaluated at > /modules/foo/manifests/params.pp:3 > notice: Finished catalog run in 0.02 seconds > > and the file looks like: > /tmp/foobar: > bar > no > bar > > > If I use include params.pp instead of inherits puppet gives: > puppet apply --modulepath=/modules/ foo/test/init.pp > warning: Scope(Class[Foo]): Could not look up qualified variable > ''foo::params::bar''; class foo::params has not been evaluated at > /modules/foo/manifests/init.pp:2 > warning: Scope(Class[Foo]): Could not look up qualified variable > ''foo::params::bar''; class foo::params has not been evaluated at > /modules/foo/manifests/init.pp:2 > warning: Scope(Class[Foo]): Could not look up qualified variable > ''foo::params::foofoo''; class foo::params has not been evaluated at > /modules/foo/manifests/init.pp:3 > warning: Scope(Class[Foo]): Could not look up qualified variable > ''foo::params::foofoo''; class foo::params has not been evaluated at > /modules/foo/manifests/init.pp:3 > > and the file looks like. > /tmp/foobar: > undef > no > undef > > > What I want it to look like is of cause: > bar > yes > bar > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/puppet-users/-/5v355b9Eo0QJ. > 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.-- Erik Dalén -- 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.
On Monday, August 13, 2012 9:25:44 AM UTC+2, Erik Dalén wrote:> > When you inherit from a class the class you inherit from is evaluated > first, which is why it is able to set the parameter defaults for the > "subclass". > > So when those if statements in foo::params are evaluated the class foo > simply haven''t been evaluated yet, so you can''t reference any > variables in it. Neither class parameters or normal variables. > > If you replace $foo::bar with just $bar in the if statement it should > work. > > And it did. Thank you. This is what I get when I try to be nice andspecify exactly from where it should load its variables :) -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/7Rx--JLr2jkJ. 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.