Share in top social networks!

Recently ran into some of these when running Puppet 2.7.x:

warning: Dynamic lookup of $variable is deprecated. Support
will be removed in Puppet 2.8.  Use a fully-qualified variable
name (e.g., $classname::variable) or parameterized classes.

The solution was pretty obvious and it’s easy to fix because the solution is mentioned in the warning. However the warning fails to mention what to do with Facter facts inside ERB templates. Figuring out how to fix this took me quite a while although it’s easy too.

Let’s start by taking a look at this snippet:

NameVirtualHost <%= 'ipaddress' %>:80
< VirtualHost <%= 'ipaddress' %>:80 >
	Servername www.example.com
	DocumentRoot /var/www/vhosts/example.com
	ServerAdmin info@example.com

If we’d apply this template in a manifest using Puppet 2.7.x we would run into the warning mentioned above because the IP address fact is out of scope. In order to avoid this we use lookupvar for Facter facts:

NameVirtualHost <%= scope.lookupvar('ipaddress') %>:80
< VirtualHost <%= scope.lookupvar('ipaddress') %>:80 >
	Servername www.example.com
	DocumentRoot /var/www/vhosts/example.com
	ServerAdmin info@example.com
Share in top social networks!

  3 Responses to ““Dynamic lookup is deprecated. Support will be removed in Puppet 2.8.” when using facts in templates”

  1. For a fact I believe you need : to prefix the fact with ::

    ex :

    otherwise you still get :

    Use a fully-qualified variable name (e.g., $classname::variable) or parameterized classes.

  2. Facter facts are defined in the top-level scope. So you’re able to use $::ipaddress, too.

    Saz

  3. Please ignore my last comment. It’s wrong. You were talking about ERB templates.

    Saz

 Leave a Reply

(required)

(required)


× 9 = eighty one

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

   
© 2012 Penumbra Suffusion theme by Sayontan Sinha