Module: Facter

Includes:
ApiDebugger
Defined in:
lib/facter/util/aix/odm_query.rb,
lib/facter.rb,
lib/facter/config.rb,
lib/facter/version.rb,
lib/facter/util/utils.rb,
lib/facter/resolvers/az.rb,
lib/facter/resolvers/dmi.rb,
lib/facter/resolvers/ec2.rb,
lib/facter/resolvers/gce.rb,
lib/facter/resolvers/ssh.rb,
lib/facter/resolvers/xen.rb,
lib/facter/resolvers/zfs.rb,
lib/facter/resolvers/lpar.rb,
lib/facter/resolvers/path.rb,
lib/facter/resolvers/ruby.rb,
lib/facter/resolvers/wpar.rb,
lib/facter/resolvers/disks.rb,
lib/facter/resolvers/lspci.rb,
lib/facter/resolvers/uname.rb,
lib/facter/resolvers/zpool.rb,
lib/facter/util/linux/dhcp.rb,
lib/facter/resolvers/augeas.rb,
lib/facter/resolvers/memory.rb,
lib/facter/resolvers/uptime.rb,
lib/facter/resolvers/vmware.rb,
lib/facter/util/file_helper.rb,
lib/facter/framework/cli/cli.rb,
lib/facter/resolvers/aix/nim.rb,
lib/facter/resolvers/open_vz.rb,
lib/facter/resolvers/selinux.rb,
lib/facter/resolvers/sw_vers.rb,
lib/facter/util/api_debugger.rb,
lib/facter/models/loaded_fact.rb,
lib/facter/resolvers/hostname.rb,
lib/facter/resolvers/identity.rb,
lib/facter/resolvers/timezone.rb,
lib/facter/util/resolvers/ssh.rb,
lib/facter/resolvers/aix/disks.rb,
lib/facter/resolvers/virt_what.rb,
lib/facter/util/linux/if_inet6.rb,
lib/facter/util/resolvers/http.rb,
lib/facter/models/resolved_fact.rb,
lib/facter/models/searched_fact.rb,
lib/facter/resolvers/aix/memory.rb,
lib/facter/resolvers/containers.rb,
lib/facter/resolvers/dmi_decode.rb,
lib/facter/resolvers/macosx/dmi.rb,
lib/facter/resolvers/networking.rb,
lib/facter/resolvers/os_release.rb,
lib/facter/resolvers/partitions.rb,
lib/facter/resolvers/processors.rb,
lib/facter/resolvers/aix/ffi/ffi.rb,
lib/facter/resolvers/eos_release.rb,
lib/facter/resolvers/filesystems.rb,
lib/facter/resolvers/freebsd/dmi.rb,
lib/facter/resolvers/lsb_release.rb,
lib/facter/resolvers/mountpoints.rb,
lib/facter/resolvers/solaris/dmi.rb,
lib/facter/resolvers/windows/ssh.rb,
lib/facter/util/windows/win32ole.rb,
lib/facter/custom_facts/util/fact.rb,
lib/facter/framework/core/options.rb,
lib/facter/models/fact_collection.rb,
lib/facter/resolvers/aix/hardware.rb,
lib/facter/resolvers/aix/os_level.rb,
lib/facter/resolvers/fips_enabled.rb,
lib/facter/resolvers/freebsd/geom.rb,
lib/facter/resolvers/solaris/ldom.rb,
lib/facter/resolvers/solaris/zone.rb,
lib/facter/resolvers/suse_release.rb,
lib/facter/resolvers/windows/fips.rb,
lib/facter/util/facts/facts_utils.rb,
lib/facter/resolvers/base_resolver.rb,
lib/facter/resolvers/facterversion.rb,
lib/facter/resolvers/load_averages.rb,
lib/facter/resolvers/solaris/disks.rb,
lib/facter/util/aix/info_extractor.rb,
lib/facter/framework/logging/logger.rb,
lib/facter/resolvers/aix/filesystem.rb,
lib/facter/resolvers/aix/networking.rb,
lib/facter/resolvers/aix/partitions.rb,
lib/facter/resolvers/aix/processors.rb,
lib/facter/resolvers/bsd/processors.rb,
lib/facter/resolvers/debian_version.rb,
lib/facter/resolvers/linux/hostname.rb,
lib/facter/resolvers/redhat_release.rb,
lib/facter/resolvers/solaris/memory.rb,
lib/facter/resolvers/windows/kernel.rb,
lib/facter/resolvers/windows/memory.rb,
lib/facter/resolvers/windows/netkvm.rb,
lib/facter/resolvers/windows/uptime.rb,
lib/facter/util/facts/uptime_parser.rb,
lib/facter/util/linux/routing_table.rb,
lib/facter/util/linux/socket_parser.rb,
lib/facter/util/resolvers/aws_token.rb,
lib/facter/resolvers/aix/ffi/structs.rb,
lib/facter/resolvers/aix/mountpoints.rb,
lib/facter/resolvers/freebsd/virtual.rb,
lib/facter/resolvers/solaris/ffi/ffi.rb,
lib/facter/util/facts/unit_converter.rb,
lib/facter/util/resolvers/ssh_helper.rb,
lib/facter/framework/core/fact_filter.rb,
lib/facter/resolvers/aix/architecture.rb,
lib/facter/resolvers/aix/serialnumber.rb,
lib/facter/resolvers/linux/networking.rb,
lib/facter/resolvers/processors_lscpu.rb,
lib/facter/resolvers/windows/dmi_bios.rb,
lib/facter/resolvers/windows/identity.rb,
lib/facter/resolvers/windows/system32.rb,
lib/facter/resolvers/windows/timezone.rb,
lib/facter/util/resolvers/fingerprint.rb,
lib/facter/custom_facts/core/aggregate.rb,
lib/facter/custom_facts/core/execution.rb,
lib/facter/framework/core/fact_manager.rb,
lib/facter/resolvers/aio_agent_version.rb,
lib/facter/resolvers/aix/load_averages.rb,
lib/facter/resolvers/macosx/processors.rb,
lib/facter/resolvers/solaris/dmi_sparc.rb,
lib/facter/resolvers/solaris/ipaddress.rb,
lib/facter/resolvers/solaris/zone_name.rb,
lib/facter/util/resolvers/ffi/hostname.rb,
lib/facter/custom_facts/util/resolution.rb,
lib/facter/framework/benchmarking/timer.rb,
lib/facter/framework/config/fact_groups.rb,
lib/facter/framework/core/cache_manager.rb,
lib/facter/framework/core/session_cache.rb,
lib/facter/resolvers/aix/ffi/ffi_helper.rb,
lib/facter/resolvers/bsd/ffi/ffi_helper.rb,
lib/facter/resolvers/freebsd/processors.rb,
lib/facter/resolvers/macosx/filesystems.rb,
lib/facter/resolvers/macosx/mountpoints.rb,
lib/facter/resolvers/macosx/swap_memory.rb,
lib/facter/resolvers/solaris/networking.rb,
lib/facter/resolvers/solaris/os_release.rb,
lib/facter/resolvers/solaris/processors.rb,
lib/facter/resolvers/windows/networking.rb,
lib/facter/resolvers/windows/processors.rb,
lib/facter/util/resolvers/uptime_helper.rb,
lib/facter/resolvers/freebsd/swap_memory.rb,
lib/facter/resolvers/linux/docker_uptime.rb,
lib/facter/resolvers/linux/load_averages.rb,
lib/facter/resolvers/solaris/ffi/structs.rb,
lib/facter/resolvers/solaris/filesystems.rb,
lib/facter/resolvers/solaris/mountpoints.rb,
lib/facter/framework/config/config_reader.rb,
lib/facter/framework/parsers/query_parser.rb,
lib/facter/resolvers/macosx/load_averages.rb,
lib/facter/resolvers/macosx/system_memory.rb,
lib/facter/util/resolvers/networking/dhcp.rb,
lib/facter/framework/detector/os_hierarchy.rb,
lib/facter/resolvers/freebsd/system_memory.rb,
lib/facter/resolvers/solaris/ffi/functions.rb,
lib/facter/resolvers/specific_release_file.rb,
lib/facter/custom_facts/core/execution/base.rb,
lib/facter/resolvers/freebsd/ffi/ffi_helper.rb,
lib/facter/resolvers/macosx/system_profiler.rb,
lib/facter/resolvers/windows/virtualization.rb,
lib/facter/util/resolvers/ffi/load_averages.rb,
lib/facter/util/resolvers/filesystem_helper.rb,
lib/facter/custom_facts/core/execution/posix.rb,
lib/facter/resolvers/freebsd/freebsd_version.rb,
lib/facter/resolvers/release_from_first_line.rb,
lib/facter/resolvers/windows/product_release.rb,
lib/facter/util/facts/posix/virtual_detector.rb,
lib/facter/util/facts/windows_release_finder.rb,
lib/facter/custom_facts/core/execution/popen3.rb,
lib/facter/custom_facts/core/execution/windows.rb,
lib/facter/framework/core/options/option_store.rb,
lib/facter/resolvers/windows/aio_agent_version.rb,
lib/facter/util/macosx/system_profile_executor.rb,
lib/facter/resolvers/windows/dmi_computersystem.rb,
lib/facter/resolvers/windows/win_os_description.rb,
lib/facter/util/resolvers/networking/networking.rb,
lib/facter/framework/formatters/formatter_helper.rb,
lib/facter/framework/core/fact/internal/core_fact.rb,
lib/facter/framework/formatters/formatter_factory.rb,
lib/facter/framework/core/fact_loaders/fact_loader.rb,
lib/facter/resolvers/windows/hardware_architecture.rb,
lib/facter/framework/core/options/options_validator.rb,
lib/facter/framework/formatters/json_fact_formatter.rb,
lib/facter/framework/formatters/yaml_fact_formatter.rb,
lib/facter/framework/formatters/hocon_fact_formatter.rb,
lib/facter/framework/core/options/config_file_options.rb,
lib/facter/framework/formatters/legacy_fact_formatter.rb,
lib/facter/util/resolvers/networking/primary_interface.rb,
lib/facter/framework/core/fact_loaders/class_discoverer.rb,
lib/facter/framework/core/fact_loaders/external_fact_loader.rb,
lib/facter/framework/core/fact_loaders/internal_fact_loader.rb,
lib/facter/framework/core/fact/external/external_fact_manager.rb,
lib/facter/framework/core/fact/internal/internal_fact_manager.rb

