Module: Facter

Defined in:
lib/util/fact.rb,
lib/facter.rb,
lib/framework/cli/cli.rb,
lib/models/loaded_fact.rb,
lib/resolvers/utils/ssh.rb,
lib/models/resolved_fact.rb,
lib/models/searched_fact.rb,
lib/framework/utils/utils.rb,
lib/framework/core/options.rb,
lib/models/fact_collection.rb,
lib/resolvers/dmi_resolver.rb,
lib/resolvers/ssh_resolver.rb,
lib/resolvers/base_resolver.rb,
lib/resolvers/disk_resolver.rb,
lib/resolvers/lpar_resolver.rb,
lib/resolvers/path_resolver.rb,
lib/resolvers/ruby_resolver.rb,
lib/resolvers/wpar_resolver.rb,
lib/framework/logging/logger.rb,
lib/resolvers/agent_resolver.rb,
lib/resolvers/uname_resolver.rb,
lib/facts_utils/uptime_parser.rb,
lib/resolvers/augeas_resolver.rb,
lib/resolvers/memory_resolver.rb,
lib/resolvers/uptime_resolver.rb,
lib/framework/core/fact_filter.rb,
lib/resolvers/selinux_resolver.rb,
lib/resolvers/sw_vers_resolver.rb,
lib/custom_facts/core/execution.rb,
lib/facts_utils/bytes_converter.rb,
lib/framework/config/block_list.rb,
lib/framework/core/fact_manager.rb,
lib/resolvers/hostname_resolver.rb,
lib/resolvers/identity_resolver.rb,
lib/resolvers/os_level_resolver.rb,
lib/resolvers/timezone_resolver.rb,
lib/resolvers/utils/fingerprint.rb,
lib/custom_facts/util/resolution.rb,
lib/framework/core/cache_manager.rb,
lib/resolvers/aix/ffi/ffi_helper.rb,
lib/framework/core/fact_augmenter.rb,
lib/framework/logging/multilogger.rb,
lib/resolvers/aix/utils/odm_query.rb,
lib/resolvers/macosx/dmi_resolver.rb,
lib/resolvers/os_release_resolver.rb,
lib/resolvers/processors_resolver.rb,
lib/framework/config/config_reader.rb,
lib/framework/parsers/query_parser.rb,
lib/resolvers/eos_release_resolver.rb,
lib/resolvers/filesystems_resolver.rb,
lib/resolvers/lsb_release_resolver.rb,
lib/resolvers/mountpoints_resolver.rb,
lib/resolvers/solaris/zfs_resolver.rb,
lib/resolvers/aix/hardware_resolver.rb,
lib/resolvers/aix/os_level_resolver.rb,
lib/resolvers/fips_enabled_resolver.rb,
lib/resolvers/solaris/zone_resolver.rb,
lib/resolvers/suse_release_resolver.rb,
lib/resolvers/windows/fips_resolver.rb,
lib/resolvers/facterversion_resolver.rb,
lib/resolvers/load_averages_resolver.rb,
lib/resolvers/solaris/zpool_resolver.rb,
lib/resolvers/aix/filesystem_resolver.rb,
lib/resolvers/aix/networking_resolver.rb,
lib/resolvers/debian_version_resolver.rb,
lib/resolvers/puppet_version_resolver.rb,
lib/resolvers/redhat_release_resolver.rb,
lib/resolvers/utils/filesystem_helper.rb,
lib/resolvers/windows/kernel_resolver.rb,
lib/resolvers/windows/memory_resolver.rb,
lib/resolvers/windows/netkvm_resolver.rb,
lib/resolvers/windows/uptime_resolver.rb,
lib/facts_utils/windows_release_finder.rb,
lib/facts_utils/bytes_to_human_readable.rb,
lib/resolvers/aix/architecture_resolver.rb,
lib/resolvers/macosx/ipaddress_resolver.rb,
lib/resolvers/macosx/processor_resolver.rb,
lib/resolvers/networking_linux_resolver.rb,
lib/resolvers/solaris/solaris_zone_name.rb,
lib/resolvers/windows/dmi_bios_resolver.rb,
lib/resolvers/windows/identity_resolver.rb,
lib/resolvers/windows/system32_resolver.rb,
lib/resolvers/aix/load_averages_resolver.rb,
lib/resolvers/solaris/ipaddress_resolver.rb,
lib/framework/core/options/helper_options.rb,
lib/framework/formatters/formatter_helper.rb,
lib/resolvers/macosx/filesystems_resolver.rb,
lib/resolvers/macosx/mountpoints_resolver.rb,
lib/resolvers/macosx/swap_memory_resolver.rb,
lib/resolvers/windows/networking_resolver.rb,
lib/resolvers/windows/processors_resolver.rb,
lib/framework/core/fact/internal/core_fact.rb,
lib/framework/core/options/default_options.rb,
lib/framework/formatters/formatter_factory.rb,
lib/resolvers/solaris/filesystems_resolver.rb,
lib/framework/core/fact_loaders/fact_loader.rb,
lib/framework/core/options/priority_options.rb,
lib/framework/core/options/validate_options.rb,
lib/resolvers/macosx/load_averages_resolver.rb,
lib/resolvers/macosx/system_memory_resolver.rb,
lib/framework/core/options/options_validator.rb,
lib/framework/formatters/json_fact_formatter.rb,
lib/framework/formatters/yaml_fact_formatter.rb,
lib/framework/formatters/hocon_fact_formatter.rb,
lib/resolvers/macosx/system_profiler_resolver.rb,
lib/resolvers/windows/virtualization_resolver.rb,
lib/framework/core/options/config_file_options.rb,
lib/framework/formatters/legacy_fact_formatter.rb,
lib/resolvers/windows/product_release_resolver.rb,
lib/framework/core/fact_loaders/class_discoverer.rb,
lib/resolvers/solaris/solaris_os_release_resolver.rb,
lib/resolvers/windows/dmi_computersystem_resolver.rb,
lib/resolvers/windows/win_os_description_resolver.rb,
lib/framework/core/fact_loaders/external_fact_loader.rb,
lib/framework/core/fact_loaders/internal_fact_loader.rb,
lib/resolvers/windows/hardware_architecture_resolver.rb,
lib/framework/core/fact/external/external_fact_manager.rb,
lib/framework/core/fact/internal/internal_fact_manager.rb

