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
|