Category: Ruby


Ruby – Parse XML or Build XML

By polfilm,

To parse an XML string:

require 'xml'

xml = '<?xml version="1.0"?><root><child attr="value">text</child></root>'
root = XML::Parser.string(xml).parse.root
child = root.children.find { |node| node.name == "child" }
attr = child["attr"]

To build an XML document:

require 'xml'

xml = XML::Document.new
root = XML::Node.new("root")
child = XML::Node.new("child", "text")
child["attr"] = "value"
root << child
xml.to_s

Chef Solo Pattern with Berkshelf

By polfilm,

http://spin.atomicobject.com/2013/01/03/berks-simplifying-chef-solo-cookbook-management-with-berkshelf/
https://github.com/englishm/chef-solo-pattern
Chef – berkshelf lesson for dummies like me Ermahgerd!
http://leonard.io/blog/2012/05/installing-ruby-1-9-3-on-ubuntu-12-04-precise-pengolin/
https://github.com/opscode/nagios-quick-start
http://stackoverflow.com/questions/14173701/chef-upload-and-re-apply-a-cookbook-to-a-node