What’s Mining: Chef Integration

Dmitry Krasilschikov

Hello everyone,

I’d like to introduce a plugin for RubyMine and IDEA that provides Chef support. It’s compatible with the last RubyMine Tsubaki EAP and Intellij IDEA 14 EAP.

Following the main concepts of Chef the plugin introduces cookbooks, recipes and resources in the IDE. It provides marking/detection options for a cookbook and code insight for a resource and for its attributes. Please note you need to install Chef gem before you start.

Cookbooks

Cookbooks are presented in RubyMine as a new kind of the project source root. So to define a directory as a cookbook you are to mark it as ‘Cookbook’ source root. This action is available via context menu in the Project View as well as in the Settings | Project Structure:

chef_1

 

If a directory contains ‘recipes’ folder with a ruby file inside, the directory is detected as a cookbook and you’re asked whether to add it or not:

chef_2

Resources

Since the folder is marked as a cookbook, code insight is available f0r any ruby file inside the ‘recipes’. E.g. one can complete any Chef resource or navigate to its definition into the Chef library:

chef_3

Attributes

Resource’s own attributes and inherited ones are also available inside the resource code block:

chef_4

Wherever it’s possible RubyMine suggests attribute arguments such as allowed actions for the action attribute; actions for the notifies and subscribes; all boolean arguments; and many more.

We would be glad if you try the plugin and share your feedback.  Please don’t hesitate to ask any questions here in the comments or on our forum.


Develop with pleasure!
JetBrains RubyMine Team

Comments below can no longer be edited.

