{"id":1091,"date":"2009-10-19T09:47:13","date_gmt":"2009-10-19T08:47:13","guid":{"rendered":"http:\/\/www.devco.net\/?p=1091"},"modified":"2009-10-20T17:13:07","modified_gmt":"2009-10-20T16:13:07","slug":"reusing_puppet_providers","status":"publish","type":"post","link":"https:\/\/www.devco.net\/archives\/2009\/10\/19\/reusing_puppet_providers.php","title":{"rendered":"Reusing Puppet Providers"},"content":{"rendered":"

Last night I was thinking about writing scripts to manage services, packages etc in a heterogeneous environment. This is hard because the operating systems all behave differently.<\/p>\n

This is of course a problem that Puppet solves with it’s providers system, after some chatting with Luke on IRC I now have a pretty nice solution.<\/p>\n

Assuming you don’t mind shell scripting in Ruby here’s a pretty decent bit of Ruby to manage a service on many different environments.<\/p>\n

\n
\nrequire 'puppet'\n\nservice = ARGV.shift\naction = ARGV.shift\n\nARGV.length > 0 ? hasstatus = true : hasstatus = false\n\nbegin\n    svc = Puppet::Type.type(:service).new(:name => service, \n        :hasstatus => hasstatus).provider\n\n    svc.send action\n\n    puts(\"#{service} #{action} status: #{svc.status}\")\nrescue Exception => e\n    puts(\"Could not #{action} service #{service}: #{e}\")\nend\n<\/pre>\n<\/blockquote>\n
\n
\n# service.rb httpd stop true\nhttpd stop status: stopped\n\n# service.rb httpd start true\nhttpd start status: running\n<\/pre>\n<\/blockquote>\n

You’d probably want to put in support for the pattern parameter to keep certain broken Operating Systems happy, but this is pretty nice and platform independent.<\/p>\n","protected":false},"excerpt":{"rendered":"

Last night I was thinking about writing scripts to manage services, packages etc in a heterogeneous environment. This is hard because the operating systems all behave differently. This is of course a problem that Puppet solves with it’s providers system, after some chatting with Luke on IRC I now have a pretty nice solution. Assuming […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","footnotes":""},"categories":[7],"tags":[77,21,13],"_links":{"self":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/1091"}],"collection":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/comments?post=1091"}],"version-history":[{"count":7,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/1091\/revisions"}],"predecessor-version":[{"id":1241,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/1091\/revisions\/1241"}],"wp:attachment":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/media?parent=1091"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/categories?post=1091"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/tags?post=1091"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}