Overview

CuAt (Customized Attributes) non-default attribute values CuDv (Customized Devices) the devices present on this machine PdAt (Predefined Attributes) default values for all device attributes PdDv (Predefined Devices) the list of all devices supported by this release of AIX

Defined Under Namespace

Modules: Aix, ConfigFileOptions, Core, DefaultOptions, FactAugmenter, FactsUtils, FilesystemHelper, HelperOptions, OptionsValidator, PriorityOptions, Resolvers, Util, Utils, ValidateOptions Classes: BlockList, BytesToHumanReadable, CacheManager, ClassDiscoverer, Cli, ConfigReader, CoreFact, ExternalFactLoader, ExternalFactManager, FactCollection, FactFilter, FactLoader, FactManager, FingerPrint, FormatterFactory, FormatterHelper, HoconFactFormatter, InternalFactLoader, InternalFactManager, JsonFactFormatter, LegacyFactFormatter, LoadedFact, Log, MultiLogger, ODMQuery, Options, QueryParser, ResolveCustomFactError, ResolvedFact, SearchedFact, Ssh, UptimeParser, WindowsReleaseFinder, YamlFactFormatter

Constant Summary collapse

RED =
31

Class Method Summary collapse

Class Method Details

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

Alias method for Facter.fact()

Parameters:

  • name (string)

    fact name

Returns:



30
31
32
# File 'lib/facter.rb', line 30

def [](name)
  fact(name)
end

.add(name, options = {}, &block) ⇒ LegacyFacter::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:



45
46
47
48
49
# File 'lib/facter.rb', line 45

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)


56
57
58
59
60
61
# File 'lib/facter.rb', line 56

