aboutsummaryrefslogtreecommitdiffstats
path: root/modules/stored_config/lib/puppet/parser/functions/get_fact.rb
blob: 8acdb2d5f396f6c1f93cf6dc0fe19a610ba4b1eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
require 'puppet/rails'

#  get_fact($node,$fact)
#    -> return the fact, from stored config

module Puppet::Parser::Functions
    newfunction(:get_fact, :type => :rvalue) do |args| 
        node = args[0]
        fact = args[1]
        # TODO use 
        # Puppet::Node::Facts.indirection.find(Puppet[:certname])
        Puppet::Rails.connect()
        return Puppet::Rails::FactValue.find( :first,
                                              :joins => [ :host, :fact_name ],
                                              :conditions => { :fact_names => {:name => fact },
                                                               :hosts => {:name => node }} 
                                            ).value
    end
end