How can I develop and debug Chef cookbooks and recipes in an IDE (like Eclipse)?

16,529

Solution 1

I was also searching for this kind of tool.

Found this one that shows the shef to do it.

http://stevendanna.github.com/blog/2012/01/28/shef-debugging-tips-1/

Solution 2

You can use Eclipse as a simple editor for Chef Cookbooks. You won't have any IDE support and debug but some people like me might prefer it anyway.

If you would use a Ruby Editor on Eclipse you might get syntax highlighting for .rb Ruby files but I didn't try this yet.

You can make any folder an Eclipse Project (for example the chef-repo OR a specific cookcook) by adding a .project file with inside:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>PROJECT_NAME</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
    </buildSpec>
    <natures>
    </natures>
</projectDescription>

Then in Eclipse choose File -> Import -> General -> Existing Projects into Workspace and choose the folder where you added the .project file.

Solution 3

For Eclipse Ruby Development Tools, there is no support for chef cookbooks as of 2015 May 13th, however there is proprietary alternative if you want.

RubyMine 7 IDE supports Chef with Auto complete and definition navigation for standard Chef resources and their attributes. Ruby Mine is based on Intellij IDEA.

Instead of RubyMine, this feature works with Intellij IDEA if you install the Chef integration plugin on top of ruby plugin

If you are student or teachers, or is for education or training, or for open source projects, you can apply for free license.

Solution 4

May be it is already known but currently we can use ATOM with additional packages language-chef, linter-foodcritic, linter-ruby

https://atom.io/

Solution 5

The answer is not so simple, as of today Opscode doesn't have an "an official plugin".

I spent the past few evenings creating a chef plugin for eclipse. It's very bare bones right now, if other people show interest in working on it I might add more as well... For now it does most of what I need (creating new cookbooks, adding recipes, attributes, lwrps, etc.), mostly I'm putting an eclipse wrapper around the chef tools (chef, berks, kitchen, foodcritic, etc)

https://github.com/rleibman/chef-eclipse-plugin

I have no intention of removing this plugin, unless opscode comes up with their own.

I got started creating this plugin with great help from this tutorial: https://cvalcarcel.wordpress.com/2009/07/08/writing-an-eclipse-plug-in-part-1-what-im-going-to-do/.

Now, having said all of this... if you're comfortable with the command line, you can do most of what you need with things that are already there: create a cookbook with either berks or chef, e.g:

chef generate cookbook my_cookbook

And then create a new ruby project in eclipse opened to the cookbook you just created. Once it's created, you can edit ruby files, etc. You can also use all the other chef features (e.g. chef generate recipe) as well to help you get started.

Share:
16,529
gene_wood
Author by

gene_wood

LinkedIn Profile

Updated on June 05, 2022

Comments

  • gene_wood
    gene_wood almost 2 years

    I'm new to ruby and Chef. I've been developing cookbooks, committing them, uploading them to the Chef Server then deploying them to a Chef client with a role change followed by a "chef-client" run on the client. This process is slow.

    How can I, using an IDE (Eclipse in my case), develop cookbooks and be able to debug (set breakpoints, watch variables etc) and run them without uploading them to the Chef Server and then pulling them back down with a chef-client run?

    • I'm using Eclipse 3.7 Indigo with the "Dynamic Languages Toolkit - Ruby Development Tools 3.0.0.v20110424-7Z--E_EkMYXO4k101442" plugin
    • I'm developing Opscode Chef cookbooks with the 10.x Chef codeline
    • I'm working on an Ubuntu 10.10 system developing cookbooks to be run on RHEL/Centos 5 servers
    • We run our own Chef Server (open source)
  • gene_wood
    gene_wood over 12 years
    Is there any way to set breakpoints and watch variables after pausing execution this way? Maybe some way to enable ruby debug outside of an IDE but within a chef-solo run?
  • jodell
    jodell over 12 years
    For explorative and initial development, you might want to look at shef, the Opscode REPL. It's just an instrumented irb session so you can do anything you want with the runtime there.
  • shawnzhu
    shawnzhu almost 11 years
    chef-solo is good. it just lacks of feature like chef search which is widely used in multi-node configuration. I would say Berkshelf and vagrant would be good for testing the behavior of cookbooks. If you just want to test the interaction of your recipes and attributes, chefspec would be good which can provide unit-test like test report.
  • zuazo
    zuazo over 7 years
    I recommend you to share it. If not, this answer does not help with the problem.
  • rleibman
    rleibman over 7 years
    Sorry, I forgot, I've since added it.
  • dckuehn
    dckuehn over 7 years
    Please also add more details to your post. I understand that this is your repo, but if you migrate or the link changes, this answer won't help anyone.