Overview

Because Open3 uses Process.detach the env $? is not set so this class reimplements Open3.popen3 with Process.wait instead.

FACT-2934

When calling Facter::Core::Execution, $? and $CHILD_STATUS

ruby env variables should be set.

Defined Under Namespace

Modules: Bsd, Config, Core, Framework, Freebsd, OptionsValidator, Resolvers, Util, Utils Classes: CacheManager, ClassDiscoverer, Cli, ConfigFileOptions, ConfigReader, CoreFact, ExternalFactLoader, ExternalFactManager, FactCollection, FactFilter, FactGroups, FactLoader, FactManager, FormatterFactory, FormatterHelper, HoconFactFormatter, InternalFactLoader, InternalFactManager, JsonFactFormatter, LegacyFactFormatter, LoadedFact, Log, OptionStore, Options, OsHierarchy, QueryParser, ResolveCustomFactError, ResolvedFact, SearchedFact, SessionCache, YamlFactFormatter

Constant Summary collapse

VERSION =
'4.4.3'
RED =
"\e[31m"
GREEN =
"\e[32m"
YELLOW =
"\e[33m"
CYAN =
"\e[36m"
RESET =
"\e[0m"
DEFAULT_LOG_LEVEL =
:warn

Class Method Summary collapse

Class Method Details