def clear
  @already_searched = {}
  LegacyFacter.clear
  LegacyFacter.collection.invalidate_custom_facts
  LegacyFacter.collection.reload_custom_facts
end

.clear_messagesObject



19
20
21
# File 'lib/facter.rb', line 19

def clear_messages
  @logger.debug('clear_messages is not implemented')
end

.core_value(user_query) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/facter.rb', line 63

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(msg) ⇒ nil

Prints out a debug message when debug option is set to true

Parameters:

  • msg (String)

    Message to be printed out

Returns:

  • (nil)


77
78
79
80
81
82
# File 'lib/facter.rb', line 77

def debug(msg)
  return unless debugging?

  @logger.debug(msg)
  nil
end

.debugging(debug_bool) ⇒ type

Enable or disable debugging

Parameters:

  • debug_bool (bool)

    State which debugging should have

Returns:

  • (type)
    description


103
104
105
106
107
108
# File 'lib/facter.rb', line 103

def debugging(debug_bool)
  @options.priority_options[:debug] = debug_bool
  @options.refresh

  debug_bool
end

.debugging?bool

Check whether debuging is enabled

Returns:

  • (bool)


93
94
95
# File 'lib/facter.rb', line 93

def debugging?
  Options[:debug]
end

.fact(user_query) ⇒ LegacyFacter::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:

  • name (String)

    the name of the fact

Returns:



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

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

  @already_searched[user_query]
end

.on_message(&block) ⇒ Object



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

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

.resetnil

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

Returns:

  • (nil)


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

def reset
  LegacyFacter.reset
  LegacyFacter.search(*Options.custom_dir)
  LegacyFacter.search_external(Options.external_dir)
  nil
end

.search(*dirs) ⇒ void

This method returns an undefined value.

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



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

def search(*dirs)
  LegacyFacter.search(*dirs)
end

.search_external(dirs) ⇒ void

This method returns an undefined value.

Registers directories to be searched for external facts.

Parameters:

  • dirs (Array<String>)

    An array of searched directories



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

def search_external(dirs)
  LegacyFacter.search_external(dirs)
end

.search_external_pathArray<String>

Returns the registered search directories.for external facts.

Returns:

  • (Array<String>)

    An array of searched directories



168
169
170
# File 'lib/facter.rb', line 168

def search_external_path
  LegacyFacter.search_external_path
end

.search_pathArray<String>

Returns the registered search directories for custom facts.

Returns:

  • (Array<String>)

    An array of the directories searched



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

def search_path
  LegacyFacter.search_path
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:



187
188
189
190
191
192
193
194
195
196
# File 'lib/facter.rb', line 187

def to_hash
  @options.priority_options[:to_hash] = true
  @options.refresh

  log_blocked_facts

  resolved_facts = Facter::FactManager.instance.resolve_facts
  CacheManager.invalidate_all_caches
  FactCollection.new.build_fact_collection!(resolved_facts)
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



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

def to_user_output(cli_options, *args)
  @options.priority_options = { is_cli: true }.merge!(cli_options.map { |(k, v)| [k.to_sym, v] }.to_h)
  @options.refresh(args)
  @logger.info("executed with command line: #{ARGV.drop(1).join(' ')}")
  log_blocked_facts

  resolved_facts = Facter::FactManager.instance.resolve_facts(args)
  CacheManager.invalidate_all_caches
  fact_formatter = Facter::FormatterFactory.build(@options)

  status = error_check(args, resolved_facts)

  [fact_formatter.format(resolved_facts), status || 0]
end

.trace(bool) ⇒ type

Enable or disable trace

Parameters:

  • debug_bool (bool)

    Set trace on debug state

Returns:

  • (type)
    description


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

def trace(bool)
  LegacyFacter.trace(bool)
end

.trace?bool

Check whether printing stack trace is enabled

Returns:

  • (bool)


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

def trace?
  LegacyFacter.trace?
end

.value(user_query) ⇒ String

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

Parameters:

  • name (String)

    the fact name

Returns:

  • (String)

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



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

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



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

def version
  version_file = ::File.join(ROOT_DIR, 'VERSION')
  ::File.read(version_file).strip
end