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/disk.rb,
lib/facter/resolvers/lpar.rb,
lib/facter/resolvers/path.rb,
lib/facter/resolvers/ruby.rb,
lib/facter/resolvers/wpar.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/macosx/processor.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/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/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.2.0'
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:



84
85
86
# File 'lib/facter.rb', line 84

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



99
100
101
102
103
# File 'lib/facter.rb', line 99

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)


110
111
112
113
114
115
116
117
118
119
120
# File 'lib/facter.rb', line 110

def clear
  @already_searched = {}
  @debug_once = []
  @warn_once = []
  LegacyFacter.clear
  Options[:custom_dir] = []
  LegacyFacter.collection.invalidate_custom_facts
  LegacyFacter.collection.reload_custom_facts
  SessionCache.invalidate_all_caches
  nil
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:



128
129
130
131
132
133
134
# File 'lib/facter.rb', line 128

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)


142
143
144
145
146
147
# File 'lib/facter.rb', line 142

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


206
207
208
# File 'lib/facter.rb', line 206

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

.debugging?bool

Check whether debugging is enabled

Returns:

  • (bool)


196
197
198
# File 'lib/facter.rb', line 196

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)


155
156
157
158
159
160
161
162
163
164
# File 'lib/facter.rb', line 155

def debugonce(message)
  return unless debugging?

  message_string = message.to_s
  return if @debug_once.include? message_string

  @debug_once << message_string
  logger.debug(message_string)
  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:



174
175
176
177
# File 'lib/facter.rb', line 174

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)


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

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:



245
246
247
248
249
250
251
252
253
254
# File 'lib/facter.rb', line 245

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)


215
216
217
# File 'lib/facter.rb', line 215

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:



411
412
413
414
415
416
# File 'lib/facter.rb', line 411

def fact(user_query)
  user_query = user_query.to_s
  resolve_fact(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.



276
277
278
279
280
# File 'lib/facter.rb', line 276

def flush
  LegacyFacter.flush
  SessionCache.invalidate_all_caches
  nil
end

.listArray

Returns a list with the names of all resolved facts

Returns:

  • (Array)

    the list with all the fact names



463
464
465
# File 'lib/facter.rb', line 463

def list
  to_hash.keys.sort
end

.load_external(enable_external) ⇒ Object

Enables/Disables external facts.

Parameters:

  • enable_external (boolean)

    @return nil



298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/facter.rb', line 298

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)


287
288
289
290
# File 'lib/facter.rb', line 287

def loadfacts
  LegacyFacter.loadfacts
  nil
end

.log_exception(exception, message = nil) ⇒ nil

Logs an exception and an optional message

Returns:

  • (nil)


449
450
451
452
453
454
455
456
457
# File 'lib/facter.rb', line 449

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)


186
187
188
189
# File 'lib/facter.rb', line 186

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



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

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)


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

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

.resolve(args_as_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:

  • query result



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

def resolve(args_as_string)
  require '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)

  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)


319
320
321
322
# File 'lib/facter.rb', line 319

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)


330
331
332
333
# File 'lib/facter.rb', line 330

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



340
341
342
# File 'lib/facter.rb', line 340

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



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

def search_path
  Options.custom_dir
end

.sequential?bool

Check if facts are resolved sequentially or not

Returns:

  • (bool)


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

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

.to_hashString

Retrieves a fact’s value. 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



359
360
361
362
363
364
365
366
367
# File 'lib/facter.rb', line 359

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)
  Hash[collection]
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



432
433
434
435
436
437
438
439
440
441
442
# File 'lib/facter.rb', line 432

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



384
385
386
# File 'lib/facter.rb', line 384

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

.trace?bool

Check whether printing stack trace is enabled

Returns:

  • (bool)


374
375
376
# File 'lib/facter.rb', line 374

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



394
395
396
397
398
399
# File 'lib/facter.rb', line 394

def value(user_query)
  user_query = user_query.to_s
  resolve_fact(user_query)

  @already_searched[user_query]&.value
end

.versionString

Returns Facter version

Returns:

  • (String)

    Current version



423
424
425
# File 'lib/facter.rb', line 423

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)


473
474
475
476
# File 'lib/facter.rb', line 473

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)


484
485
486
487
488
489
490
491
# File 'lib/facter.rb', line 484

def warnonce(message)
  message_string = message.to_s
  return if @warn_once.include? message_string

  @warn_once << message_string
  logger.warn(message_string)
  nil
end