Facts in ERB Template not working

496 views
Skip to first unread message

zjhe...@gmail.com

unread,
Apr 21, 2014, 5:45:09 PM4/21/14
to puppet...@googlegroups.com
Having an odd issue with the facts inside an ERB template.  I'm using the facts to build a somewhat dynamic MOTD.  I made some changes to init.pp for the module and deployed to my Dev environment and it started breaking things.  It started off with not being able to find a value for lsbdistdescription

Could not retrieve catalog from remote server: Error 400 on SERVER: Failed to parse template motd/motd.erb: Filepath: /usr/lib/ruby/site_ruby/1.8/puppet/parser/templatewrapper.rb Line: 81 Detail: Could not find value for 'lsbdistdescription' at /etc/puppet/environments/development/modules/motd/templates/motd.erb:10 at /etc/puppet/environments/development/modules/motd/manifests/init.pp:44 on node cbe01d.example.com

Looking into the issue the only thing I found was that facts should now have an @ sign in front of them. Changing that didn't help.  I have reverted back to the old code and its still broken.  Oddly enough, it works as expected when I go to the server and run $ sudo puppet agent -t.  It applies the lsbdistdescription to MOTD, then the puppet daemon fires off after 30minutes and does not acknowledge lsbdistdescription.

Here is the current template:
+++++++++++++++++: System Data :+++++++++++++++++++
+ Hostname = <%= hostname %>
+ Domain = <%= domain %>
+ Address = <%= ipaddress_eth0 %>
+ OS: <%= @lsbdistdescription %> <%= architecture %>
+ Kernel = <%= kernelrelease %>
+ Uptime = <%= uptime %>
+ CPU = <%= processorcount %>x  <%= processor0 %>
+ Total Memory = <%= memorysize %>
+ Managed by Puppet version <%= puppetversion %>
<% if @extra -%>
+ Extra Info = <%= @extra %>
<% end -%>
+++++++++++++++++++++++++++++++++++++++++++++++++++

Any ideas why only manual runs work as expected?

jcbollinger

unread,
Apr 22, 2014, 9:35:05 AM4/22/14
to puppet...@googlegroups.com


On Monday, April 21, 2014 4:45:09 PM UTC-5, zjhe...@gmail.com wrote:
Having an odd issue with the facts inside an ERB template.  I'm using the facts to build a somewhat dynamic MOTD.  I made some changes to init.pp for the module and deployed to my Dev environment and it started breaking things.  It started off with not being able to find a value for lsbdistdescription

Could not retrieve catalog from remote server: Error 400 on SERVER: Failed to parse template motd/motd.erb: Filepath: /usr/lib/ruby/site_ruby/1.8/puppet/parser/templatewrapper.rb Line: 81 Detail: Could not find value for 'lsbdistdescription' at /etc/puppet/environments/development/modules/motd/templates/motd.erb:10 at /etc/puppet/environments/development/modules/motd/manifests/init.pp:44 on node cbe01d.example.com

Looking into the issue the only thing I found was that facts should now have an @ sign in front of them.


That is the current recommendation, but it is not a requirement.  Bare variable names work, too.

 
Changing that didn't help.  I have reverted back to the old code and its still broken.  Oddly enough, it works as expected when I go to the server and run $ sudo puppet agent -t.  It applies the lsbdistdescription to MOTD, then the puppet daemon fires off after 30minutes and does not acknowledge lsbdistdescription.


So, under what conditions does it not work?  Because running the agent on the node that hosts the master is not fundamentally different from running it on any other node.

 

Here is the current template:
+++++++++++++++++: System Data :+++++++++++++++++++
+ Hostname = <%= hostname %>
+ Domain = <%= domain %>
+ Address = <%= ipaddress_eth0 %>
+ OS: <%= @lsbdistdescription %> <%= architecture %>
+ Kernel = <%= kernelrelease %>
+ Uptime = <%= uptime %>
+ CPU = <%= processorcount %>x  <%= processor0 %>
+ Total Memory = <%= memorysize %>
+ Managed by Puppet version <%= puppetversion %>
<% if @extra -%>
+ Extra Info = <%= @extra %>
<% end -%>
+++++++++++++++++++++++++++++++++++++++++++++++++++

Any ideas why only manual runs work as expected?



The problem is much more likely to be tied to specific target nodes than to be related to the manner in which you launch the agent.  In particular, whether the LSB-related facts are provided by a given node may depend on whether a particular package is installed there.  And that makes sense, too, because such machines might not comply with any version of the LSB.

A quick look at the Facter code confirms that only nodes that provide the lsb_release command will assert the lsbdistdescription fact.  On RedHat-family Linuxes that command is provided by the "redhat-lsb" package.

Going forward, you clearly cannot rely on your nodes to provide LSB-related facts.  You could probably work around this issue by putting this declaration in the class or definition that uses the template:

$lsbdistdescription = "${::lsbdistdescription}"

That reliably sets a local variable that itself is always present, and that will shadow the global fact if the fact exists.  The local variable will have the same value as the global, or an empty value if the global does not exist.  Of course, you could get more creative, too.  For example, you could arrange to provide a non-empty default value when there is no lsbdistdescription.


John

Sans

unread,
Apr 22, 2014, 10:36:01 AM4/22/14
to puppet...@googlegroups.com


On Tuesday, April 22, 2014 2:35:05 PM UTC+1, jcbollinger wrote:


That is the current recommendation, but it is not a requirement.  Bare variable names work, too.
 
You sure it's just a "recommendation"? IIRC, it doesn't work with Ruby v1.9.x.
But that's definitely not the actual problem here though.

Felix Frank

unread,
Apr 22, 2014, 10:43:14 AM4/22/14
to puppet...@googlegroups.com
On 04/22/2014 04:36 PM, Sans wrote:
> You sure it's just a "recommendation"? IIRC, it doesn't work with Ruby
> v1.9.x.
> But that's definitely not the actual problem here though.

That's right.

The @ is just to safeguard against an issue where variable names clash
with method names from the ruby kernel, such as 'fork' etc. This is all
independent of product versions.

Have you made sure that for the node in question, the lsbdistdescription
fact is actually available? It's one of the oddball facts that is tied
to certain packages (i.e. lsb packages) on the agent system.

HTH,
Felix

zjhe...@gmail.com

unread,
Apr 22, 2014, 11:17:00 AM4/22/14
to puppet...@googlegroups.com
I can run $ lsb-release -a on the servers in question and it returns the information I expect.  When I use the @lsbdistdescription the local puppet daemon does not acknowledge the field.  That line simply gets the architecture.  With the @ there is nothing to report when I look in foreman, when I remove the @ I get the error again.

Here is the output from the commands:
$ lsb_release -a
LSB Version:    :core-4.0-amd64:core-4.0-ia32:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-ia32:printing-4.0-noarch
Distributor ID:    RedHatEnterpriseServer
Description:    Red Hat Enterprise Linux Server release 5.10 (Tikanga)
Release:    5.10
Codename:    Tikanga

$ facter lsbdistdescription
Red Hat Enterprise Linux Server release 5.10 (Tikanga)

Reply all
Reply to author
Forward
0 new messages