# file: module/lib/facter/custom_fact.rb
Facter.add("test_fact") do
setcode do
Facter.value(:my_structured_fact::key::key). # This doesn't work
end
end
How can I reference nested levels of structured fact?
On
You can avoid undef errors with, if you know that my_structured_fact is always a Hash (also known in other programming languages as map or dict)
Facter.value('my_structured_fact').dig('key', 'key')
dig(key, ...) → objectclickto toggle source Retrieves the value object corresponding to the each key objects repeatedly. more aboutdig
I have also heard synonyms for a structured fact:
Hash value
Get the structured fact, then use Ruby to access the hash keys/values.