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?

3 Answers 3

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

4
  • 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? Oct 5, 2014 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, 2014 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, 2016 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, 2016 at 18:25
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
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] )
2
  • 1
    That is what I thought, but it is coming back empty :-/ Oct 5, 2014 at 10:09
  • // , Has anyone gotten this one to work? Apr 24, 2017 at 22:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .