FAQ
Hope I'm not being too thick about this but I'm having trouble creating a
Hash from my server's Facts.

I've tried the following:
facts = File.read( "#{puppetdir}/yaml/facts/#{certname}.yaml" )

factH = YAML.load( facts ) # fails
factH = YAML.load( facts ).to_hash # fails

It looks like the facts file is a yaml of a Puppet::Node::Facts but I can't
figure out how to access it's contents.

What's the proper syntax for extracting the Facts into a hash?

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com.
To post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Larry Fast at Apr 14, 2013 at 2:35 pm
    Starting to get some clarity but still need help. Using YAML to load Facts
    produces the YAML object below. But I'm still not clear on how to access
    the contents.

    myFacts = YAML.load( facts.yaml )
    print myFacts.inspect

    ### output:

    #<YAML::Object:0x7f550d6c6858 @class="Puppet::Node::Facts",
    @ivars={"values"=>{"timezone"=>"UTC", "puppet_vardir"=>"/var/lib/puppet",
    "macaddress_eth0"=>"00:50:56:8D:4E:95", ...

    Spelunking through the code leads me to think that the following should
    work, but it doesn't:
    print myFacts['timezone']


    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com.
    To post to this group, send email to puppet-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.
  • R.I.Pienaar at Apr 14, 2013 at 3:18 pm

    ----- Original Message -----
    From: "Larry Fast" <lfast1234@gmail.com>
    To: puppet-users@googlegroups.com
    Sent: Sunday, April 14, 2013 3:35:29 PM
    Subject: [Puppet Users] Re: what's the syntax for converting the yaml of facts into a hash table?

    Starting to get some clarity but still need help. Using YAML to load Facts
    produces the YAML object below. But I'm still not clear on how to access
    the contents.

    myFacts = YAML.load( facts.yaml )
    YAML.load_file("facts.yaml")

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com.
    To post to this group, send email to puppet-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Larry Fast at Apr 14, 2013 at 3:38 pm
    Oh yes, I forgot the first line of my snippet. But I still don't have a
    working syntax for reading the facts from that object.

    facts = File.read(filename)
    myFact = YAML.load( facts )
    print myFacts.inspect
    #<YAML::Object:0x7f550d6c6858 @class="Puppet::Node::Facts",
    @ivars={"values"=>{"timezone"=>"UTC", "puppet_vardir"=>"/var/lib/puppet",
    "macaddress_eth0"=>"00:50:56:8D:4E:95", ...
    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com.
    To post to this group, send email to puppet-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppuppet-users @
categoriespuppet
postedApr 14, '13 at 6:14a
activeApr 14, '13 at 3:38p
posts4
users2
websitepuppetlabs.com

2 users in discussion

Larry Fast: 3 posts R.I.Pienaar: 1 post

People

Translate

site design / logo © 2022 Grokbase