30 Responses to What’s Mining: Chef Integration

  1. Andi S. says:

    September 9, 2014

    Well, this got me excited for a second, but then I noticed I had a different Chef in mind… oh well :/

  2. Yulian S. says:

    September 17, 2014

    That was a long-awaited feature
    Thank you guys!

    • Dmitry Krasilschikov says:

      September 17, 2014

      Thank you for kind words!

  3. Daryl Robbins says:

    September 23, 2014

    Fantastic addition to Ruby Mine! I have been looking for IDE support for Chef for a long time. It’s painful not having access to good code completion. Keep up the good work!

    • Dmitry Krasilschikov says:

      October 1, 2014

      Thank you! Your feedback would be greatly appreciated!

  4. Justin Schuhmann says:

    October 2, 2014

    Can’t get this working in IntelliJ IDEA Ultimate 14 EAP…
    1. Installed the plugin
    2. when running sudo gem install chef
    -Building native extensions. This could take a while…
    ERROR: Error installing chef:
    ERROR: Failed to build gem native extension.

    /opt/chef/embedded/bin/ruby extconf.rb
    creating Makefile
    /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/libyajl2-1.0.1/ext/libyajl2
    extconf.rb:104:in `makemakefiles’: unhandled exception
    from extconf.rb:143:in `’

    Gem files will remain installed in /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/libyajl2-1.0.1 for inspection.
    Results logged to /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/libyajl2-1.0.1/ext/libyajl2/gem_make.out

    i’m running on mac os x, I presume i need this gem (even though i have chef installed) because i can’t get the ide to allow me to select items in the project view to have a Cookbook or chef tag.

  5. Justin Schuhmann says:

    October 2, 2014

    I now have the gem install chef working….
    However I still don’t have an option under Project Structure to tag my cookbooks

  6. Justin Schuhmann says:

    October 2, 2014

    To get this working I first had to in IntelliJ IDEA EAP 14 Terminal run:
    sudo gem install chef

    I then loaded the chef-repo folder:
    I have to open a recipe inside a cookbook and my cookbooks were auto detected.

    I still don’t have intellisense

    Note: On mac os x if you get a compile error with gem install chef
    run the following:
    sudo gcc -v
    then go to the bottom using space
    then type accept

    • Justin Schuhmann says:

      October 2, 2014

      It doesn’t seem to understand anything chef as well

      • Dmitry Krasilschikov says:

        October 5, 2014

        Hello, Justin!

        Thank you for details feedback.

        > It doesn’t seem to understand anything chef as well
        Please clarify the problem.

        Since the ‘chef’ gem has been installed it should be automatically added as ‘external library’. Also the code completion of the chef default resources, attributes and some attribute parameters should appear in all “.rb” files under the marked ‘cookbook’ directory, shouldn’t they?

  7. Martin Cleaver says:

    November 14, 2014

    Does it work well with ChefDK? And with rbenv for ChefDK too?

    Thanks, M.

  8. Dmitry Krasilschikov says:

    November 17, 2014

    Hello, Martin,

    the Chef plugin of RubyMine uses the ‘Chef’ gem in the selected Ruby SDK.

    Please note that the “Chef” gem is pre-installed into the embedded into the ChefDK Ruby SDK (by default it’s ‘/opt/chefdk/embedded/bin/ruby’) so you can just add it into the RubyMine and the ‘Chef’ plugin will use it.

    Sure, the same you can do in the case of the ChefDK managed by rbenv. Please see also the ‘rbenv support’ reference.

  9. Michael Hedgpeth says:

    November 25, 2014

    This is a really great plugin that I mostly got working. Thanks so much for your hard work!

    One question: How does the plugin handle cookbook dependencies.

    I have a cookbook with a Berksfile declared with a dependency on the windows and dsc cookbooks. It doesn’t appear that my dsc_resource or powershell_script resources are being recognized by RubyMine. Is this expected?

  10. Darryl says:

    March 18, 2015

    Hey,

    I still can’t get code completion to work. I’ve pointed at my chefdk ruby, the cookbook is getting recognised and flagged as a cookbook root, however I get no chef code completion like in the Resources screenshot.

    Any ideas?

    I’m on RubyMine 7.0.4 with ChefDK 0.4.0.

    Cheers,
    Darryl

    • Dmitry Krasilschikov says:

      March 19, 2015

      Hello, Darryl,

      unfortunately the Chef DK hasn’t supported yet, I’m working on it now, please follow https://youtrack.jetbrains.com/issue/RUBY-16312

      To get completion work in the RubyMine 7.x please add the ‘Chef’ gem into your ruby sdk as mentioned in the post.

  11. Daniel Zabel says:

    September 16, 2015

    Hello Dmitry,

    is it possible to configure excludes for cookbook detection?

    For example: berks-cookbooks

    Cheers,

    Daniel

    • Dmitry Krasilschikov says:

      September 16, 2015

      Hello Daniel,

      Unfortunately there isn’t ability to exclude cookbooks but you can entirely disable this intention in Settings | Inspections.

      I’ve created request – https://youtrack.jetbrains.com/issue/RUBY-17161

  12. Aleksey Hariton says:

    October 27, 2015

    Hello Dmitry,

    could you please help to disable some rules of FoodCritic delivered with plugin, where I can find FC config or run arguments?

    Thanks.

    • Dmitry Krasilschikov says:

      October 27, 2015

      Hello Aleksey,

      unfortunately there is no possibility to customize foodcritic output in Chef plugin now.

      I’ve created feature https://youtrack.jetbrains.com/issue/RUBY-17304, please vote and follow.

      • Aleksey Hariton says:

        October 28, 2015

        Done.
        Mb you can share plugin Git repo?
        I can try to do patch by myself and share it, its not so large feature 🙂

  13. Hemant says:

    October 31, 2016

    Does ruby mine integrate with Test Kitchen for running rspec tests ?

    • Dmitry Krasilschikov says:

      November 1, 2016

      Hello, Hemant,

      RubyMine widely supports RSpec tests so you can use it with Test Kitchen framework.

  14. Yan says:

    November 3, 2016

    Tnx for good info

  15. Gene Wood says:

    October 25, 2017

    Dmitry, should this Chef plugin still work here in 2017?

    If using RubyMine 2017.2.4
    with the plugin “Chef integration” of version 172.3317.67
    And chefdk’s ruby-2.4.2-p198 interpreter

    And i create a new directory

    mkdir testing
    cd testing

    and in that directory a new cookbook by running

    chef generate cookbook examplecookbook

    And I open “testing” in RubyMine

    And I open testing/examplecookbook/recipes/defualt.rb

    The plugin prompts me to setup two cookbooks

    examplecookbook
    build_cookbook

    And I click “Configure Cookbooks”

    and uncheck build_cookbook so I can setup examplecookbook

    I get no chef plugin functionality (highlighting, autocomplete, etc)

    Since this is the most basic setup I can think of, am I overlooking something or does this plugin just no longer work with modern chef and/or modern RubyMine?

    • Anna Kutarba says:

      November 3, 2017

      Most possible reason is https://youtrack.jetbrains.com/issue/RUBY-20361, which will be fixed in the 2017.2.5 EAP (next week). You can try 2017.3 BETA which doesn’t contain this problem: https://www.jetbrains.com/ruby/download/ or add Gemfile to the project and bundle gem ‘chef’ to the project, then you will be able to see completion and resolving.
      Thanks for bug-report and deeply sorry for inconveniences.

      • Valter says:

        April 10, 2018

        Hi Anna, I’m still having the same issue as described by Gene Wood. I’m using Ruby Mine 2018.1, I’m doing the exact steps as he did. Still no autocompletion for anything. Could you please assist?

        Thank you very much,
        Valter.

        • Valter says:

          April 11, 2018

          I just found my mistake, I forgot to inform RubyMine to use ChefDK as SDK and not my local ruby installation 🙂
          All good now!

  16. Jim Croft says:

    March 28, 2019

    YT issue asking for Berkshelf support has been open for four years! If Jetbrains have no interest in maintaining this plugin can it be open sourced so others can pick it up?

Subscribe

Subscribe for updates