aboutsummaryrefslogtreecommitdiffstats
path: root/modules/stored_config/lib/puppet/parser/functions/get_fact.rb
blob: 1aae8b5a484f3dbd5a7a2a23ca7edaaee5720eb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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]

        Puppet::Rails.connect()
        return Puppet::Rails::FactValue.find( :first,
                                              :joins => [ :host, :fact_name ],
                                              :conditions => { :fact_names => {:name => fact },
                                                               :hosts => {:name => node }} 
                                            ).value
    end
end