Larry Fast
2013-Apr-14 06:14 UTC
[Puppet Users] what''s the syntax for converting the yaml of facts into a hash table?
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.
Larry Fast
2013-Apr-14 14:35 UTC
[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 ) 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
2013-Apr-14 15:10 UTC
Re: [Puppet Users] Re: what''s the syntax for converting the yaml of facts into a hash table?
----- 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
2013-Apr-14 15:38 UTC
Re: [Puppet Users] Re: what''s the syntax for converting the yaml of facts into a hash table?
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.