Setting up Sublime Text 3 with an RVM-managed Puppet rig

I use Sublime Text pretty much exclusively when I’m working with Puppet code. It’s nice to be able to validate that the manifest I’m working on is syntactically correct without leaving Sublime Text. This was easy to do at one point in time, but got complicated as my relationship with Puppet, Ruby, and RVM evolved. Some of the magic interconnectedness broke for me quite some time ago. I didn’t bother fixing it until last night. As I did that, I documented the process so that maybe it will be easier for someone else.

Install package control and necessary packages

The instructions for installation are found here. They request that one not repost installation instructions. It’s a simple one-command experience. Just do it.

Install sublimelinter and puppet sublime text packages

Use Package Control to install the SublimeLinter, and Puppet packages. Incidentially, these are open source, volunteer-driven projects. If you use them, and derive value from them, be a good human, and throw a donation their way. Either contribute something code-wise, or throw a few dollars, bitcoin, chickens,whathaveyou at them.

Restart Sublime Text

It’s entirely possible this is an unnecessary step. I don’t care. Who’s driving this bus? You are. If you don’t wanna restart Sublime Text, don’t.

Tangent: Invoking Sublime Text from inside a terminal

I don’t know if this holds true for you, but I work in iTerm2 a lot. I’ve found it pretty helpful to be able to fire up a Sublime Text session in the directory I happen to be working with in a terminal. This is super easy to do: I am assuming Your Sublime Text installation is located at /Applications/Sublime\ If it’s installed at a different location on your system, change the path to correspond with the location of Sublime Text

  • Link the shellcmd into someplace relevant:I chose to install this in /usr/local/bin/subl. You can very easily use ~/bin, or any location that’s in your PATH environment variable. Pick a relevant location to your sensibilities if you don’t like/usr/local/bin/
    $ sudo ln -s /Applications/Sublime\ /usr/local/bin/subl
  • Make sure it worked:
    ~$ ls -la /usr/local/bin/subl
    lrwxr-xr-x 1 wnoble humans 62 Jun 18 21:36 /usr/local/bin/subl -> /Applications/Sublime
    ~$ subl .

Assuming this worked, you’ll get a sublime window opened up, with all the files in your home directory listed in a nice navbar on the left side of the window. Get one? Sweet!

Awesome! Now we’re ready! Lets validate some code!

Try out the new build system!

Lets open up a puppet manifest to test out our new build system I’ll use my bashrc module here.

~/Wolfspyre/Puppet/Modules/core/bashrc (master)$ subl .
  • open up init.pp
  • launch the build system:

‘⌘’ + ‘b’

What the hell?!

[Errno 2] No such file or directory: ‘puppet'
[cmd: ['puppet', 'parser', 'validate', '--color=false', '--confdir=/tmp', '--vardir=/tmp', '/Users/wnoble/Wolfspyre/Puppet/Modules/core/bashrc/manifests/init.pp']]
[dir: /Users/wnoble/Wolfspyre/Puppet/Modules/core/bashrc/]
[path: /usr/bin:/bin:/usr/sbin:/sbin]

Nope. This wasn’t going to be straight forward.

So… Now what?!

I went down a rabbithole and figured out that I had to edit the sublime text build system config file for Puppet. Strangely enough, the configfile is stored inside a static file, which is a zip of the package which was downloaded. If you edit it, the next time the package gets updated, your edits will get lost. This is going to break in the future, and I’m not going to want to figure it out at the time. I’m certain of this, as the last time it broke it took me almost a year to get around to trying to fix it. Lets just avoid this problem all together. To do that, we have to override the default settings with some values relevant to your system. That sounds simple enough, right? Here’s a few links to various build system doculemtation:

Overriding the defaults didn’t seem to work as well as anticipated

I read the Sublime Text 3 documentation for settings and for projects. After reading them, I assumed that if I created a file in: ~/Library/Application Support$ cd Sublime\ Text\ 3/Packages/User with the name of Puppet.sublime-build that everything would work fine… Well, not quite so much. Duplicated_Build_System   Hmm… uh… well… OK, it works, but it’s not so easy to know which one to use. The Puppet.sublime-build file in the package zip file is still being referenced. As is the override file we just made. So we now have two build system files, so Sublime Text nicely lists them both for us to select which Puppet build system configuration we’d like to use… Rather than having to remember which one was my Puppet build system configuration, I just decided to make my own, and have its’ name not conflict with the configuration provided by the package:

~/Library/Application Support/Sublime Text 3/Packages/User$ mv Puppet.sublime-build  Our_Puppet.sublime-build

Distinguished_Build_System That’s better.

Okay great! So.. Uh… What’s in this file of wonderflonium?

So now that it’s pretty easily to tell what build system Sublime Text is going to use for validating my code,Great! Now what’s the difference between my awesome Puppet.sublime-build file, and the default one?

RVM pathing

I opened Issue 2935 on RVM’s github page to make/manage a set of symlinks pertaining to the idea of the current RVM environment you’re working in. Hopefully they like the idea and implemet it. Until then, just stick with your global RVM environment, or decide on an environment to explicitly tie Sublime Text to use. Either way, once you’ve told RVM which evironment to use, figure out the relevant bits of your path/environment to share with Sublime Text

PATH and Environment Variables

So, Puppet works just fine for me on the command line, lets figure out why it doesn’t work in Sublime Text.

~$ which puppet

Aha! So I have to set the PATH and a few environment variables for Puppet. What’s relevant

~/Library/Application Support/Sublime Text 3/Packages/User$ env|egrep -i '(gem|ruby|rvm)'
rvm_version=1.25.28 (stable)

That’s a mouthful. Fortunately, not everything there is really relevant. We need to update the PATH variable, and set some environment variables. Lets create a sublime-build file and add these to it:

Open Your Sublime Text settings directory in… Sublime Text.

I’ll spare you a recursion joke and just get on with it.

~$ cd ~/Library/Application Support/Sublime\ Text\ 3/Packages/User; subl .
Create your .sublime-build file

I chose to name the sublime-build file Our_Puppet.sublime-build. You can name yours monkey_bars.sublime-build, or chicken-coop.sublime-build, or whatever_the_hell_you_want.sublime-build.. Picking something relevant to Puppet might make your life a little simpler when trying to select the build system you want to use… But hey, it’s your workflow, not mine. Whatever you name the file, put this as the content. Be sure to change my home directory to yours, otherwise this won’t really do you much good.


    "cmd": [ "puppet", "parser", "validate", "--confdir=/tmp", "--color=false", "--vardir=/tmp", "$file" ],
    "working_dir": "${project_path:${folder:${file_path}}}",
    "selector": "source.pp",
    "env": {
        "IRBRC": "/Users/wnoble/.rvm/rubies/ruby-1.9.3-p547/.irbrc",
        "MY_RUBY_HOME": "/Users/wnoble/.rvm/rubies/ruby-1.9.3-p547",
    "path": "/Users/wnoble/bin:/Users/wnoble/.rvm/gems/ruby-1.9.3-p547/bin:/Users/wnoble/.rvm/rubies/ruby-1.9.3-p547/bin:/Users/wnoble/.rvm/gems/ruby-1.9.3-p547@global/bin:/Users/wnoble/.rvm/bin:/opt/local/bin:$PATH",

Once this file is set, you should be able to run Puppet to check that your particular file is syntactically correct in Sublime by simply pressing ‘⌘’ + ‘b’!

Hope this helps you!

If it does, there’s Bitcoin/Litecoin donation links at the bottom of the page, should you feel so inclined.

Leave a Reply