Class: Champu::Step
- Inherits:
-
Object
- Object
- Champu::Step
- Defined in:
- lib/champu/step.rb
Instance Attribute Summary collapse
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #config(opts = {}) ⇒ Object
- #config_value(key) ⇒ Object
- #execute(command) ⇒ Object
-
#initialize(title) ⇒ Step
constructor
A new instance of Step.
- #nodes ⇒ Object
- #search(term) ⇒ Object
- #ui ⇒ Object
Constructor Details
#initialize(title) ⇒ Step
Returns a new instance of Step.
15 16 17 18 19 |
# File 'lib/champu/step.rb', line 15 def initialize(title) @title=title Chef::Config[:color]=true @config={} end |
Instance Attribute Details
#title ⇒ Object (readonly)
Returns the value of attribute title.
13 14 15 |
# File 'lib/champu/step.rb', line 13 def title @title end |
Instance Method Details
#config(opts = {}) ⇒ Object
29 30 31 32 |
# File 'lib/champu/step.rb', line 29 def config(opts={}) @config.merge!(opts) unless opts.empty? @config end |
#config_value(key) ⇒ Object
34 35 36 |
# File 'lib/champu/step.rb', line 34 def config_value(key) @config.key?(key) ? @config[key] : Champu::Config[key] end |
#execute(command) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/champu/step.rb', line 44 def execute(command) Chef::Config[:knife][:ssh_attribute] = config_value :ssh_attribute Chef::Config[:knife][:ssh_user]= config_value :ssh_user ui.msg(ui.color("Executing command:",:magenta) + ui.color(command,:yellow)) c=Chef::Knife::Ssh.new c.configure_attribute c.configure_user c.configure_identity_file c.config[:attribute]= config_value :ssh_attribute c.action_nodes(nodes) longest=0 nodes.collect{|n|c.format_for_display(n)[c.config[:attribute]]}.each do |item| hostspec = "#{config_value(:ssh_user)}@#{item}" session_opts = {} session_opts[:keys] = config_value :identity_file session_opts[:keys_only] = true session_opts[:logger] = Chef::Log.logger session_opts[:paranoid] = false session_opts[:user_known_hosts_file] = "/dev/null" c.session.use(hostspec, session_opts) longest = item.length if item.length > longest end c.fix_longest(longest) c.ssh_command(command) c.session.close end |
#nodes ⇒ Object
25 26 27 |
# File 'lib/champu/step.rb', line 25 def nodes @nodes end |
#search(term) ⇒ Object
38 39 40 41 42 |
# File 'lib/champu/step.rb', line 38 def search(term) Chef::Config[:knife][:ssh_attribute] = config_value(:ssh_attribute) Chef::Config[:knife][:ssh_user]= config_value :ssh_user @nodes=Chef::Search::Query.new.search(:node,term).first end |
#ui ⇒ Object
21 22 23 |
# File 'lib/champu/step.rb', line 21 def ui @ui ||= Chef::Knife::UI.new(STDOUT,STDERR,STDIN,Champu::Config) end |