puppet-pssh 0.1.2 → 0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/puppet-pssh.rb +24 -6
- metadata +1 -1
data/lib/puppet-pssh.rb
CHANGED
@@ -7,7 +7,7 @@ require 'colored'
|
|
7
7
|
|
8
8
|
module PuppetPSSH
|
9
9
|
|
10
|
-
VERSION = "0.
|
10
|
+
VERSION = "0.2"
|
11
11
|
|
12
12
|
if !defined? Log or Log.nil?
|
13
13
|
Log = Logger.new($stdout)
|
@@ -86,8 +86,16 @@ module PuppetPSSH
|
|
86
86
|
option "--[no-]host-key-verify", :flag, "Verify SSH host key", :default => true
|
87
87
|
option "--threads", "THREADS", "Use up to N threads", :default => 40
|
88
88
|
option "--cached-hostlist", :flag, "Use cached hostlist", :default => false
|
89
|
+
option ["-s","--splay"], :flag, "Wait a random piece of time", :default => false
|
90
|
+
option ["-e","--extra-args"], "EXTRA_ARGS", "parallel-ssh extra arguments"
|
91
|
+
option ["-l","--user"], "USER", "SSH user (parallel-ssh -l argument)", :default => 'root'
|
89
92
|
|
90
93
|
def execute
|
94
|
+
|
95
|
+
Log.info "SSH user: #{user}"
|
96
|
+
Log.info "Node log output path: #{node_output_path}"
|
97
|
+
Log.info "Max threads: #{threads}"
|
98
|
+
|
91
99
|
unless File.exist?(pssh_path)
|
92
100
|
Log.error "parallel-ssh command not found in #{pssh_path}."
|
93
101
|
Log.error "Install it or use --pssh-path argument."
|
@@ -129,7 +137,7 @@ module PuppetPSSH
|
|
129
137
|
unless nameserver.nil?
|
130
138
|
address = res.query(i).answer.first.address rescue next
|
131
139
|
end
|
132
|
-
f.puts "#{address}
|
140
|
+
f.puts "#{address}"
|
133
141
|
end
|
134
142
|
end
|
135
143
|
else
|
@@ -137,16 +145,26 @@ module PuppetPSSH
|
|
137
145
|
end
|
138
146
|
|
139
147
|
$stdout.sync = true
|
140
|
-
|
141
|
-
|
148
|
+
if splay?
|
149
|
+
Log.info "Using 30s splay"
|
150
|
+
command = "sleep `echo $[ ( $RANDOM % 30 ) + 1 ]`;" + command_list.join(' ')
|
151
|
+
else
|
152
|
+
command = command_list.join(' ')
|
153
|
+
end
|
142
154
|
Log.info "Running command '#{command}' with parallel-ssh..."
|
143
|
-
Log.info "Max threads: #{threads}"
|
144
155
|
ssh_opts = ''
|
156
|
+
extra_opts = "-l #{user} "
|
157
|
+
if extra_args
|
158
|
+
Log.info "Extra pssh arguments: #{extra_args}"
|
159
|
+
extra_opts << extra_args
|
160
|
+
end
|
145
161
|
unless host_key_verify?
|
146
162
|
Log.warn 'Disabled host key verification'
|
147
163
|
ssh_opts = '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
|
148
164
|
end
|
149
|
-
|
165
|
+
full_cmd = "#{pssh_path} #{extra_opts} -p #{threads} -o #{node_output_path} -t 300 -h #{hostlist_path} -x '#{ssh_opts}' " + "'#{command} 2>&1'"
|
166
|
+
Log.debug full_cmd
|
167
|
+
system full_cmd
|
150
168
|
end
|
151
169
|
end
|
152
170
|
|