Access arrays/hashes in facter 2 facts

In facter 2 you can now have arrays/hashes as facts.

For example:

os => {
  "name"=>"CentOS",
  "family"=>"RedHat",
  "release"=>{
    "major"=>"7",
    "minor"=>"0",
    "full"=>"7.0.1406"
  }
}

What is the format to access os=>release=>major from a manifest?


Solution 1:

For example like this:

notify { $::os[release][major] : }

Note that you need to set the option stringify_facts to false for this to work (default as of writing with Puppet 3.7.1: true).

Solution 2:

You can access facts from manifests by using hashes, like this:

notify { $::os['release']['major']: }

Example:

# puppet apply -e 'notify { $::os['release']['major']: }'
Notice: Compiled catalog for mon.adriatic.local in environment production in 0.04 seconds
Notice: 6
Notice: /Stage[main]/Main/Notify[6]/message: defined 'message' as '6'
Notice: Applied catalog in 0.28 seconds

Solution 3:

Should be possible access it as usual hash datatype.

Example:

$myhash = {os => {
  "name"=>"CentOS",
  "family"=>"RedHat",
  "release"=>{
    "major"=>"7",
    "minor"=>"0",
    "full"=>"7.0.1406"
  }
 }
}

notice( $myhash[os][release][major] )