Extract nested hash facts from puppet’s facter command-line tool. How

facterpuppet

This might be obvious. However, after searching through facter's help, puppetlab's website, and Google I am still unable to figure out how to retrieve a nested facter fact .

For example, I can do:

>facter os

{"release"=>{"major"=>"6", "minor"=>"7", "full"=>"6.7"}, "family"=>"RedHat", "name"=>"CentOS"}

How do I retrieve os['name'] or os['release']['minor'] or any arbitrary nested fact via command line with facter?

Best Answer

Nested fact values can be viewed in the CLI by using a dot between variables

e.g. to retrieve os['release']['minor'] in the CLI type: facter os.release.minor

EDIT: Apperently this only works with facter 3.x.

This doc gives a brief mention on how to access these structured (aka nested) facts (http://docs.puppetlabs.com/facter/3.1/core_facts.html):

Legacy Facts Note: As of Facter 3, legacy facts such as architecture are hidden by default to reduce noise in Facter’s default command-line output. These older facts are now part of more useful structured facts; for example, architecture is now part of the os fact and accessible as os.architecture. You can still use these legacy facts in Puppet manifests ($architecture), request them on the command line (facter architecture), and view them alongside structured facts (facter --show-legacy).

Unfortunately I cannot find information about accessing nested facts using older versions.

In facter v3 you can do the following:

facter os
{
  architecture => "amd64",
  distro => {
    codename => "trusty",
    description => "Ubuntu 14.04.3 LTS",
    id => "Ubuntu",
    release => {
      full => "14.04",
      major => "14.04"
    }
  },
  family => "Debian",
  hardware => "x86_64",
  name => "Ubuntu",
  release => {
    full => "14.04",
    major => "14.04"
  },
  selinux => {
    enabled => false
  }
}

.

facter os.release
{
  full => "14.04",
  major => "14.04"
}

.

facter os.release.major
14.04