Module: Deployinator::Helpers::DshHelpers
- Defined in:
- lib/deployinator/helpers/dsh.rb
Instance Method Summary collapse
- #dsh_fanout ⇒ Object
- #hosts_for(group) ⇒ Object
- #run_dsh(groups, cmd, only_stdout = true, &block) ⇒ Object
- #run_dsh_extra(dsh_group, cmd, extra_opts, only_stdout = true, &block) ⇒ Object
-
#run_dsh_hosts(hosts, cmd, extra_opts = '', only_stdout = true, &block) ⇒ Object
run dsh against a given host or array of hosts.
Instance Method Details
#dsh_fanout ⇒ Object
4 5 6 |
# File 'lib/deployinator/helpers/dsh.rb', line 4 def dsh_fanout @dsh_fanout || 30 end |
#hosts_for(group) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/deployinator/helpers/dsh.rb', line 39 def hosts_for(group) @hosts_for ||= {} @hosts_for[group] ||= begin dsh_file = "/home/#{Deployinator.default_user}/.dsh/group/#{group}" hosts = `ssh #{Deployinator.default_user}@#{Deployinator.deploy_host} cat #{dsh_file}`.chomp if $?.nil? || $?.exitstatus != 0 raise "DSH hosts file at #{Deployinator.deploy_host}:#{dsh_file} is likely missing!" end hosts.split("\n").delete_if { |x| x.lstrip[0..0] == "#" } end end |
#run_dsh(groups, cmd, only_stdout = true, &block) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/deployinator/helpers/dsh.rb', line 8 def run_dsh(groups, cmd, only_stdout=true, &block) groups = [groups] unless groups.is_a?(Array) dsh_groups = groups.map {|group| "-g #{group} "}.join("") cmd_return = run_cmd(%Q{ssh #{Deployinator.default_user}@#{Deployinator.deploy_host} dsh #{dsh_groups} -r ssh -F #{dsh_fanout} "#{cmd}"}, &block) if only_stdout cmd_return[:stdout] else cmd_return end end |
#run_dsh_extra(dsh_group, cmd, extra_opts, only_stdout = true, &block) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/deployinator/helpers/dsh.rb', line 29 def run_dsh_extra(dsh_group, cmd, extra_opts, only_stdout=true, &block) # runs dsh to a single group with extra args to dsh cmd_return = run_cmd(%Q{ssh #{Deployinator.default_user}@#{Deployinator.deploy_host} dsh -g #{dsh_group} -r ssh #{extra_opts} -F #{dsh_fanout} "#{cmd}"}, &block) if only_stdout cmd_return[:stdout] else cmd_return end end |
#run_dsh_hosts(hosts, cmd, extra_opts = '', only_stdout = true, &block) ⇒ Object
run dsh against a given host or array of hosts
20 21 22 23 24 25 26 27 |
# File 'lib/deployinator/helpers/dsh.rb', line 20 def run_dsh_hosts(hosts, cmd, extra_opts='', only_stdout=true, &block) hosts = [hosts] unless hosts.is_a?(Array) if extra_opts.length > 0 run_cmd %Q{ssh #{Deployinator.default_user}@#{Deployinator.deploy_host} 'dsh -m #{hosts.join(',')} -r ssh -F #{dsh_fanout} #{extra_opts} -- "#{cmd}"'}, &block else run_cmd %Q{ssh #{Deployinator.default_user}@#{Deployinator.deploy_host} 'dsh -m #{hosts.join(',')} -r ssh -F #{dsh_fanout} -- "#{cmd}"'}, &block end end |