Creating new Knife plugins

Sometimes, you will be dealing with unique situations and need to create your own knife plugin. In this section, we will review how that is accomplished.

The basic plugin file format

A custom knife plugin begins by creating a new plugin ruby file. The plugin file has to have a specific format. That format, in its simplest form, looks like this:

require 'chef/knife' module ModuleName class SubclassName < Chef::Knife deps do require 'chef/dependency' end banner 'knife subcommand argument VALUE (options)' option :name_of_option, :short => "-l VALUE", :long => "--long-option-name VALUE", :description => "The description for the option.", :proc => Proc.new { code_to_run } :boolean => true | false :default => default_value def ...

Get Chef: Powerful Infrastructure Automation now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.