.[](name) ⇒ Facter::Util::Fact?

Alias method for Facter.fact()

Parameters:

  • name (string)

    fact name

Returns:



82
83
84
# File 'lib/facter.rb', line 82

def [](name)
  fact(name)
end

.add(name, options = {}, &block) ⇒ Facter::Util::Fact

Add custom facts to fact collection

Parameters:

  • name (String)

    Custom fact name

  • options (defaults to: {})

    {} [Hash] optional parameters for the fact - attributes

    of Facter::Util::Fact and Facter::Util::Resolution can be supplied here

  • block (Proc)

    a block defining a fact resolution

Returns:

  • (Facter::Util::Fact)

    the fact object, which includes any previously defined resolutions



97
98
99
100
101
# File 'lib/facter.rb', line 97

def add(name, options = {}, &block)
  options[:fact_type] = :custom
  LegacyFacter.add(name, options, &block)
  LegacyFacter.collection.invalidate_custom_facts
end

.clearnil

Clears all cached values and removes all facts from memory.

Returns:

  • (nil)


108
109
110
111
112
113
114
115
116
117
# File 'lib/facter.rb', line 108

def clear
  @already_searched = {}
  Facter.clear_messages
  LegacyFacter.clear
  Options[:custom_dir] = []
  LegacyFacter.collection.invalidate_custom_facts
  LegacyFacter.collection.reload_custom_facts
  SessionCache.invalidate_all_caches
  nil
end

.clear_messagesnil

Clears the seen state of debug and warning messages.

Returns:

  • (nil)


122
123
124
# File 'lib/facter.rb', line 122

def clear_messages
  Facter::Log.clear_messages
end

.core_value(user_query) ⇒ FactCollection

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Retrieves the value of a core fact. External or custom facts are not returned with this call. Returns ‘nil` if no such fact exists.

Returns:



132
133
134
135
136
137
138
# File 'lib/facter.rb', line 132

def core_value(user_query)
  user_query = user_query.to_s
  resolved_facts = Facter::FactManager.instance.resolve_core([user_query])
  fact_collection = FactCollection.new.build_fact_collection!(resolved_facts)
  splitted_user_query = Facter::Utils.split_user_query(user_query)
  fact_collection.dig(*splitted_user_query)
end

.debug(message) ⇒ nil

Logs debug message when debug option is set to true

Parameters:

  • message (Object)

    Message object to be logged

Returns:

  • (nil)


146
147
148
149
150
151
# File 'lib/facter.rb', line 146

def debug(message)
  return unless debugging?

  logger.debug(message.to_s)
  nil
end

.debugging(debug_bool) ⇒ type

Enable or disable debugging

Parameters:

  • debug_bool (bool)

    State which debugging should have

Returns:

  • (type)
    description


204
205
206
# File 'lib/facter.rb', line 204

def debugging(debug_bool)
  Facter::Options[:debug] = debug_bool
end

.debugging?bool

Check whether debugging is enabled

Returns:

  • (bool)


194
195
196
# File 'lib/facter.rb', line 194

def debugging?
  Options[:debug]
end

.debugonce(message) ⇒ nil

Logs the same debug message only once when debug option is set to true

Parameters:

  • message (Object)

    Message object to be logged

Returns:

  • (nil)


159
160
161
162
# File 'lib/facter.rb', line 159

def debugonce(message)
  logger.debugonce(message)
  nil
end

.define_fact(name, options = {}, &block) ⇒ Facter::Util::Fact

Define a new fact or extend an existing fact.

Parameters:

  • name (Symbol)

    The name of the fact to define

  • options (Hash) (defaults to: {})

    A hash of options to set on the fact

Returns:



172
173
174
175
# File 'lib/facter.rb', line 172

def define_fact(name, options = {}, &block)
  options[:fact_type] = :custom
  LegacyFacter.define_fact(name, options, &block)
end

.disable_sequentialbool

Disable sequential resolving of facts

Returns:

  • (bool)


241
242
243
# File 'lib/facter.rb', line 241

def disable_sequential
  Facter::Options[:sequential] = false
end

.each {|name, value| ... } ⇒ Facter

Iterates over fact names and values

Yield Parameters:

  • name (String)

    the fact name

  • value (String)

    the current value of the fact

Returns:



262
263
264
265
266
267
268
269
270
271
# File 'lib/facter.rb', line 262

def each
  log_blocked_facts
  resolved_facts = Facter::FactManager.instance.resolve_facts

  resolved_facts.each do |fact|
    yield(fact.name, fact.value)
  end

  self
end

.enable_sequentialbool

Enable sequential resolving of facts

Returns:

  • (bool)


232
233
234
# File 'lib/facter.rb', line 232

def enable_sequential
  Facter::Options[:sequential] = true
end

.fact(user_query) ⇒ Facter::Util::Fact?

Returns a fact object by name. If you use this, you still have to call ‘value` on it to retrieve the actual value.

Parameters:

  • user_query (String)

    the name of the fact

Returns:



435
436
437
438
439
440
# File 'lib/facter.rb', line 435

def fact(user_query)
  user_query = user_query.to_s.downcase
  resolve_fact(user_query) unless @already_searched.include?(user_query)

  @already_searched[user_query]
end

.flushvoid

This method returns an undefined value.

Flushes cached values for all facts. This does not cause code to be reloaded; it only clears the cached results.



293
294
295
296
297
# File 'lib/facter.rb', line 293

def flush
  LegacyFacter.flush
  SessionCache.invalidate_all_caches
  nil
end

.http_debug(http_debug_bool) ⇒ type

Enable or disable http debugging

Parameters:

  • debug_bool (bool)

    State which http debugging should have

Returns:

  • (type)
    description


223
224
225
# File 'lib/facter.rb', line 223

def http_debug(http_debug_bool)
  Facter::Options[:http_debug] = http_debug_bool
end

.http_debug?bool

Check whether http debugging is enabled

Returns:

  • (bool)


213
214
215
# File 'lib/facter.rb', line 213

def http_debug?
  Options[:http_debug]
end

.listArray

Returns a list with the names of all resolved facts

Returns:

  • (Array)

    the list with all the fact names



487
488
489
# File 'lib/facter.rb', line 487

def list
  to_hash.keys.sort
end

.load_external(enable_external) ⇒ Object

Enables/Disables external facts.

Parameters:

  • enable_external (boolean)

    @return nil



315
316
317
318
319
320
321
322
323
324
325
326
327
# File 'lib/facter.rb', line 315

def load_external(enable_external)
  # enable_external param needs negation because behind the scene
  # no_external_facts= method is negating the parameter again.
  Options[:no_external_facts] = !enable_external

  if enable_external
    logger.debug('Facter.load_external(true) called. External facts will be loaded')
  else
    logger.debug('Facter.load_external(false) called. External facts will NOT be loaded')
  end

  nil
end

.loadfactsnil

Loads all facts

Returns:

  • (nil)


304
305
306
307
# File 'lib/facter.rb', line 304

def loadfacts
  LegacyFacter.loadfacts
  nil
end

.log_exception(exception, message = nil) ⇒ nil

Logs an exception and an optional message

Returns:

  • (nil)


473
474
475
476
477
478
479
480
481
# File 'lib/facter.rb', line 473

def log_exception(exception, message = nil)
  error_message = []

  error_message << message.to_s unless message.nil? || (message.is_a?(String) && message.empty?)

  parse_exception(exception, error_message)
  logger.error(error_message.flatten.join("\n"))
  nil
end

.on_message(&block) ⇒ nil

Stores a proc that will be used to output custom messages.

The proc must receive one parameter that will be the message to log.

Parameters:

  • block (Proc)

    a block defining messages handler

Returns:

  • (nil)


184
185
186
187
# File 'lib/facter.rb', line 184

def on_message(&block)
  Facter::Log.on_message(&block)
  nil
end

.puppet_factsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Method used by cli to set puppet paths in order to retrieve puppet custom and external facts

Returns:

  • nil



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/facter.rb', line 54

def puppet_facts
  require 'puppet'

  # don't allow puppet logger to be injected in Facter
  Options[:allow_external_loggers] = false

  Puppet.initialize_settings
  $LOAD_PATH << Puppet[:libdir] unless $LOAD_PATH.include?(Puppet[:libdir])
  Facter.reset
  Facter.search_external([Puppet[:pluginfactdest]])
  if Puppet.respond_to? :initialize_facts
    Puppet.initialize_facts
  else
    Facter.add(:puppetversion) do
      setcode { Puppet.version.to_s }
    end
  end
rescue LoadError => e
  logger.error("Could not load puppet gem, got #{e}")
end

.resetnil

Reset search paths for custom and external facts If config file is set custom and external facts will be reloaded

Returns:

  • (nil)


279
280
281
282
283
284
285
# File 'lib/facter.rb', line 279

def reset
  LegacyFacter.reset
  Options[:custom_dir] = []
  Options[:external_dir] = []
  SessionCache.invalidate_all_caches
  nil
end

.resolve(args_as_string) ⇒ Hash<String, Object>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Method used by puppet-agent to retrieve facts

Parameters:

  • args_as_string (string)

    facter cli arguments

Returns:

  • (Hash<String, Object>)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/facter.rb', line 24

def resolve(args_as_string)
  require_relative 'facter/framework/cli/cli_launcher'

  args = args_as_string.split(' ')
  Facter::OptionsValidator.validate(args)
  processed_arguments = CliLauncher.prepare_arguments(args, nil)
  cli = Facter::Cli.new([], processed_arguments)
  cli_options = cli.options.dup

  # config file options
  config_file = cli_options.delete(:config)
  if config_file
    Facter::OptionStore.set(:config, config_file)
    Facter::ConfigFileOptions.init(config_file)
    Facter::Options.store(ConfigFileOptions.get)
  end

  # user provided options
  cli_options[:show_legacy] ||= false
  Facter::Options.store(cli_options)

  Hash[queried_facts(cli.args)]
end

.search(*dirs) ⇒ nil

Register directories to be searched for custom facts. The registered directories

must be absolute paths or they will be ignored.

Parameters:

  • dirs (Array<String>)

    An array of searched directories

