 of precedence for a knife option is:
- A value passed via the command line
- A value saved in the knife.rb file
- A default value
The following example shows how the knife bootstrap subcommand checks for a value in the knife.rb file by using the :proc attribute:
option :ssh_port, :short => "-p PORT", :long => "--ssh-port PORT", :description => "The ssh port", :proc => Proc.new { |key| Chef::Config[:knife][:ssh_port] = key }
where Chef::Config[:knife][:ssh_port] tells knife to check the knife.rb file for a setting named knife[:ssh_port].
And the following example shows the knife bootstrap subcommand calling the knife ssh subcommand for the actual SSH part of running a bootstrap operation:
def knife_ssh ssh = Chef::Knife::Ssh.new ssh.ui = ui ssh.name_args = [ server_name, ssh_command ] ssh.config[:ssh_user] = Chef::Config[:knife][:ssh_user] || config[:ssh_user] ssh.config[:ssh_password] = config[:ssh_password] ssh.config[:ssh_port] = Chef::Config[:knife][:ssh_port] || config[:ssh_port] ssh.config[:ssh_gateway] = Chef::Config[:knife][:ssh_gateway] || config[:ssh_gateway] ssh.config[:identity_file] = Chef::Config[:knife][:identity_file] || config[:identity_file] ssh.config[:manual] = true ssh.config[:host_key_verify] = Chef::Config[:knife][:host_key_verify] || config[:host_key_verify] ssh.config[:on_error] = :raise ssh end
where
- ssh = Chef::Knife::Ssh.new creates a new instance of the Ssh subclass named ssh
- A series of settings in knife ssh are associated with knife bootstrap using the ssh.config[:setting_name] syntax
- Chef::Config[:knife][:setting_name] tells knife to check the knife.rb file for various settings
- Raises an exception if any aspect of the SSH operation fails
Search¶
Use the Chef server search capabilities from a plugin to return information about the infrastructure to that plugin. Use the require method to ensure that search functionality is available with the following:
require 'chef/search/query'
Create a search query object and assign it to a variable:
variable_name = Chef::Search::Query.new
After the search object is created it can be used by the plugin to execute search queries for objects on the Chef server. For example, using a variable named query_nodes a plugin could search for nodes with the webserver role and then return the name of each node found:
query = "role:webserver" query_nodes.search('node', query) do |node_item| puts "Node Name: #{node_item.name}" end
This result can then be used to edit nodes. For example, searching for nodes with the webserver role, and then changing the run_list for those nodes to a role named apache2:
query = "role:webserver" query_nodes.search('node', query) do |node_item| ui.msg "Changing the run_list to role[apache2] for #{node_item.name}" node_item.run_list("role[apache2]") node_item.save ui.msg "New run_list: #{node_item.run_list}" end
It’s also possible to specify multiple items to add to the run_list:
node_item.run_list("role[apache2]", "recipe[mysql]")
And arguments sent with a plugin command can also be used to search. For example, if the command knife envchange "web*" is sent, then the command will search for any nodes in roles beginning with “web” and then change their environment to “web”:
module MyKnifePlugins class Envchange < Chef::Knife banner "knife envchange ROLE" deps do require 'chef/search/query' end def run if name_args.size == 1 role = name_args.first else ui.fatal "Please provide a role name to search for" exit 1 end query = "role:#{role}" query_nodes = Chef::Search::Query.new query_nodes.search('node', query) do |node_item| ui.msg "Moving #{node_item.name} to the web environment" node_item.chef_environment("web") node_item.save end end end
User Interaction¶
The ui object provides a set of methods that can be used to define user interactions and to help ensure a consistent user experience across knife plugins. The following methods should be used in favor of manually handling user interactions:
For example, to show a fatal error in a plugin in the same way that it would be shown in knife do something similar to the following:
unless name_args.size == 1 ui.fatal "Be sure to say hello to someone!" show_usage exit 1 end
Create a Plugin¶
A knife command is a Ruby class that inherits from the Chef::Knife class. A knife command is run by calling the run method on an instance of the command class. For example:
module MyKnifePlugins class HelloWorld < Chef::Knife def run puts "Hello, World!" end end end
and is run from the command line using:
$ knife hello world
Exceptions¶
In most cases, the exception handling available within knife is enough to ensure that exception handling for a plugin is consistent with how knife ordinarily behaves. That said, exceptions can also be handled within a knife plugin in the same way they are handled in any Ruby program.
Install a Plugin¶
To install a knife plugin from a file, do one of the following:
- Copy the file to the ~/.chef/plugins/knife directory; the file’s extension must be.rb
- Add the file to the chef-repo at the CHEF_REPO/.chef/plugins/knife; the file’s extension must be.rb
- Install the plugin from RubyGemsPost a reply to the thread: Congrats to the newest 48 State'r!!.
Drop by Nor Cal when..
you do. I'll drive with ya.
Scott Pettit
Drop by Nor Cal when..
---------------------------------------------------------------------------------------------------
Re: Congrats to the newest 48 State'r!!
I'd keep playing! I don't think the heavy stuff will be coming down for quite a while!
z3RIFFRAFF
---------------------------------------------------------------------------------------------------
I just saw them when they had 1 to go!
I have 13 to go, should have them done by next spring. And, Yes! I know that this is not a competition!
Fred
96 1.9 Z3 black/tan/black
97 M3/4 estoril/gray
08 Kubota 3400 HST orange/charcoal
08 GMC Sierra stealth gray/gray
I just saw them when they had 1 to go!
Congrats, I witness them in 5 of those states.
Congrats, I witness them in 5 of those states.
I've only got 23, but I got the east coast DONE only got 23, but I got the east coast DONE
Way to go! Or is it 'way to went'?
Congrats to the newest 48 State'r!!
Buddy & Kathy have now reached the 48 state mark in their cute little car*... Way to go guys... Welcome to the club.
Their West Coast visit.
* Please note this is not a.
Congrats to the newest 48 State'r!!
Forum Rules<reponame>automaidan/judges
{"Department":"Прокуратура Донецької області","Region":"Донецька область","Position":"прокурор відділу процесуального керівництва у кримінальних провадженнях слідчих регіональної прокуратури прокуратури Донецької області","Name":"<NAME>","Декларації 2013":"","Декларації 2014":"","Декларації 2015":"","Декларації 2016":"https://public.nazk.gov.ua/declaration/1b6c18ce-01b6-480a-acc6-73a936caa305","Фото":"","Як живе":"","Декларації доброчесності":"http://www.gp.gov.ua/integrity_profile/files/af2a26af1053412cd81d68ab2c5b545f.pdf","type":"prosecutor","key":"surkov_artem_viktorovich","analytics":[{"y":2015,"h":25.2,"ha":1,"fi":89910,"fh":25.2,"fha":1,"fla":2},{"y":2016,"i":80472,"h":25.