Jira (FACT-2998) Facter breaks when querying for custom facts

22 views
Skip to first unread message

Gheorghe Popescu (Jira)

unread,
Mar 26, 2021, 9:13:04 AM3/26/21
to puppe...@googlegroups.com
Gheorghe Popescu updated an issue
 
Facter / Bug FACT-2998
Facter breaks when querying for custom facts
Change By: Gheorghe Popescu
Summary: CLI Facter breaks when querying for custom facts
Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.5.2#805002-sha1:a66f935)
Atlassian logo

Gheorghe Popescu (Jira)

unread,
Mar 26, 2021, 9:14:03 AM3/26/21
to puppe...@googlegroups.com
Gheorghe Popescu updated an issue
When you query for a custom structured fact, Facter uses Hash#dig to cicle through keys, but this can fail if the value of one of the cicled keys is not a Hash.

Simple ruby example:

{code:ruby}
❯ ruby -e '{"a" => "b"}.dig("a", "z")'
Traceback (most recent call last):
1: from -e:1:in `<main>'
-e:1:in `dig': String does not have #dig method (TypeError)
{code}

Steps to reproduce in Facter:
1. create a custom fact

{code:ruby}
Facter.add('foo.bar') do
  setcode { 'baz' }
end
{code}

Query for that fact name and an extra key:

{code:ruby}
❯ bx facter foo.bar.x

facter-4.0.52/lib/facter/framework/formatters/formatter_helper.rb:28:in `dig': String does not have #dig method (TypeError)
{code}

Same for Facter.value

{code:ruby}
2.7.2 :001 > require 'facter'
2.7.2 :003 > Facter.value('foo.bar.x')
facter-4.0.52/lib/facter/models/fact_collection.rb:22:in `block in value'
NoMethodError (undefined method `fetch' for "baz":String)
{code}



Gheorghe Popescu (Jira)

unread,
Mar 26, 2021, 9:17:03 AM3/26/21
to puppe...@googlegroups.com
Another thing is that for core facts, Facter ignores parts of the query, if it is partial matched:



{code:ruby}
❯ bx facter os.family.xyz
Darwin

2.7.2 :006 > Facter.value('os.family.a.b')
=> "Darwin"
{code}

Gheorghe Popescu (Jira)

unread,
Mar 26, 2021, 9:17:07 AM3/26/21
to puppe...@googlegroups.com

Gheorghe Popescu (Jira)

unread,
Mar 26, 2021, 9:28:04 AM3/26/21
to puppe...@googlegroups.com
Another thing is that even for core facts, Facter ignores parts of the query, if it is partial matched:




{code:ruby}
❯ bx facter os.family.xyz
Darwin

2.7.2 :006 > Facter.value('os.family.a.b')
=> "Darwin"
{code}

Mihai Buzgau (Jira)

unread,
Mar 31, 2021, 4:57:03 AM3/31/21
to puppe...@googlegroups.com

Mihai Buzgau (Jira)

unread,
Mar 31, 2021, 4:57:03 AM3/31/21
to puppe...@googlegroups.com
Mihai Buzgau updated an issue
Change By: Mihai Buzgau
Sprint: NW - 2021-04-14

Gabriel Nagy (Jira)

unread,
Mar 31, 2021, 9:49:04 AM3/31/21
to puppe...@googlegroups.com
Gabriel Nagy assigned an issue to Gabriel Nagy
Change By: Gabriel Nagy
Assignee: Gabriel Nagy

Josh Cooper (Jira)

unread,
Mar 31, 2021, 7:47:04 PM3/31/21
to puppe...@googlegroups.com
Josh Cooper updated an issue
Change By: Josh Cooper
Fix Version/s: FACT 4.0.53

Claire Cadman (Jira)

unread,
Apr 13, 2021, 9:21:04 AM4/13/21
to puppe...@googlegroups.com
Claire Cadman updated an issue
Change By: Claire Cadman
Labels: doc_reviewed
This message was sent by Atlassian Jira (v8.13.2#813002-sha1:c495a97)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages