Ask Your Question

Accessing Facter Facts in "map" type fact

asked 2015-12-15 17:18:01 -0500

wsanders1 gravatar image

updated 2015-12-15 17:21:28 -0500

I can't find this documented anywhere: If I want to access a facter fact that is in one of the map data types instead of the legacy "one word" top level variables, how do I do it? For example, "facter networking": { ... interfaces => { ... eth1 => { mac => "00:25:90:91:33:3b", mtu => 1500 },

How do I, for example, check for the existence of eth1? For starters, none of these evaluate to true, when eth1 exists (and eth1 is itself a map/hash):

if $facts['networking[interfaces[eth1]]'] {       (Evaluates to false)
if $facts['networking.interfaces.eth1'] {        (Evaluates to false)
if $facts['networking:interfaces:eth1'] {        (Evaluates to false)
if $facts['networking::interfaces::eth1'] {        (Evaluates to false)
if $facts[networking[interfaces[eth1]]] {        (Evaluation error)
if $facts[networking[interfaces['eth1']]] {       (Evaluation error)


An effective workaround is "if $interfaces =~ /eth1/" ....

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-12-15 19:31:58 -0500

lavaman gravatar image

You don't typically access facts from a fact array, you just reference them as top-scope variables. In your example, I believe you're looking for $::networking['interfaces']['eth1']

edit flag offensive delete link more


Exactly what I was looking for, thanks.

wsanders1 gravatar imagewsanders1 ( 2015-12-16 11:15:11 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-12-15 17:18:01 -0500

Seen: 662 times

Last updated: Dec 15 '15