4

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?

chriscowley
  • 523
  • 4
  • 17

3 Answers3

6

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).

faker
  • 17,326
  • 2
  • 60
  • 69
  • That is not a sustainable option though. That option will be depreciated in Puppet 4, so how is it proposed to deal with that then? – chriscowley Oct 05 '14 at 10:08
  • It's my understanding that it will be deprecated in Puppet 4 because the new default will be false then. See https://tickets.puppetlabs.com/browse/PUP-406 and https://tickets.puppetlabs.com/browse/PUP-2966 – faker Oct 05 '14 at 10:15
  • 1
    `Error: Could not retrieve catalog from remote server: Error 400 on SERVER: ::os is not a hash or array when accessing it with name at /etc/puppet/environments/` – 030 Apr 17 '16 at 17:59
  • @Alfred: still works for me with latest Puppet 4.x version. Again, stringify_facts = false is the important part here. If it still doesn't work I'd suggest asking a new question with more details. – faker Apr 17 '16 at 18:25
2

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] )
рüффп
  • 620
  • 1
  • 11
  • 24
Ruslan
  • 349
  • 1
  • 4
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
Jakov Sosic
  • 5,157
  • 3
  • 22
  • 33