puppet 4.4 syntax help with nested fact using erb template (solved)

810 views
Skip to first unread message

Aaron D

unread,
Apr 13, 2016, 7:48:10 PM4/13/16
to Puppet Users
Hi, I'm trying to get a fact into a file.  It worked fine in puppet 3.0.2 but now with 4.4 it doesn't work.  It seems I'm not understanding the new syntax or maybe the scope level too?

As I was writing this I figured out the solution and am including it here in case others come across the same problem.  Nested facts aren't documented in the puppet docs, only first level facts.

Problem:
This line returns a blank instead of the mac address.
HWADDR="<%= scope.lookupvar('::networking::interfaces::eth0::mac') %>"

This line is also blank
HWADDR="<%= scope['::networking::interfaces::eth0::mac'] %>"

I've also tried this but it is also blank
HWADDR="<%= @mac %>"

If I use I try this it works and I get the facter version
HWADDR="<%= @facterversion %>"

but this doesn't
HWADDR="<%= ::facterversion %>"

====================================================================

Solution: 
HWADDR="<%= scope['networking']['interfaces']['eth0']['mac'] %>"

=====================================================================
host facter results

networking => {
  dhcp => "192.168.16.5",
  domain => "example.com",
  fqdn => "s1.example.com",
  hostname => "s1",
  interfaces => {
    eth0 => {
      dhcp => "192.168.16.5",
      mac => "00:xx:xx:xx:xx:c2",
      mtu => 1500
}

=====================================================================
file I'm trying to change

DEVICE="eth0"
HWADDR="<%= scope.lookupvar('::networking::interfaces::eth0::mac') %>"  #this line not working
NM_CONTROLLED=no
ONBOOT=yes
BOOTPROTO=none
TYPE=Ethernet
USERCTL=no
IPV6INIT=no


Francois Lafont

unread,
Apr 14, 2016, 7:20:56 AM4/14/16
to puppet...@googlegroups.com
Hello,

Try this in your template:

HWADDR is <%= scope.lookupvar('::networking')['interfaces']['eth0']['mac'] %>

or this:

HWADDR is <%= scope.lookupvar('::facts')['networking']['interfaces']['eth0']['mac'] %>

Now, with Puppet 4, facts are structured. You can use the global $::facts hash.

Regards.
François Lafont

aloha...@gmail.com

unread,
Apr 14, 2016, 6:15:19 PM4/14/16
to puppet...@googlegroups.com
Thanks Francois, that works as well!


--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/570F7D09.6080501%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages