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/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/cloud.rb,
lib/facter/resolvers/lspci.rb,
lib/facter/resolvers/uname.rb,
lib/facter/resolvers/zpool.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/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/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/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/macosx/processor.rb,
lib/facter/resolvers/networking_linux.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/facts/virtual_detector.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/framework/core/fact_augmenter.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/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, FactAugmenter, 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.0.51'
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:



75
76
77
# File 'lib/facter.rb', line 75

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



90
91
92
93
94
# File 'lib/facter.rb', line 90

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)


101
102
103
104
105
106
107
108
109
110
111
# File 'lib/facter.rb', line 101

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.

Gets the value for a core fact, external or custom facts are

not returned with this call. Returns `nil` if no such fact exists.

Returns:



119
120
121
122
123
124
125
# File 'lib/facter.rb', line 119

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)


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

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


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

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

.debugging?bool

Check whether debugging is enabled

Returns:

  • (bool)


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

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)


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

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:



165
166
167
168
# File 'lib/facter.rb', line 165

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

.disable_sequentialObject



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

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:



221
222
223
224
225
226
227
228
229
230
# File 'lib/facter.rb', line 221

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_sequentialObject



201
202
203
# File 'lib/facter.rb', line 201

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:



242
243
244
245
246
247
# File 'lib/facter.rb', line 242

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.



269
270
271
272
273
# File 'lib/facter.rb', line 269

def flush
  LegacyFacter.flush
  SessionCache.invalidate_all_caches
  nil
end

.listArray

Returns a list with the names of all solved facts

Returns:

  • (Array)

    the list with all the fact names



461
462
463
# File 'lib/facter.rb', line 461

def list
  to_hash.keys.sort
end

.load_external(enable_external) ⇒ Object

Enables/Disables external facts.

Parameters:

  • enable_external (boolean)

    @return nil



291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/facter.rb', line 291

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)


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

def loadfacts
  LegacyFacter.loadfacts
  nil
end

.log_exception(exception, message = nil) ⇒ nil

Logs an exception and an optional message

Returns:

  • (nil)


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

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)


177
178
179
180
# File 'lib/facter.rb', line 177

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

.puppet_factsObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/facter.rb', line 47

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)


255
256
257
258
259
260
261
# File 'lib/facter.rb', line 255

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
# 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)

  if cli.args.include?(:version)
    cli.invoke(:version, [])
  elsif cli.args.include?('--list-cache-groups')
    cli.invoke(:list_cache_groups, [])
  elsif cli.args.include?('--list-block-groups')
    cli.invoke(:list_block_groups, [])
  else
    cli.invoke(:arg_parser)
  end
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)


312
313
314
315
# File 'lib/facter.rb', line 312

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)


323
324
325
326
# File 'lib/facter.rb', line 323

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



333
334
335
# File 'lib/facter.rb', line 333

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



342
343
344
# File 'lib/facter.rb', line 342

def search_path
  Options.custom_dir
end

.sequential?Boolean

Returns:

  • (Boolean)


209
210
211
# File 'lib/facter.rb', line 209

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

.to_hashFactCollection

Gets a hash mapping fact names to their values The hash contains core facts, legacy facts, custom facts and external facts (all facts that can be resolved).

Returns:



352
353
354
355
356
357
358
359
360
# File 'lib/facter.rb', line 352

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



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

def to_user_output(cli_options, *args)
  init_cli_options(cli_options, args)
  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



377
378
379
# File 'lib/facter.rb', line 377

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

.trace?bool

Check whether printing stack trace is enabled

Returns:

  • (bool)


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

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



387
388
389
390
391
# File 'lib/facter.rb', line 387

def value(user_query)
  user_query = user_query.to_s
  resolve_fact(user_query)
  @already_searched[user_query]&.value
end

.values(options, user_queries) ⇒ FactCollection

Gets the values for multiple facts.

Parameters:

Returns:



403
404
405
406
407
408
409
410
411
412
413
414
# File 'lib/facter.rb', line 403

def values(options, user_queries)
  init_cli_options(options, user_queries)
  log_blocked_facts
  resolved_facts = Facter::FactManager.instance.resolve_facts(user_queries)
  resolved_facts.reject! { |fact| fact.type == :custom && fact.value.nil? }

  if user_queries.count.zero?
    Facter::FactCollection.new.build_fact_collection!(resolved_facts)
  else
    FormatterHelper.retrieve_facts_to_display_for_user_query(user_queries, resolved_facts)
  end
end

.versionString

Returns Facter version

Returns:

  • (String)

    Current version



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

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)


471
472
473
474
# File 'lib/facter.rb', line 471

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)


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

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