Apr 29

Chef 0.10 Preview: chefignore

By Dan DeLeo 3 Comments
Be Sociable, Share!
  • HackerNews
  • Reddit
  • Tumblr
  • email
Tag: , , , ,

Here's the issue: we love our text editors and version control systems, but, despite all the indespensible things these tools do for us, they sometimes leave behind temporary or data files that we don't want to distribute to every host in our infrastructure. Before Chef 0.10, it was a pain to keep knife from uploading swap files and version control data to your Chef Server. Chef actually has had an ignore file feature for quite some time; however, ignore files are only respected on a per-cookbook basis, so you have to maintain a copy of this ignore file for each cookbook you have in your repository. In addition, ignore files use regular expressions to match paths, which is a bit unnatural for the task.

In Chef 0.10, the old ignore file system has been removed. In it's place, Chef now uses a single chefignore file, placed in the root of your cookbook repository, to determine which files to ignore when uploading cookbooks. chefignore files use Ruby's File.fnmatch under the hood, so the syntax is similar to a shell glob—much more natural when dealing with file paths.

Ignoring Subversion Directories

I don't use subversion day-to-day anymore, but for demonstration purposes I've created a cookbook and placed a .svn directory inside the templates directory. When I upload it, I can see the subversion data is there:

knife cookbook show ignoramus 0.0.1 | grep .svn
    name:         .svn/some-svn-data
    path:         templates/default/.svn/some-svn-data

Now I create the chefignore file in the root of the repo with the following content:

*/.svn/*

After re-uploading the cookbook, I can see that my svn directories are now ignored:

knife cookbook show ignoramus 0.0.1 | grep .svn
# nothin'

Ignoring Editor Swapfiles

Ignoring the files left behind by editors is easy. Just put this in your chefignore file:

# emacs
*~
# vim
*.sw[a-z]

This feature is certainly less exciting than some of the other new features in Chef 0.10, but it's definitely something that it's hard to live without when you need it. We think you'll find this a big improvement over the current system.

By the way, we're in the home stretch for Chef 0.10. If you're on the Opscode Platform you can start using Chef 0.10 by upgrading your gems:

(sudo) gem install chef --pre

And if you're running your own Chef server, check the wiki for upgrade instructions or spin up a new server for testing:

sudo chef-solo -j chef.json -c solo.rb -r https://s3.amazonaws.com/chef-solo/bootstrap-0.10.0.rc.0.tar.gz

As always, you can find us on irc.freenode.net#chef or on the mailing list if you need a hand.

  • Pingback: Chef 0.10.0 Released! | Opscode.com

  • http://parsedparticiple.org/ Faiz Kazi

    Thanks for adding this feature.

    It appears though, that the chefignore file only works if placed under the “cookbooks/” directory.
    At least on my setup (ruby 1.9.2, chef 0.10.0 installed via gem, Debian 6), placing it
    at the repo root had no effect.

    • Scott Wallace

      I also found this to be true.