module Beaker::DSL::Helpers::FacterHelpers

Methods that help you interact with your facter installation, facter must be installed for these methods to execute correctly

Public Instance Methods

fact(name, opts = {}) click to toggle source

Get a facter fact from the default host @see fact_on

# File lib/beaker-puppet/helpers/facter_helpers.rb, line 57
def fact(name, opts = {})
  fact_on(default, name, opts)
end
fact_on(host, name, opts = {}) click to toggle source

Get a facter fact from a provided host

@param [Host, Array<Host>, String, Symbol] host One or more hosts to act upon,

or a role (String or Symbol) that identifies one or more hosts.

@param [String] name The name of the fact to query for @!macro common_opts

@return String The value of the fact 'name' on the provided host @raise [FailTest] Raises an exception if call to facter fails

# File lib/beaker-puppet/helpers/facter_helpers.rb, line 39
def fact_on(host, name, opts = {})
  raise(ArgumentError, "fact_on's `name` option must be a String. You provided a #{name.class}: '#{name}'") unless name.is_a?(String)
  if opts.kind_of?(Hash)
    opts.merge!({json: nil})
  else
    opts << ' --json'
  end

  result = on host, facter("\"#{name}\"", opts)
  if result.kind_of?(Array)
    result.map { |res| JSON.parse(res.stdout)[name] }
  else
    JSON.parse(result.stdout)[name]
  end
end