Chef knife EDITOR variable unhappiness

I recently had to replace my main workstation because of a graphics card dying. It wasn’t all that big of a deal, thanks to the magic of regular backups and whatnot, but I found a very strange problem where when I tried to use knife to do any chef work that required editing anything in knife, I got the message:

ERROR: RuntimeError: Please set EDITOR environment variable

This was odd, since EDITOR was in fact set.

Turns out the solution is simple: I had installed MacVim with homebrew and set up my usual .vimrc stuff. I had EDITOR=vi in my .bashrc, but the vi in my path was the default OS X /usr/bin/vi. Unfortunately my .vimrc makes the default OS X vi gripe a little, and it exits with an exit status of 1. It still works fine, but that’s enough to make knife think that it failed miserably and it spits out the misleading message about the EDITOR variable above. To fix this, either fix the error in your .vimrc or make a symlink of /usr/local/bin/vi to /usr/local/bin/mvim. After that everything should be good.

NB: This situation probably applies to configurations for other editors as well, but I haven’t tested that at all. Still, if you have an emacs config that works and edits files fine but exits with a non-zero status, I imagine knife would be unhappy about that as well. I have no suggestions on how to fix emacs though.

Update: It was pointed out to me that you can also set knife[:editor] explicity in knife.rb:

That’s in the docs, of course (although I’ve never had much good luck with using the gui vim with knife; YMMV), and I tried setting knife[:editor] = "/usr/bin/vi". Still, it took me a while to figure out what the error about the EDITOR not being set even meant here and what was causing it. It wasn’t obvious at first that the problem was with one particular vi interacting with the .vimrc. However, explicitly setting knife[:editor] to the right editor you want with the full path would fix it too.

 
comments powered by Disqus