knife-api Chef Tool
A small library that lets you drive Chef's `knife` programmatically
Install & Usage Instructions
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install knife-api
The main feature of this library is the ability to drive knife as a method call as opposed to an individual program. This has a number of benefits:
- It's a lot faster
- You can capture output
- You're relying on code that has a contract to maintain compatible with Chef
- Use knife plugins all you want without breaking your workflow
- Optionally, Chef becomes constrained by a gemfile (as do the plugins you use) and that constraint remains consistent.
It provides two calls,
knife_capture that are injected into the
top-level namespace automatically. Additionally, if you are using
will detect this and make it available to rake's DSL as well.
If you wish to use this code elsewhere, just
include Chef::Knife::API into
Both commands take two argument-passing styles. Both use an array of strings to represent the ARGV passed to knife, but there is additionally a shorthand to make the actual subcommand stand out: if you supply a symbol or string with underscore-delimited subcommand names, it will automatically convert this for you. This allows you to visually distinguish a command from its arguments.
knife-api allows the use of alternative Chef Configs via the