Class: Chef::Knife::Cereal
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::Cereal
- Defined in:
- lib/chef/knife/cereal.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Instance Method Summary collapse
- #cereal(node, command) ⇒ Object
- #chef_client_command(node_name, command) ⇒ Object
- #parse_args! ⇒ Object
- #run ⇒ Object
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
18 19 20 |
# File 'lib/chef/knife/cereal.rb', line 18 def command @command end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
17 18 19 |
# File 'lib/chef/knife/cereal.rb', line 17 def query @query end |
Instance Method Details
#cereal(node, command) ⇒ Object
54 55 56 57 |
# File 'lib/chef/knife/cereal.rb', line 54 def cereal(node, command) ui.msg "Running [#{command}] on node: [#{node.name}]" chef_client_command(node.name, command).run end |
#chef_client_command(node_name, command) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/chef/knife/cereal.rb', line 59 def chef_client_command(node_name, command) knife_ssh = Chef::Knife::Ssh.new knife_ssh.config[:manual] = true knife_ssh.name_args[0] = node_name knife_ssh.name_args[1] = command knife_ssh.config[:ssh_user] = config[:ssh_user] knife_ssh.config[:ssh_password] = config[:ssh_password] knife_ssh.config[:ssh_port] = config[:ssh_port] knife_ssh.config[:ssh_gateway] = config[:ssh_gateway] knife_ssh.config[:on_error] = :raise knife_ssh end |
#parse_args! ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/chef/knife/cereal.rb', line 72 def parse_args! @query = @name_args[0] @command = @name_args[1] if @query.nil? || @command.nil? ui.fatal "You need to specify the query and the command." exit 1 end end |
#run ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/chef/knife/cereal.rb', line 40 def run parse_args! begin query_nodes = Chef::Search::Query.new query_nodes.search('node', query) do |node| cereal(node, command) end rescue Exception => e ui.fatal "Node failed to cereal: #{e.}" ui.fatal e.backtrace.join("\n") exit 1 end end |