Jira (FACT-3067) Facter API does not resolve custom facts that partial match legacy facts

21 views
Skip to first unread message

Gheorghe Popescu (Jira)

unread,
Aug 26, 2021, 2:44:02 AM8/26/21
to puppe...@googlegroups.com
Gheorghe Popescu created an issue
 
Facter / Bug FACT-3067
Facter API does not resolve custom facts that partial match legacy facts
Issue Type: Bug Bug
Assignee: Unassigned
Created: 2021/08/25 11:43 PM
Priority: Normal Normal
Reporter: Gheorghe Popescu

Facter defines a couple of legacy facts using regexes, example networking: https://github.com/puppetlabs/facter/blob/main/lib/facter/facts/macosx/network_interfaces.rb#L6

Adding the following custom_fact:

Facter.add('network_nexthop_ip') do
  setcode do
    'custom_value'
  end
end
{noformat}
*no* further _formatting_ is done here
{noformat}

Will result in the fact being resolved on CLI but not when using Facter.value / Facter.fact

❯ bx facter network_nexthop_ip --custom-dir $custom_dir --debug
[2021-08-26 09:41:40.066702 ] INFO Facter - executed with command line: network_nexthop_ip --custom-dir /Users/gheorghe.popescu/Workspace/custom_facts --debug
[2021-08-26 09:41:40.066788 ] DEBUG Facter - Facter version: 4.2.4
[2021-08-26 09:41:40.068471 ] DEBUG Facter::FactManager - Resolving facts sequentially
[2021-08-26 09:41:40.069033 ] DEBUG Facter::FactLoader - Loading all internal facts
[2021-08-26 09:41:40.069164 ] DEBUG Facter::FactLoader - Loading custom facts
[2021-08-26 09:41:40.077111 ] DEBUG Facter::FactLoader - Loading external facts
[2021-08-26 09:41:40.079167 ] DEBUG Facter::QueryParser - List of resolvable facts: [#<Facter::SearchedFact:0x00007fbfc42e4470 @name="network_.*", @fact_class=Facts::Macosx::NetworkInterfaces, @user_query="network_nexthop_ip", @type=:legacy, @file=nil>, #<Facter::SearchedFact:0x00007fbfc90eabb0 @name="network_nexthop_ip", @fact_class=nil, @user_query="network_nexthop_ip", @type=:custom, @file=nil>]
[2021-08-26 09:41:40.079312 ] DEBUG Facter::Core::Execution::Posix - Executing command: ifconfig -a
[2021-08-26 09:41:40.092197 ] DEBUG Facter::Core::Execution::Posix - Executing command: ipconfig getoption en0 server_identifier
[2021-08-26 09:41:40.100080 ] DEBUG Facter::Core::Execution::Posix - Executing command: ipconfig getoption awdl0 server_identifier
[2021-08-26 09:41:40.107701 ] DEBUG Facter::Core::Execution::Posix - Executing command: ipconfig getoption llw0 server_identifier
[2021-08-26 09:41:40.118377 ] DEBUG Facter::Core::Execution::Posix - Executing command: route -n get default
[2021-08-26 09:41:40.128626 ] DEBUG Facter::Util::Fact - custom fact network_nexthop_ip got resolved from: ["/Users/gheorghe.popescu/Workspace/custom_facts/ipaddress.rb", 25]
[2021-08-26 09:41:40.129107 ] DEBUG Facter::FactLoader - Loading all internal facts
[2021-08-26 09:41:40.130886 ] DEBUG Facter::QueryParser - List of resolvable facts: [#<Facter::SearchedFact:0x00007fbfc40f51c8 @name="network_.*", @fact_class=Facts::Macosx::NetworkInterfaces, @user_query="network_nexthop_ip", @type=:legacy, @file=nil>]
[2021-08-26 09:41:40.131228 ] DEBUG Facter::FactManager - fact "network_lo0" has resolved to: 127.0.0.0
[2021-08-26 09:41:40.131252 ] DEBUG Facter::FactManager - fact "network_en0" has resolved to: 192.168.100.0
[2021-08-26 09:41:40.131264 ] DEBUG Facter::FactManager - fact "network_nexthop_ip" has resolved to: custom_value
[2021-08-26 09:41:40.131390 ] DEBUG Facter::LegacyFactFormatter - Formatting for single user query
custom_value

Facter.value
 
froce_dot: false
4.2.4
 
 
D, [2021-08-26T09:43:09.389815 #44494] DEBUG -- : Facter::FactManager - Resolving facts sequentially
D, [2021-08-26T09:43:09.389872 #44494] DEBUG -- : Facter::FactManager - resolving fact with user_query: network_nexthop_ip
D, [2021-08-26T09:43:09.390443 #44494] DEBUG -- : Facter::FactManager - Searching fact: network_nexthop_ip in file: network_nexthop_ip.rb
D, [2021-08-26T09:43:09.390938 #44494] DEBUG -- : Facter::FactManager - Searching fact: network_nexthop_ip in core facts and external facts
D, [2021-08-26T09:43:09.390965 #44494] DEBUG -- : Facter::FactLoader - Loading all internal facts
D, [2021-08-26T09:43:09.392238 #44494] DEBUG -- : Facter::QueryParser - List of resolvable facts: [#<Facter::SearchedFact:0x00007f8a458d08c0 @name="network_.*", @fact_class=Facts::Macosx::NetworkInterfaces, @user_query="network_nexthop_ip", @type=:legacy, @file=nil>]
D, [2021-08-26T09:43:09.392640 #44494] DEBUG -- : Facter::Core::Execution::Posix - Executing command: ifconfig -a
D, [2021-08-26T09:43:09.403237 #44494] DEBUG -- : Facter::Core::Execution::Posix - Executing command: ipconfig getoption en0 server_identifier
D, [2021-08-26T09:43:09.410192 #44494] DEBUG -- : Facter::Core::Execution::Posix - Executing command: ipconfig getoption awdl0 server_identifier
D, [2021-08-26T09:43:09.416527 #44494] DEBUG -- : Facter::Core::Execution::Posix - Executing command: ipconfig getoption llw0 server_identifier
D, [2021-08-26T09:43:09.424148 #44494] DEBUG -- : Facter::Core::Execution::Posix - Executing command: route -n get default
D, [2021-08-26T09:43:09.432659 #44494] DEBUG -- : Facter::FactLoader - Loading external facts
D, [2021-08-26T09:43:09.437615 #44494] DEBUG -- : Facter::FactManager - fact "network_lo0" has resolved to: 127.0.0.0
D, [2021-08-26T09:43:09.437645 #44494] DEBUG -- : Facter::FactManager - fact "network_en0" has resolved to: 192.168.100.0
network_nexthop_ip ->

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.13.2#813002-sha1:c495a97)
Atlassian logo

Gheorghe Popescu (Jira)

unread,
Aug 26, 2021, 2:45:02 AM8/26/21
to puppe...@googlegroups.com

Gheorghe Popescu (Jira)

unread,
Aug 26, 2021, 2:45:03 AM8/26/21
to puppe...@googlegroups.com
Gheorghe Popescu updated an issue
This works on Facter 3.

Facter
defines a couple of legacy facts using regexes, example networking:  https://github.com/puppetlabs/facter/blob/main/lib/facter/facts/macosx/network_interfaces.rb#L6

Adding the following custom_fact:

{code:ruby}

Facter.add('network_nexthop_ip') do
  setcode do
    'custom_value'
  end
end
{noformat}
*no* further _formatting_ is done here
{noformat}

{code}


Will result in the fact being resolved on CLI but not when using Facter.value / Facter.fact


{noformat}

❯ bx facter network_nexthop_ip --custom-dir $custom_dir --debug
[2021-08-26 09:41:40.066702 ] INFO Facter - executed with command line: network_nexthop_ip --custom-dir /Users/gheorghe.popescu/Workspace/custom_facts --debug
[2021-08-26 09:41:40.066788 ] DEBUG Facter - Facter version: 4.2.4
[2021-08-26 09:41:40.068471 ] DEBUG Facter::FactManager - Resolving facts sequentially
[2021-08-26 09:41:40.069033 ] DEBUG Facter::FactLoader - Loading all internal facts
[2021-08-26 09:41:40.069164 ] DEBUG Facter::FactLoader - Loading custom facts
[2021-08-26 09:41:40.077111 ] DEBUG Facter::FactLoader - Loading external facts
[2021-08-26 09:41:40.079167 ] DEBUG Facter::QueryParser - List of resolvable facts: [#<Facter::SearchedFact:0x00007fbfc42e4470 @name="network_.*", @fact_class=Facts::Macosx::NetworkInterfaces, @user_query="network_nexthop_ip", @type=:legacy, @file=nil>, #<Facter::SearchedFact:0x00007fbfc90eabb0 @name="network_nexthop_ip", @fact_class=nil, @user_query="network_nexthop_ip", @type=:custom, @file=nil>]
[2021-08-26 09:41:40.079312 ] DEBUG Facter::Core::Execution::Posix - Executing command: ifconfig -a
[2021-08-26 09:41:40.092197 ] DEBUG Facter::Core::Execution::Posix - Executing command: ipconfig getoption en0 server_identifier
[2021-08-26 09:41:40.100080 ] DEBUG Facter::Core::Execution::Posix - Executing command: ipconfig getoption awdl0 server_identifier
[2021-08-26 09:41:40.107701 ] DEBUG Facter::Core::Execution::Posix - Executing command: ipconfig getoption llw0 server_identifier
[2021-08-26 09:41:40.118377 ] DEBUG Facter::Core::Execution::Posix - Executing command: route -n get default
[2021-08-26 09:41:40.128626 ] DEBUG Facter::Util::Fact - custom fact network_nexthop_ip got resolved from: ["/Users/gheorghe.popescu/Workspace/custom_facts/ipaddress.rb", 25]
[2021-08-26 09:41:40.129107 ] DEBUG Facter::FactLoader - Loading all internal facts
[2021-08-26 09:41:40.130886 ] DEBUG Facter::QueryParser - List of resolvable facts: [#<Facter::SearchedFact:0x00007fbfc40f51c8 @name="network_.*", @fact_class=Facts::Macosx::NetworkInterfaces, @user_query="network_nexthop_ip", @type=:legacy, @file=nil>]
[2021-08-26 09:41:40.131228 ] DEBUG Facter::FactManager - fact "network_lo0" has resolved to: 127.0.0.0
[2021-08-26 09:41:40.131252 ] DEBUG Facter::FactManager - fact "network_en0" has resolved to: 192.168.100.0
[2021-08-26 09:41:40.131264 ] DEBUG Facter::FactManager - fact "network_nexthop_ip" has resolved to: custom_value
[2021-08-26 09:41:40.131390 ] DEBUG Facter::LegacyFactFormatter - Formatting for single user query
custom_value
{noformat}


{noformat}

Facter.value

froce_dot: false
4.2.4


D, [2021-08-26T09:43:09.389815 #44494] DEBUG -- : Facter::FactManager - Resolving facts sequentially
D, [2021-08-26T09:43:09.389872 #44494] DEBUG -- : Facter::FactManager - resolving fact with user_query: network_nexthop_ip
D, [2021-08-26T09:43:09.390443 #44494] DEBUG -- : Facter::FactManager - Searching fact: network_nexthop_ip in file: network_nexthop_ip.rb
D, [2021-08-26T09:43:09.390938 #44494] DEBUG -- : Facter::FactManager - Searching fact: network_nexthop_ip in core facts and external facts
D, [2021-08-26T09:43:09.390965 #44494] DEBUG -- : Facter::FactLoader - Loading all internal facts
D, [2021-08-26T09:43:09.392238 #44494] DEBUG -- : Facter::QueryParser - List of resolvable facts: [#<Facter::SearchedFact:0x00007f8a458d08c0 @name="network_.*", @fact_class=Facts::Macosx::NetworkInterfaces, @user_query="network_nexthop_ip", @type=:legacy, @file=nil>]
D, [2021-08-26T09:43:09.392640 #44494] DEBUG -- : Facter::Core::Execution::Posix - Executing command: ifconfig -a
D, [2021-08-26T09:43:09.403237 #44494] DEBUG -- : Facter::Core::Execution::Posix - Executing command: ipconfig getoption en0 server_identifier
D, [2021-08-26T09:43:09.410192 #44494] DEBUG -- : Facter::Core::Execution::Posix - Executing command: ipconfig getoption awdl0 server_identifier
D, [2021-08-26T09:43:09.416527 #44494] DEBUG -- : Facter::Core::Execution::Posix - Executing command: ipconfig getoption llw0 server_identifier
D, [2021-08-26T09:43:09.424148 #44494] DEBUG -- : Facter::Core::Execution::Posix - Executing command: route -n get default
D, [2021-08-26T09:43:09.432659 #44494] DEBUG -- : Facter::FactLoader - Loading external facts
D, [2021-08-26T09:43:09.437615 #44494] DEBUG -- : Facter::FactManager - fact "network_lo0" has resolved to: 127.0.0.0
D, [2021-08-26T09:43:09.437645 #44494] DEBUG -- : Facter::FactManager - fact "network_en0" has resolved to: 192.168.100.0
network_nexthop_ip ->

{noformat}



Gheorghe Popescu (Jira)

unread,
Aug 26, 2021, 2:46:03 AM8/26/21
to puppe...@googlegroups.com

Gheorghe Popescu (Jira)

unread,
Aug 26, 2021, 2:46:03 AM8/26/21
to puppe...@googlegroups.com

Ciprian Badescu (Jira)

unread,
Aug 30, 2021, 10:11:02 AM8/30/21
to puppe...@googlegroups.com

Ciprian Badescu (Jira)

unread,
Sep 8, 2021, 5:25:02 AM9/8/21
to puppe...@googlegroups.com

Luchian Nemes (Jira)

unread,
Sep 13, 2021, 7:32:04 AM9/13/21
to puppe...@googlegroups.com

Luchian Nemes (Jira)

unread,
Sep 16, 2021, 10:38:03 AM9/16/21
to puppe...@googlegroups.com
Luchian Nemes updated an issue
Change By: Luchian Nemes
Release Notes: Bug Fix
Release Notes Summary: Before this fix, custom facts with names that partially matched core legacy facts were being resolved as expected in CLI but not using the API. Due to the nature of how legacy facts are defined in Facter 4, with the regular expression used in FACT_NAME, `Facter::FactManager` was not resolving custom facts if core or external facts had any results.

This fix adds a new method to check if the user query matches the name of already resolved facts to decide whether or not custom facts should be also resolved.

Ciprian Badescu (Jira)

unread,
Sep 20, 2021, 8:18:03 AM9/20/21
to puppe...@googlegroups.com

Claire Cadman (Jira)

unread,
Oct 5, 2021, 8:23:03 AM10/5/21
to puppe...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages