Module: Beaker::DSL::Helpers::FacterHelpers

Defined in:
lib/beaker/dsl/helpers/facter_helpers.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#fact(name, opts = {}) ⇒ Object

Get a facter fact from the default host

See Also:



50
51
52
# File 'lib/beaker/dsl/helpers/facter_helpers.rb', line 50

def fact(name, opts = {})
  fact_on(default, name, opts)
end

#fact_on(host, name, opts = {}) ⇒ Object

Get a facter fact from a provided host

Parameters:

  • host (Host, Array<Host>, String, Symbol)

    One or more hosts to act upon, or a role (String or Symbol) that identifies one or more hosts.

  • name (String)

    The name of the fact to query for

  • opts (Hash{Symbol=>String}) (defaults to: {})

    Options to alter execution.

Options Hash (opts):

  • :silent (Boolean) — default: false

    Do not produce log output

  • :acceptable_exit_codes (Array<Fixnum>) — default: [0]

    An array (or range) of integer exit codes that should be considered acceptable. An error will be thrown if the exit code does not match one of the values in this list.

  • :accept_all_exit_codes (Boolean) — default: false

    Consider all exit codes as passing.

  • :dry_run (Boolean) — default: false

    Do not actually execute any commands on the SUT

  • :stdin (String) — default: nil

    Input to be provided during command execution on the SUT.

  • :pty (Boolean) — default: false

    Execute this command in a pseudoterminal.

  • :expect_connection_failure (Boolean) — default: false

    Expect this command to result in a connection failure, reconnect and continue execution.

  • :environment (Hash{String=>String}) — default: {}

    These will be treated as extra environment variables that should be set before running the command.

Returns:

  • String The value of the fact 'name' on the provided host

Raises:

  • (FailTest)

    Raises an exception if call to facter fails



39
40
41
42
43
44
45
46
# File 'lib/beaker/dsl/helpers/facter_helpers.rb', line 39

def fact_on(host, name, opts = {})
  result = on host, facter(name, opts)
  if result.kind_of?(Array)
    result.map { |res| res.stdout.chomp }
  else
    result.stdout.chomp
  end
end