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?

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

  • 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 5 '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 tickets.puppetlabs.com/browse/PUP-406 and tickets.puppetlabs.com/browse/PUP-2966 – faker Oct 5 '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: https://docs.puppetlabs.com/puppet/latest/reference/lang_datatypes.html#indexing-1

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

notice( $myhash[os][release][major] )
  • 1
    That is what I thought, but it is coming back empty :-/ – chriscowley Oct 5 '14 at 10:09
  • // , Has anyone gotten this one to work? – Nathan Basanese Apr 24 '17 at 22:16
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.