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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to