Returns:

  • (nil)


336
337
338
339
# File 'lib/facter.rb', line 336

def search(*dirs)
  Options[:custom_dir] += dirs
  nil
end

.search_external(dirs) ⇒ nil

Registers directories to be searched for external facts.

Parameters:

  • dirs (Array<String>)

    An array of searched directories

Returns:

  • (nil)


347
348
349
350
# File 'lib/facter.rb', line 347

def search_external(dirs)
  Options[:external_dir] += dirs
  nil
end

.search_external_pathArray<String>

Returns the registered search directories.for external facts.

Returns:

  • (Array<String>)

    An array of searched directories



357
358
359
# File 'lib/facter.rb', line 357

def search_external_path
  Options.external_dir
end

.search_pathArray<String>

Returns the registered search directories for custom facts.

Returns:

  • (Array<String>)

    An array of the directories searched



366
367
368
# File 'lib/facter.rb', line 366

def search_path
  Options.custom_dir
end

.sequential?bool

Check if facts are resolved sequentially or not

Returns:

  • (bool)


250
251
252
# File 'lib/facter.rb', line 250

def sequential?
  Facter::Options[:sequential]
end

.to_hashHash<String, Object>

Retrieves a fact’s value. Returns ‘nil` if no such fact exists.

Parameters:

  • user_query (String)

    the fact name

Returns:

  • (Hash<String, Object>)


376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
# File 'lib/facter.rb', line 376

def to_hash
  log_blocked_facts
  logger.debug("Facter version: #{Facter::VERSION}")

  resolved_facts = Facter::FactManager.instance.resolve_facts
  resolved_facts.reject! { |fact| fact.type == :custom && fact.value.nil? }
  collection = Facter::FactCollection.new.build_fact_collection!(resolved_facts)

  # Ensures order of keys in hash returned from Facter.to_hash() and
  # Facter.resolve() is always stable
  if collection.empty?
    Hash[collection]
  else
    Hash[Facter::Utils.sort_hash_by_key(collection)]
  end
end

.to_user_output(cli_options, *args) ⇒ Array

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Gets a hash mapping fact names to their values

Returns:

  • (Array)

    the hash of fact names and values



456
457
458
459
460
461
462
463
464
465
466
# File 'lib/facter.rb', line 456

def to_user_output(cli_options, *args)
  init_cli_options(cli_options)
  logger.info("executed with command line: #{ARGV.drop(1).join(' ')}")
  logger.debug("Facter version: #{Facter::VERSION}")
  log_blocked_facts
  resolved_facts = resolve_facts_for_user_query(args)
  fact_formatter = Facter::FormatterFactory.build(Facter::Options.get)
  status = error_check(resolved_facts)

  [fact_formatter.format(resolved_facts), status]
end

.trace(bool) ⇒ bool

Enable or disable trace

Parameters:

  • bool (bool)

    Set trace on debug state

Returns:

  • (bool)

    Value of trace debug state



408
409
410
# File 'lib/facter.rb', line 408

def trace(bool)
  Options[:trace] = bool
end

.trace?bool

Check whether printing stack trace is enabled

Returns:

  • (bool)


398
399
400
# File 'lib/facter.rb', line 398

def trace?
  Options[:trace]
end

.value(user_query) ⇒ String

Gets the value for a fact. Returns ‘nil` if no such fact exists.

Parameters:

  • user_query (String)

    the fact name

Returns:

  • (String)

    the value of the fact, or nil if no fact is found



418
419
420
421
422
423
# File 'lib/facter.rb', line 418

def value(user_query)
  user_query = user_query.to_s.downcase
  resolve_fact(user_query) unless @already_searched.include?(user_query)

  @already_searched[user_query]&.value
end

.versionString

Returns Facter version

Returns:

  • (String)

    Current version



447
448
449
# File 'lib/facter.rb', line 447

def version
  Facter::VERSION
end

.warn(message) ⇒ nil

Logs the message parameter as a warning.

Parameters:

  • message (Object)

    the warning object to be displayed

Returns:

  • (nil)


497
498
499
500
# File 'lib/facter.rb', line 497

def warn(message)
  logger.warn(message.to_s)
  nil
end

.warnonce(message) ⇒ nil

Logs only once the same warning message.

Parameters:

  • message (Object)

    the warning message object

Returns:

  • (nil)


508
509
510
511
# File 'lib/facter.rb', line 508

def warnonce(message)
  logger.warnonce(message)
  nil
end