background preloader

Convert b/w puppet & chef

Facebook Twitter

Relistan/chef2puppet. Convert Chef Cookbooks to Puppet Modules – Repeatable Systems. What if you, for any number of reasons, needed to convert Chef cookbooks to Puppet modules and it were convenient to do it in an automated way?

Convert Chef Cookbooks to Puppet Modules – Repeatable Systems

How hard the task would be to convert the cookbook depends largely on how off the ranch the recipes are with respect to the Chef DSL. Since Chef recipes are just Ruby code, you can write whatever you want into the recipe. But if the recipes were written in a way that mostly sticks with the Chef DSL you can get fairly clean Puppet output in a really simple way: take advantage of the fact that Chef’s DSL is Ruby, and write a system for evaluating the Chef DSL and generating Puppet syntax output. I found this to be a surprisingly legitimate case for heavy meta-programming as much of the Chef DSL translates pretty well directly to Puppet. Hopefully no one is ready to start a flame war at this point.

Usage: convert.rb [options] -c, --cookbook COOKBOOK Chef Cookbook directory (e.g. contains /recipes, /attributes...) Here is what the converter handles: FactsOhai - MCollective Plugins - Puppet Labs. Overview¶ The Ohai plugin enables mcollective to use OpsCode Ohai as a source for facts about your system.

FactsOhai - MCollective Plugins - Puppet Labs

This plugin uses a 3000 second cache for facts, after that it will reset Ohai and regenerate all the facts, this adds a few seconds or so overhead to discovery. This plugin is released as Apache License v2 same as the license of Ohai. Installation ¶ If you are using MCollective 1.1.0 or newer you need the file opscodeohai_facts.rb else opscodeohai.rb The source for the plugin is GitHubFollow the basic plugin install guide – place the opscodeohai.rb or opscodeohai_facts.rb in the facts sub directory Configuration¶ You can set the following config options in the server.cfg.

Using With Chef. If you’re a Chef user you are supported in both facts and classes filters.

Using With Chef

Facts There is a community plugin to enable Ohai as a fact source. Using this plugin Ohai facts will be converted from: to: ""=>"1.6.0", ""=>"OpenJDK Runtime Environment", ""=>"1.6.0-b09", So you can use the flattened versions of the information provided by Ohai in filters, reports etc. % mco find --with-fact Class Filters Chef does not provide a list of roles and recipes that has been applied to a node, to use with MCollective you need to create such a list.

It’s very easy with Chef to do this in a simple cookbook. This will create a list of all roles and recipes in /var/tmp/chefnode.txt on each node for us to use: ruby_block "store node data locally" do block do state ="/var/tmp/chefnode.txt", "w") node.run_state[:seen_recipes].keys.each do |recipe| state.puts("recipe. Converting Puppet Modules to Chef Cookbooks - redbluemagenta. Over a couple of caffeine induced nights, I’ve converted a handful of our Puppet modules over to Chef cookbooks (by hand) to see how it’d all turn out.

Converting Puppet Modules to Chef Cookbooks - redbluemagenta

We’ve not yet decided whether we will actually use Chef in production, but I figure that if I’ve lowered the bar of entry, it would make the decision much easier (we’d still have to worry about whether the technical merits justify putting in time to transition everything over to Chef, but at least the initial cost of converting things over isn’t as painful as it would’ve been.) Here’s a sample snippet of Puppet code that I’ll be referring to for the rest of the article: Here’s what our code will look like so far, given the above: Now, what do we do with the exec resources? There’s still a few things that make sense to port directly to Chef’s “execute” resources - things like updating database users, running a program to alter configuration (think “make” for creating sendmail database files), or extracting tarballs. Devstructure/blueprint. Puppet to chef converter.