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.
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 run end end
The essential sections of this file are:
The required
chef/knife
directive provides the calls all knife plugins inherit fromModuleName
is the name space for our plugin...