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
-
.[](name) ⇒ LegacyFacter::Util::Fact?
Alias method for Facter.fact().
-
.add(name, options = {}, &block) ⇒ LegacyFacter::Util::Fact
Add custom facts to fact collection.
-
.clear ⇒ nil
Clears all cached values and removes all facts from memory.
- .clear_messages ⇒ Object
- .core_value(user_query) ⇒ Object
-
.debug(msg) ⇒ nil
Prints out a debug message when debug option is set to true.
-
.debugging(debug_bool) ⇒ type
Enable or disable debugging.
-
.debugging? ⇒ bool
Check whether debuging is enabled.
-
.fact(user_query) ⇒ LegacyFacter::Util::Fact?
Returns a fact object by name.
- .on_message(&block) ⇒ Object
-
.reset ⇒ nil
Reset search paths for custom and external facts If config file is set custom and external facts will be reloaded.
-
.search(*dirs) ⇒ void
Register directories to be searched for custom facts.
-
.search_external(dirs) ⇒ void
Registers directories to be searched for external facts.
-
.search_external_path ⇒ Array<String>
Returns the registered search directories.for external facts.
-
.search_path ⇒ Array<String>
Returns the registered search directories for custom facts.
-
.to_hash ⇒ FactCollection
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).
-
.to_user_output(cli_options, *args) ⇒ Array
private
Gets a hash mapping fact names to their values.
-
.trace(bool) ⇒ type
Enable or disable trace.
-
.trace? ⇒ bool
Check whether printing stack trace is enabled.
-
.value(user_query) ⇒ String
Gets the value for a fact.
-
.version ⇒ String
Returns Facter version.
Class Method Details
.[](name) ⇒ LegacyFacter::Util::Fact?
Alias method for Facter.fact()
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
45 46 47 48 49 |
# File 'lib/facter.rb', line 45 def add(name, = {}, &block) [:fact_type] = :custom LegacyFacter.add(name, , &block) LegacyFacter.collection.invalidate_custom_facts end |
.clear ⇒ nil
Clears all cached values and removes all facts from memory.
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_messages ⇒ Object
19 20 21 |
# File 'lib/facter.rb', line 19 def @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
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
103 104 105 106 107 108 |
# File 'lib/facter.rb', line 103 def debugging(debug_bool) @options.[:debug] = debug_bool @options.refresh debug_bool end |
.debugging? ⇒ bool
Check whether debuging is enabled
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.
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 (&block) Facter::Log.(&block) end |
.reset ⇒ nil
Reset search paths for custom and external facts If config file is set custom and external facts will be reloaded
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.
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.
159 160 161 |
# File 'lib/facter.rb', line 159 def search_external(dirs) LegacyFacter.search_external(dirs) end |
.search_external_path ⇒ Array<String>
Returns the registered search directories.for external facts.
168 169 170 |
# File 'lib/facter.rb', line 168 def search_external_path LegacyFacter.search_external_path end |
.search_path ⇒ Array<String>
Returns the registered search directories for custom facts.
177 178 179 |
# File 'lib/facter.rb', line 177 def search_path LegacyFacter.search_path end |
.to_hash ⇒ FactCollection
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).
187 188 189 190 191 192 193 194 195 196 |
# File 'lib/facter.rb', line 187 def to_hash @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
244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/facter.rb', line 244 def to_user_output(, *args) @options. = { is_cli: true }.merge!(.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
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
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.
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 |
.version ⇒ String
Returns Facter 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 |