[Puppet Users] parsing puppet YAML

1,094 views
Skip to first unread message

Baker, Luke Jefferson

unread,
May 22, 2010, 4:44:33 AM5/22/10
to Puppet Users

Hey there,

 

I’ve playing with parsing some of the yaml data that puppet creates. Has anyone had luck doing this with python or the like? It seems that in every yaml file, there is a comment at the top of the file like this..

 

--- !ruby/object:Puppet::Node

 

Which doesn’t make may yaml parsers happy.. where am I going wrong?

 

--Luke Baker

 

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

Ohad Levy

unread,
May 22, 2010, 7:43:20 AM5/22/10
to puppet...@googlegroups.com
Hi Luke,

Thats a dump of a ruby object in yaml, meaning that if you would like to restore the object (and its methods) you would need to run it in ruby and load the puppet libraries.

what are you trying to achieve? there are a few examples out there already.

Ohad

Nigel Kersten

unread,
May 22, 2010, 4:01:29 PM5/22/10
to puppet...@googlegroups.com
You can load it in Python, you just need to do a bit more extra work first.

I can get you an example on Monday or whenever Comcast fix my home internet connection...
--
nigel

Nigel Kersten

unread,
May 22, 2010, 6:32:21 PM5/22/10
to puppet...@googlegroups.com
On Fri, May 21, 2010 at 9:44 PM, Baker, Luke Jefferson <Bak...@missouri.edu> wrote:

Hey there,

 

I’ve playing with parsing some of the yaml data that puppet creates. Has anyone had luck doing this with python or the like? It seems that in every yaml file, there is a comment at the top of the file like this..

 

--- !ruby/object:Puppet::Node

 

Which doesn’t make may yaml parsers happy.. where am I going wrong?



Hopefully this is enough to get you started. I've been meaning to write up a blog post on this, so I might try and get that done soon.

You need to set up some stub objects so Python knows what to do with them, like:

class PuppetReport(yaml.YAMLObject):
  yaml_tag = u'!ruby/object:Puppet::Transaction::Report'
  def __init__(self, host, logs, metrics, records, time):
    self.host = host
    self.logs = logs
    self.metrics = metrics
    self.records = records
    self.time = time


class PuppetLog(yaml.YAMLObject):
  yaml_tag = u'!ruby/object:Puppet::Util::Log'
  def __init__(self, source, message, tags, time, level):
    self.source = source
    self.message = message
    self.tags = tags
    self.time = time
    self.level = level


class PuppetMetric(yaml.YAMLObject):
  yaml_tag = u'!ruby/object:Puppet::Util::Metric'
  def __init__(self, values, name, label):
    self.values = values
    self.name = name
    self.label = label


Then when you read the yaml file, Python will consider !ruby/object:Puppet::Util::Metric to be a PuppetMetric class.

This may not be complete even for these objects, but I tend to just iterate until I've got all the data I need.
 

Stuart Cracraft

unread,
Dec 13, 2013, 12:04:39 AM12/13/13
to puppet...@googlegroups.com
Where did this go?

Dan White

unread,
Dec 13, 2013, 1:24:17 AM12/13/13
to Puppet Users Mailing List
Continue down the thread:


and then this should help


Puppet::Node is a data structure like Puppet::Transaction::Report and Puppet::Util::Log as described here:



To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/e23870ec-93e1-4057-a616-977da955ec73%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

“Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us.” 
Bill Waterson (Calvin & Hobbes)

Reply all
Reply to author
Forward
0 new messages