Custom fact scoping problem

111 views
Skip to first unread message

Greg Etling

unread,
Jul 15, 2011, 12:39:42 PM7/15/11
to puppet...@googlegroups.com
OK, I think this is probably something that is entirely my fault, but I cannot access a facter fact that I need. It evaluates only on certain clients, and is dependent upon the creation and value of another fact. Client and server are puppet 2.6.6 and facter 1.5.9.

Custom fact defined in common module:
/etc/puppetdev/modules/common/lib/facter/openldap.rb
Facter.add("is_ldap_server") do
  setcode do
    if  FileTest.exists?("/usr/sbin/slapd")
      Facter.add("ldap_rid") do
        setcode do
          case Facter::network_eth0
          when "192.168.96.0"
            Facter::ipaddress[/[0-9]+$/].chomp
          when "192.168.97.0"
            ( 500 + Facter::ipaddress_eth0[/[0-9]+$/].chomp.to_i )
          end
end
      end
      %x{echo yes}.chomp
    else
      %x{echo no}.chomp
    end
  end
end

This fact does evaluate on the client in question:
ldap_rid => 529

However, whatever way I use to try to find it in my template fails...can someone please help?
Attempted syntaxes:
<%= @ldap_rid %>
<% @ldap_rid %>
<%= ldap_rid %>
<% ldap_rid %>
<%= scope.lookupvar("ldap_rid") %>
<%= scope.lookupvar("::ldap_rid") %>
...probably others as well. I'm probably just scoping it wrong, but every time it comes up as blank or 'undef'.

Thanks.

Greg Etling

unread,
Jul 15, 2011, 1:50:11 PM7/15/11
to puppet...@googlegroups.com
Well, whatever problem I'm seeing is due to the nested Facter.add statements...when I pulled the ldap_rid one out and ran it separately, it worked.

Greg Etling

unread,
Jul 15, 2011, 2:02:19 PM7/15/11
to puppet...@googlegroups.com
I have it working, but I'm curious if this might be a bug with nested Facter.add statements?

I simply un-nested them and used a 'confine' statement to make things work. New facts posted below:
Facter.add("is_ldap_server") do
  setcode do
    if  FileTest.exists?("/usr/sbin/slapd")
      %x{echo yes}.chomp
    else
      %x{echo no}.chomp
    end
  end
end

Facter.add("ldap_rid") do
  confine :is_ldap_server => :yes

Ken Barber

unread,
Jul 15, 2011, 2:12:31 PM7/15/11
to puppet...@googlegroups.com
IMHO I don't think I want nested facts to work :-). The evaluation
order alone is trouble some ... ie. the inner fact wouldn't get added
until the enclosed fact is evaluated ... doesn't sound like something
you would want in ordinary circumstances :-). Remember sometimes fact
information is gather on a per-fact basis and doing nesting would
break this for your inner fact.

I think using the confine is fine :-).

ken.

> --
> 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/-/ob5dE8e2afMJ.
> To post to this group, send email to puppet...@googlegroups.com.
> To unsubscribe from this group, send email to
> puppet-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/puppet-users?hl=en.
>

--
"Join us for PuppetConf, September 22nd and 23rd in Portland, OR:
http://bit.ly/puppetconfsig"

Reply all
Reply to author
Forward
0 new messages