Sha256: 5c141ebdb31e213e581fc939594ff2e6e47b84c51b69c6606cbb771e5d2c5ead

Contents?: true

Size: 1.87 KB

Versions: 159

Compression:

Stored size: 1.87 KB

Contents

require 'puppet/indirector/facts/facter'

require 'puppet/configurer'
require 'puppet/configurer/downloader'

# Break out the code related to facts.  This module is
# just included into the agent, but having it here makes it
# easier to test.
module Puppet::Configurer::FactHandler
  def find_facts
    # This works because puppet agent configures Facts to use 'facter' for
    # finding facts and the 'rest' terminus for caching them.  Thus, we'll
    # compile them and then "cache" them on the server.
    begin
      facts = Puppet::Node::Facts.indirection.find(Puppet[:node_name_value], :environment => Puppet::Node::Environment.remote(@environment))
      unless Puppet[:node_name_fact].empty?
        Puppet[:node_name_value] = facts.values[Puppet[:node_name_fact]]
        facts.name = Puppet[:node_name_value]
      end
      facts
    rescue SystemExit,NoMemoryError
      raise
    rescue Exception => detail
      message = _("Could not retrieve local facts: %{detail}") % { detail: detail }
      Puppet.log_exception(detail, message)
      raise Puppet::Error, message, detail.backtrace
    end
  end

  def facts_for_uploading
    facts = find_facts

    # NOTE: :facts specified as parameters are URI encoded here,
    # then  encoded for a second time depending on their length:
    #
    # <= 1024 characters sent via query string of a HTTP GET, additionally query string encoded
    # > 1024 characters sent in POST data, additionally x-www-form-urlencoded
    # so it's only important that encoding method here return original values
    # correctly when CGI.unescape called against it (in compiler code)
    if Puppet[:preferred_serialization_format] == "pson"
      {:facts_format => :pson, :facts => Puppet::Util.uri_query_encode(facts.render(:pson)) }
    else
      {:facts_format => 'application/json', :facts => Puppet::Util.uri_query_encode(facts.render(:json)) }
    end
  end
end

Version data entries

159 entries across 159 versions & 2 rubygems

Version Path
puppet-5.5.22 lib/puppet/configurer/fact_handler.rb
puppet-5.5.22-x86-mingw32 lib/puppet/configurer/fact_handler.rb
puppet-5.5.22-x64-mingw32 lib/puppet/configurer/fact_handler.rb
puppet-5.5.22-universal-darwin lib/puppet/configurer/fact_handler.rb
puppet-5.5.21 lib/puppet/configurer/fact_handler.rb
puppet-5.5.21-x86-mingw32 lib/puppet/configurer/fact_handler.rb
puppet-5.5.21-x64-mingw32 lib/puppet/configurer/fact_handler.rb
puppet-5.5.21-universal-darwin lib/puppet/configurer/fact_handler.rb
puppet-5.5.20 lib/puppet/configurer/fact_handler.rb
puppet-5.5.20-x86-mingw32 lib/puppet/configurer/fact_handler.rb
puppet-5.5.20-x64-mingw32 lib/puppet/configurer/fact_handler.rb
puppet-5.5.20-universal-darwin lib/puppet/configurer/fact_handler.rb
puppet-5.5.19 lib/puppet/configurer/fact_handler.rb
puppet-5.5.19-x86-mingw32 lib/puppet/configurer/fact_handler.rb
puppet-5.5.19-x64-mingw32 lib/puppet/configurer/fact_handler.rb
puppet-5.5.19-universal-darwin lib/puppet/configurer/fact_handler.rb
puppet-5.5.18 lib/puppet/configurer/fact_handler.rb
puppet-5.5.18-x86-mingw32 lib/puppet/configurer/fact_handler.rb
puppet-5.5.18-x64-mingw32 lib/puppet/configurer/fact_handler.rb
puppet-5.5.18-universal-darwin lib/puppet/configurer/fact_handler.rb