dust-deploy 0.12.2 → 0.13.0
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/bin/dust +192 -66
- data/changelog.md +37 -0
- data/lib/dust.rb +1 -0
- data/lib/dust/messaging.rb +140 -0
- data/lib/dust/recipe.rb +4 -1
- data/lib/dust/recipes/aliases.rb +5 -5
- data/lib/dust/recipes/apt.rb +4 -4
- data/lib/dust/recipes/cjdroute.rb +32 -35
- data/lib/dust/recipes/cups_client.rb +5 -5
- data/lib/dust/recipes/debsecan.rb +4 -4
- data/lib/dust/recipes/duplicity.rb +13 -15
- data/lib/dust/recipes/etc_hosts.rb +3 -3
- data/lib/dust/recipes/hash_check.rb +5 -6
- data/lib/dust/recipes/iptables.rb +12 -17
- data/lib/dust/recipes/limits.rb +19 -11
- data/lib/dust/recipes/locale.rb +14 -14
- data/lib/dust/recipes/logrotate.rb +3 -3
- data/lib/dust/recipes/make.rb +29 -0
- data/lib/dust/recipes/motd.rb +3 -3
- data/lib/dust/recipes/mysql.rb +5 -5
- data/lib/dust/recipes/newrelic.rb +6 -6
- data/lib/dust/recipes/nginx.rb +10 -10
- data/lib/dust/recipes/ntpd.rb +2 -6
- data/lib/dust/recipes/pacemaker.rb +3 -3
- data/lib/dust/recipes/postgres.rb +22 -22
- data/lib/dust/recipes/rc_local.rb +8 -8
- data/lib/dust/recipes/redis.rb +3 -25
- data/lib/dust/recipes/repositories.rb +28 -30
- data/lib/dust/recipes/resolv_conf.rb +16 -16
- data/lib/dust/recipes/ruby_rvm.rb +17 -18
- data/lib/dust/recipes/skel.rb +1 -2
- data/lib/dust/recipes/ssh_authorized_keys.rb +4 -5
- data/lib/dust/recipes/sshd.rb +1 -1
- data/lib/dust/recipes/sudoers.rb +2 -2
- data/lib/dust/recipes/sysctl.rb +12 -8
- data/lib/dust/recipes/zabbix_agent.rb +28 -28
- data/lib/dust/server.rb +114 -115
- data/lib/dust/version.rb +1 -1
- metadata +4 -2
@@ -1,13 +1,13 @@
|
|
1
1
|
class ZabbixAgent < Recipe
|
2
2
|
desc 'zabbix_agent:deploy', 'installs and configures zabbix agent'
|
3
|
-
def deploy
|
3
|
+
def deploy
|
4
4
|
return unless install_zabbix
|
5
|
-
|
5
|
+
|
6
6
|
# set daemon name, according zu distribution
|
7
7
|
daemon = @node.uses_emerge? ? 'zabbix-agentd' : 'zabbix-agent'
|
8
|
-
|
8
|
+
|
9
9
|
@node.write '/etc/zabbix/zabbix_agentd.conf', generate_zabbix_agentd_conf
|
10
|
-
|
10
|
+
|
11
11
|
# restart using new configuration
|
12
12
|
@node.autostart_service daemon
|
13
13
|
@node.restart_service daemon if options.restart?
|
@@ -19,19 +19,19 @@ class ZabbixAgent < Recipe
|
|
19
19
|
return unless @node.package_installed? daemon
|
20
20
|
@node.print_service_status daemon
|
21
21
|
end
|
22
|
-
|
23
|
-
|
22
|
+
|
23
|
+
|
24
24
|
private
|
25
25
|
# installs zabbix and its dependencies
|
26
26
|
def install_zabbix
|
27
27
|
|
28
28
|
if @node.uses_apt?
|
29
|
-
# debsecan is needed for zabbix checks (security updates)
|
29
|
+
# debsecan is needed for zabbix checks (security updates)
|
30
30
|
return false unless @node.install_package 'zabbix-agent'
|
31
31
|
return false unless @node.install_package 'debsecan'
|
32
32
|
|
33
33
|
elsif @node.uses_emerge?
|
34
|
-
# glsa-check (part of gentoolkit) is needed for zabbix checks (security updates)
|
34
|
+
# glsa-check (part of gentoolkit) is needed for zabbix checks (security updates)
|
35
35
|
return false unless @node.install_package 'zabbix', :env => 'USE=agent'
|
36
36
|
return false unless @node.install_package 'gentoolkit'
|
37
37
|
|
@@ -39,17 +39,17 @@ class ZabbixAgent < Recipe
|
|
39
39
|
return false unless @node.install_package 'zabbix-agent'
|
40
40
|
|
41
41
|
else
|
42
|
-
|
43
|
-
|
42
|
+
msg = @node.messages.add('os not supported')
|
43
|
+
msg.failed
|
44
44
|
return false
|
45
45
|
end
|
46
46
|
|
47
47
|
true
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
# generate zabbix_agentd.conf
|
51
51
|
def generate_zabbix_agentd_conf
|
52
|
-
@config = default_config.merge @config
|
52
|
+
@config = default_config.merge @config
|
53
53
|
|
54
54
|
@config['UserParameter'] = Array @config['UserParameter']
|
55
55
|
|
@@ -57,37 +57,37 @@ class ZabbixAgent < Recipe
|
|
57
57
|
@config['UserParameter'] |= enable_apt if @node.uses_apt?
|
58
58
|
@config['UserParameter'] |= enable_rpm if @node.uses_rpm?
|
59
59
|
@config['UserParameter'] |= enable_emerge if @node.uses_emerge?
|
60
|
-
|
60
|
+
|
61
61
|
# additional monitoring (raid status and postgresql)
|
62
62
|
@config['UserParameter'] |= enable_postgres if @node.package_installed? [ 'postgresql-server', 'postgresql' ], :quiet => true
|
63
63
|
@config['UserParameter'] |= enable_arcconf if @node.package_installed? 'arcconf', :quiet => true
|
64
|
-
|
64
|
+
|
65
65
|
zabbix_agentd_conf = ''
|
66
|
-
|
66
|
+
|
67
67
|
# add normal configuration variables
|
68
68
|
@config.each do |key, value|
|
69
69
|
next if key == 'UserParameter'
|
70
70
|
zabbix_agentd_conf << "#{key}=#{value}\n"
|
71
|
-
end
|
72
|
-
|
71
|
+
end
|
72
|
+
|
73
73
|
# add user parameters
|
74
74
|
@config['UserParameter'].each do |user_parameter|
|
75
75
|
zabbix_agentd_conf << "UserParameter=#{user_parameter}\n"
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
zabbix_agentd_conf
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
# default zabbix_agentd.conf configuration options
|
82
82
|
def default_config
|
83
|
-
defaults = {
|
83
|
+
defaults = {
|
84
84
|
'StartAgents' => 5,
|
85
85
|
'DebugLevel' => 3,
|
86
86
|
'Timeout' => 30,
|
87
87
|
'Hostname' => @node['fqdn'],
|
88
88
|
'UserParameter' => []
|
89
89
|
}
|
90
|
-
|
90
|
+
|
91
91
|
if @node.uses_apt?
|
92
92
|
defaults['PidFile'] ||= '/var/run/zabbix-agent/zabbix_agentd.pid'
|
93
93
|
defaults['LogFile'] ||= '/var/log/zabbix-agent/zabbix_agentd.log'
|
@@ -95,10 +95,10 @@ class ZabbixAgent < Recipe
|
|
95
95
|
defaults['PidFile'] ||= '/var/run/zabbix/zabbix_agentd.pid'
|
96
96
|
defaults['LogFile'] ||= '/var/log/zabbix/zabbix_agentd.log'
|
97
97
|
end
|
98
|
-
|
98
|
+
|
99
99
|
defaults
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
# monitor postgres database
|
103
103
|
def enable_postgres
|
104
104
|
[ 'psql.version,psql --version|head -n1',
|
@@ -120,22 +120,22 @@ class ZabbixAgent < Recipe
|
|
120
120
|
def enable_arcconf
|
121
121
|
[ 'raid.smart_warnings,/sbin/arcconf getconfig 1 pd |grep "S.M.A.R.T. warnings" | awk "{SMART += $4} END {print SMART}"',
|
122
122
|
'raid.disk_rpm,/sbin/arcconf getconfig 1 pd |grep "Power State" |grep -v "Full rpm" |wc -l',
|
123
|
-
'raid.disk_state,/sbin/arcconf getconfig 1 pd |grep "\s\sState" |grep -v "Online" |wc -l'
|
123
|
+
'raid.disk_state,/sbin/arcconf getconfig 1 pd |grep "\s\sState" |grep -v "Online" |wc -l'
|
124
124
|
]
|
125
125
|
end
|
126
|
-
|
127
|
-
# check for security patches and system updates on emerge systems
|
126
|
+
|
127
|
+
# check for security patches and system updates on emerge systems
|
128
128
|
def enable_apt
|
129
129
|
[ 'debian.updates,aptitude search \'~U\' |wc -l',
|
130
130
|
'debian.security,debsecan --suite squeeze --only-fixed --format packages |wc -l'
|
131
131
|
]
|
132
132
|
end
|
133
133
|
|
134
|
-
# check for security patches and system updates on emerge systems
|
134
|
+
# check for security patches and system updates on emerge systems
|
135
135
|
def enable_rpm
|
136
136
|
[ 'centos.updates,yum check-update -q |wc -l' ]
|
137
137
|
end
|
138
|
-
|
138
|
+
|
139
139
|
# check for security patches and system updates on emerge systems
|
140
140
|
def enable_emerge
|
141
141
|
[ 'gentoo.security,glsa-check -t all 2>/dev/null | wc -l',
|
data/lib/dust/server.rb
CHANGED
@@ -4,10 +4,11 @@ require 'net/scp'
|
|
4
4
|
require 'net/ssh/proxy/socks5'
|
5
5
|
require 'erb'
|
6
6
|
require 'tempfile'
|
7
|
+
require 'colorize'
|
7
8
|
|
8
9
|
module Dust
|
9
10
|
class Server
|
10
|
-
attr_reader :ssh
|
11
|
+
attr_reader :ssh, :messages
|
11
12
|
|
12
13
|
def default_options options = {}
|
13
14
|
{ :quiet => false, :indent => 1 }.merge options
|
@@ -19,15 +20,18 @@ module Dust
|
|
19
20
|
@node['port'] ||= 22
|
20
21
|
@node['password'] ||= ''
|
21
22
|
@node['sudo'] ||= false
|
23
|
+
|
24
|
+
@messages = Messages.new
|
22
25
|
end
|
23
26
|
|
24
27
|
def connect
|
25
|
-
|
28
|
+
messages.print_hostname_header(@node['hostname']) unless $parallel
|
29
|
+
|
26
30
|
begin
|
27
31
|
# connect to proxy if given
|
28
32
|
if @node['proxy']
|
29
33
|
host, port = @node['proxy'].split ':'
|
30
|
-
proxy = Net::SSH::Proxy::SOCKS5.new
|
34
|
+
proxy = Net::SSH::Proxy::SOCKS5.new(host, port)
|
31
35
|
else
|
32
36
|
proxy = nil
|
33
37
|
end
|
@@ -38,8 +42,8 @@ module Dust
|
|
38
42
|
:proxy => proxy }
|
39
43
|
rescue Exception
|
40
44
|
error_message = "coudln't connect to #{@node['fqdn']}"
|
41
|
-
error_message
|
42
|
-
|
45
|
+
error_message << " (via socks5 proxy #{@node['proxy']})" if proxy
|
46
|
+
messages.add(error_message, :indent => 0).failed
|
43
47
|
return false
|
44
48
|
end
|
45
49
|
|
@@ -57,6 +61,9 @@ module Dust
|
|
57
61
|
exit_code = nil
|
58
62
|
exit_signal = nil
|
59
63
|
|
64
|
+
# prepend a newline, if output is live
|
65
|
+
messages.add("\n", :indent => 0) if options[:live]
|
66
|
+
|
60
67
|
@ssh.open_channel do |channel|
|
61
68
|
|
62
69
|
# if :as_user => user is given, execute as user (be aware of ' usage)
|
@@ -84,13 +91,13 @@ module Dust
|
|
84
91
|
sudo_authenticated = true
|
85
92
|
else
|
86
93
|
stdout += data
|
87
|
-
|
94
|
+
messages.add(data.green, :indent => 0) if options[:live] and not data.empty?
|
88
95
|
end
|
89
96
|
end
|
90
97
|
|
91
98
|
channel.on_extended_data do |ch, type, data|
|
92
99
|
stderr += data
|
93
|
-
|
100
|
+
messages.add(data.red, :indent => 0) if options[:live] and not data.empty?
|
94
101
|
end
|
95
102
|
|
96
103
|
channel.on_request('exit-status') { |ch, data| exit_code = data.read_long }
|
@@ -109,13 +116,13 @@ module Dust
|
|
109
116
|
def write destination, content, options = {}
|
110
117
|
options = default_options.merge options
|
111
118
|
|
112
|
-
|
119
|
+
msg = messages.add("deploying #{File.basename destination}", options)
|
113
120
|
|
114
121
|
f = Tempfile.new 'dust-write'
|
115
122
|
f.print content
|
116
123
|
f.close
|
117
124
|
|
118
|
-
ret =
|
125
|
+
ret = msg.parse_result(scp(f.path, destination, :quiet => true))
|
119
126
|
f.unlink
|
120
127
|
|
121
128
|
ret
|
@@ -124,12 +131,12 @@ module Dust
|
|
124
131
|
def append destination, newcontent, options = {}
|
125
132
|
options = default_options.merge options
|
126
133
|
|
127
|
-
|
134
|
+
messages.add("appending to #{File.basename destination}", options)
|
128
135
|
|
129
136
|
content = exec("cat #{destination}")[:stdout]
|
130
137
|
content.concat newcontent
|
131
138
|
|
132
|
-
|
139
|
+
msg.parse_result(write(destination, content, :quiet => true))
|
133
140
|
end
|
134
141
|
|
135
142
|
def scp source, destination, options = {}
|
@@ -138,7 +145,7 @@ module Dust
|
|
138
145
|
# make sure scp is installed on client
|
139
146
|
install_package 'openssh-clients', :quiet => true if uses_rpm?
|
140
147
|
|
141
|
-
|
148
|
+
msg = messages.add("deploying #{File.basename source}", options)
|
142
149
|
|
143
150
|
# save permissions if the file already exists
|
144
151
|
ret = exec "stat -c %a:%u:%g #{destination}"
|
@@ -153,7 +160,7 @@ module Dust
|
|
153
160
|
if @node['sudo']
|
154
161
|
ret = exec 'mktemp --tmpdir dust.XXXXXXXXXX'
|
155
162
|
if ret[:exit_code] != 0
|
156
|
-
|
163
|
+
msg.failed('could not create temporary file (needed for sudo)')
|
157
164
|
return false
|
158
165
|
end
|
159
166
|
|
@@ -164,11 +171,11 @@ module Dust
|
|
164
171
|
chown @node['user'], tmpfile, :quiet => true
|
165
172
|
@ssh.scp.upload! source, tmpfile
|
166
173
|
chown 'root', tmpfile, :quiet => true
|
167
|
-
|
174
|
+
msg.parse_result(exec("mv -f #{tmpfile} #{destination}")[:exit_code])
|
168
175
|
|
169
176
|
else
|
170
177
|
@ssh.scp.upload! source, destination
|
171
|
-
|
178
|
+
msg.ok
|
172
179
|
end
|
173
180
|
|
174
181
|
# set file permissions
|
@@ -185,15 +192,15 @@ module Dust
|
|
185
192
|
# make sure scp is installed on client
|
186
193
|
install_package 'openssh-clients', :quiet => true if uses_rpm?
|
187
194
|
|
188
|
-
|
189
|
-
|
195
|
+
msg = messages.add("downloading #{File.basename source}", options)
|
196
|
+
msg.parse_result(@ssh.scp.download!(source, destination))
|
190
197
|
end
|
191
198
|
|
192
199
|
def symlink source, destination, options = {}
|
193
200
|
options = default_options.merge options
|
194
201
|
|
195
|
-
|
196
|
-
ret =
|
202
|
+
msg = messages.add("symlinking #{File.basename source} to '#{destination}'", options)
|
203
|
+
ret = msg.parse_result(exec("ln -s #{source} #{destination}")[:exit_code])
|
197
204
|
restorecon destination, options # restore SELinux labels
|
198
205
|
ret
|
199
206
|
end
|
@@ -201,22 +208,22 @@ module Dust
|
|
201
208
|
def chmod mode, file, options = {}
|
202
209
|
options = default_options.merge options
|
203
210
|
|
204
|
-
|
205
|
-
|
211
|
+
msg = messages.add("setting mode of #{File.basename file} to #{mode}", options)
|
212
|
+
msg.parse_result(exec("chmod -R #{mode} #{file}")[:exit_code])
|
206
213
|
end
|
207
214
|
|
208
215
|
def chown user, file, options = {}
|
209
216
|
options = default_options.merge options
|
210
217
|
|
211
|
-
|
212
|
-
|
218
|
+
msg = messages.add("setting owner of #{File.basename file} to #{user}", options)
|
219
|
+
msg.parse_result(exec("chown -R #{user} #{file}")[:exit_code])
|
213
220
|
end
|
214
221
|
|
215
222
|
def rm file, options = {}
|
216
223
|
options = default_options.merge options
|
217
224
|
|
218
|
-
|
219
|
-
|
225
|
+
msg = messages.add("deleting #{file}", options)
|
226
|
+
msg.parse_result(exec("rm -rf #{file}")[:exit_code])
|
220
227
|
end
|
221
228
|
|
222
229
|
def cp source, destination, options = {}
|
@@ -225,8 +232,8 @@ module Dust
|
|
225
232
|
# get rid of overly careful aliases
|
226
233
|
exec 'unalias -a'
|
227
234
|
|
228
|
-
|
229
|
-
|
235
|
+
msg = messages.add("copying #{source} to #{destination}", options)
|
236
|
+
msg.parse_result(exec("cp -a #{source} #{destination}")[:exit_code])
|
230
237
|
end
|
231
238
|
|
232
239
|
def mv source, destination, options = {}
|
@@ -235,8 +242,8 @@ module Dust
|
|
235
242
|
# get rid of overly careful aliases
|
236
243
|
exec 'unalias -a'
|
237
244
|
|
238
|
-
|
239
|
-
|
245
|
+
msg = messages.add("moving #{source} to #{destination}", options)
|
246
|
+
msg.parse_result(exec("mv #{source} #{destination}")[:exit_code])
|
240
247
|
end
|
241
248
|
|
242
249
|
def mkdir dir, options = {}
|
@@ -244,8 +251,8 @@ module Dust
|
|
244
251
|
|
245
252
|
return true if dir_exists? dir, :quiet => true
|
246
253
|
|
247
|
-
|
248
|
-
ret =
|
254
|
+
msg = messages.add("creating directory #{dir}", options)
|
255
|
+
ret = msg.parse_result(exec("mkdir -p #{dir}")[:exit_code])
|
249
256
|
restorecon dir, options # restore SELinux labels
|
250
257
|
ret
|
251
258
|
end
|
@@ -259,16 +266,16 @@ module Dust
|
|
259
266
|
ret = exec 'which restorecon'
|
260
267
|
return true unless ret[:exit_code] == 0
|
261
268
|
|
262
|
-
|
263
|
-
|
269
|
+
msg = messages.add("restoring selinux labels for #{path}", options)
|
270
|
+
msg.parse_result(exec("#{ret[:stdout].chomp} -R #{path}")[:exit_code])
|
264
271
|
end
|
265
272
|
|
266
273
|
def get_system_users options = {}
|
267
274
|
options = default_options.merge options
|
268
275
|
|
269
|
-
|
276
|
+
msg = messages.add("getting all system users", options)
|
270
277
|
ret = exec 'getent passwd |cut -d: -f1'
|
271
|
-
|
278
|
+
msg.parse_result(ret[:exit_code])
|
272
279
|
|
273
280
|
users = []
|
274
281
|
ret[:stdout].each do |user|
|
@@ -283,23 +290,23 @@ module Dust
|
|
283
290
|
|
284
291
|
packages = [ packages ] if packages.is_a? String
|
285
292
|
|
286
|
-
|
293
|
+
msg = messages.add("checking if #{packages.join(' or ')} is installed", options)
|
287
294
|
|
288
295
|
packages.each do |package|
|
289
296
|
if uses_apt?
|
290
|
-
return
|
297
|
+
return msg.ok if exec("dpkg -l #{package} |grep '^ii'")[:exit_code] == 0
|
291
298
|
elsif uses_emerge?
|
292
|
-
return
|
299
|
+
return msg.ok unless exec("qlist -I #{package}")[:stdout].empty?
|
293
300
|
elsif uses_rpm?
|
294
|
-
return
|
301
|
+
return msg.ok if exec("rpm -q #{package}")[:exit_code] == 0
|
295
302
|
elsif uses_pacman?
|
296
|
-
return
|
303
|
+
return msg.ok if exec("pacman -Q #{package}")[:exit_code] == 0
|
297
304
|
elsif uses_opkg?
|
298
|
-
return
|
305
|
+
return msg.ok unless exec("opkg status #{package}")[:stdout].empty?
|
299
306
|
end
|
300
307
|
end
|
301
308
|
|
302
|
-
|
309
|
+
msg.failed
|
303
310
|
end
|
304
311
|
|
305
312
|
def install_package package, options = {}
|
@@ -307,10 +314,10 @@ module Dust
|
|
307
314
|
options[:env] ||= ''
|
308
315
|
|
309
316
|
if package_installed? package, :quiet => true
|
310
|
-
return
|
317
|
+
return messages.add("package #{package} already installed", options).ok
|
311
318
|
end
|
312
319
|
|
313
|
-
|
320
|
+
msg = messages.add("installing #{package}", options)
|
314
321
|
|
315
322
|
if uses_apt?
|
316
323
|
exec "DEBIAN_FRONTEND=noninteractive aptitude install -y #{package}"
|
@@ -323,43 +330,40 @@ module Dust
|
|
323
330
|
elsif uses_opkg?
|
324
331
|
exec "opkg install #{package}"
|
325
332
|
else
|
326
|
-
|
327
|
-
return Dust.print_failed "install_package only supports apt, emerge and yum systems at the moment",
|
328
|
-
{ :quiet => options[:quiet], :indent => options[:indent] + 1 }
|
333
|
+
return msg.failed("install_package only supports apt, emerge and yum systems at the moment")
|
329
334
|
end
|
330
335
|
|
331
336
|
# check if package actually was installed
|
332
|
-
|
337
|
+
msg.parse_result(package_installed?(package, :quiet => true))
|
333
338
|
end
|
334
339
|
|
335
340
|
def remove_package package, options = {}
|
336
341
|
options = default_options.merge options
|
337
342
|
|
338
343
|
unless package_installed? package, :quiet => true
|
339
|
-
return
|
344
|
+
return messages.add("package #{package} not installed", options).ok
|
340
345
|
end
|
341
346
|
|
342
|
-
|
347
|
+
msg = messages.add("removing #{package}", options)
|
343
348
|
if uses_apt?
|
344
|
-
|
349
|
+
msg.parse_result(exec("DEBIAN_FRONTEND=noninteractive aptitude purge -y #{package}")[:exit_code])
|
345
350
|
elsif uses_emerge?
|
346
|
-
|
351
|
+
msg.parse_result(exec("emerge --unmerge #{package}")[:exit_code])
|
347
352
|
elsif uses_rpm?
|
348
|
-
|
353
|
+
msg.parse_result(exec("yum erase -y #{package}")[:exit_code])
|
349
354
|
elsif uses_pacman?
|
350
|
-
|
355
|
+
msg.parse_result(exec("echo y |pacman -R #{package}")[:exit_code])
|
351
356
|
elsif uses_opkg?
|
352
|
-
|
357
|
+
msg.parse_result(exec("opkg remove #{package}")[:exit_code])
|
353
358
|
else
|
354
|
-
|
359
|
+
msg.failed
|
355
360
|
end
|
356
361
|
end
|
357
362
|
|
358
363
|
def update_repos options = {}
|
359
364
|
options = default_options.merge options
|
360
365
|
|
361
|
-
|
362
|
-
puts if options[:live]
|
366
|
+
msg = messages.add('updating system repositories', options)
|
363
367
|
|
364
368
|
if uses_apt?
|
365
369
|
ret = exec 'aptitude update', options
|
@@ -376,13 +380,11 @@ module Dust
|
|
376
380
|
elsif uses_opkg?
|
377
381
|
ret = exec 'opkg update', options
|
378
382
|
else
|
379
|
-
return
|
383
|
+
return msg.failed
|
380
384
|
end
|
381
385
|
|
382
|
-
|
383
|
-
|
384
|
-
else
|
385
|
-
Dust.print_result ret[:exit_code], options
|
386
|
+
unless options[:live]
|
387
|
+
msg.parse_result(ret[:exit_code])
|
386
388
|
end
|
387
389
|
|
388
390
|
ret[:exit_code]
|
@@ -393,8 +395,7 @@ module Dust
|
|
393
395
|
|
394
396
|
update_repos
|
395
397
|
|
396
|
-
|
397
|
-
puts if options[:live]
|
398
|
+
msg = messages.add('installing system updates', options)
|
398
399
|
|
399
400
|
if uses_apt?
|
400
401
|
ret = exec 'DEBIAN_FRONTEND=noninteractive aptitude full-upgrade -y', options
|
@@ -409,14 +410,12 @@ module Dust
|
|
409
410
|
# upgrading openwrt is very experimental, and should not used normally
|
410
411
|
ret = exec 'opkg upgrade $(echo $(opkg list-upgradable |cut -d' ' -f1 |grep -v Multiple))', options
|
411
412
|
else
|
412
|
-
|
413
|
+
msg.failed('system not (yet) supported')
|
413
414
|
return false
|
414
415
|
end
|
415
416
|
|
416
|
-
|
417
|
-
|
418
|
-
else
|
419
|
-
Dust.print_result ret[:exit_code], options
|
417
|
+
unless options[:live]
|
418
|
+
msg.parse_result(ret[:exit_code])
|
420
419
|
end
|
421
420
|
|
422
421
|
ret[:exit_code]
|
@@ -428,55 +427,55 @@ module Dust
|
|
428
427
|
options = default_options(:quiet => true).merge options
|
429
428
|
|
430
429
|
return @uses_apt if defined? @uses_apt
|
431
|
-
|
432
|
-
@uses_apt =
|
430
|
+
msg = messages.add('determining whether node uses apt', options)
|
431
|
+
@uses_apt = msg.parse_result(exec('test -e /etc/debian_version')[:exit_code])
|
433
432
|
end
|
434
433
|
|
435
434
|
def uses_rpm? options = {}
|
436
435
|
options = default_options(:quiet => true).merge options
|
437
436
|
|
438
437
|
return @uses_rpm if defined? @uses_rpm
|
439
|
-
|
440
|
-
@uses_rpm =
|
438
|
+
msg = messages.add('determining whether node uses rpm', options)
|
439
|
+
@uses_rpm = msg.parse_result(exec('test -e /etc/redhat-release')[:exit_code])
|
441
440
|
end
|
442
441
|
|
443
442
|
def uses_emerge? options = {}
|
444
443
|
options = default_options(:quiet => true).merge options
|
445
444
|
|
446
445
|
return @uses_emerge if defined? @uses_emerge
|
447
|
-
|
448
|
-
@uses_emerge =
|
446
|
+
msg = messages.add('determining whether node uses emerge', options)
|
447
|
+
@uses_emerge = msg.parse_result(exec('test -e /etc/gentoo-release')[:exit_code])
|
449
448
|
end
|
450
449
|
|
451
450
|
def uses_pacman? options = {}
|
452
451
|
options = default_options(:quiet => true).merge options
|
453
452
|
|
454
453
|
return @uses_pacman if defined? @uses_pacman
|
455
|
-
|
456
|
-
@uses_pacman =
|
454
|
+
msg = messages.add('determining whether node uses pacman', options)
|
455
|
+
@uses_pacman = msg.parse_result(exec('test -e /etc/arch-release')[:exit_code])
|
457
456
|
end
|
458
457
|
|
459
458
|
def uses_opkg? options = {}
|
460
459
|
options = default_options(:quiet => true).merge options
|
461
460
|
|
462
461
|
return @uses_opkg if defined? @uses_opkg
|
463
|
-
|
464
|
-
@uses_opkg =
|
462
|
+
msg = messages.add('determining whether node uses opkg', options)
|
463
|
+
@uses_opkg = msg.parse_result(exec('test -e /etc/opkg.conf')[:exit_code])
|
465
464
|
end
|
466
465
|
|
467
466
|
def is_os? os_list, options = {}
|
468
467
|
options = default_options(:quiet => true).merge options
|
469
468
|
|
470
|
-
|
471
|
-
return
|
469
|
+
msg = messages.add("checking if this machine runs #{os_list.join(' or ')}", options)
|
470
|
+
return msg.failed unless collect_facts options
|
472
471
|
|
473
472
|
os_list.each do |os|
|
474
473
|
if @node['operatingsystem'].downcase == os.downcase
|
475
|
-
return
|
474
|
+
return msg.ok
|
476
475
|
end
|
477
476
|
end
|
478
477
|
|
479
|
-
|
478
|
+
msg.failed
|
480
479
|
false
|
481
480
|
end
|
482
481
|
|
@@ -532,47 +531,47 @@ module Dust
|
|
532
531
|
def is_executable? file, options = {}
|
533
532
|
options = default_options.merge options
|
534
533
|
|
535
|
-
|
536
|
-
|
534
|
+
msg = messages.add("checking if file #{file} exists and is executeable", options)
|
535
|
+
msg.parse_result(exec("test -x $(which #{file})")[:exit_code])
|
537
536
|
end
|
538
537
|
|
539
538
|
def file_exists? file, options = {}
|
540
539
|
options = default_options.merge options
|
541
540
|
|
542
|
-
|
543
|
-
|
541
|
+
msg = messages.add("checking if file #{file} exists", options)
|
542
|
+
msg.parse_result(exec("test -e #{file}")[:exit_code])
|
544
543
|
end
|
545
544
|
|
546
545
|
def dir_exists? dir, options = {}
|
547
546
|
options = default_options.merge options
|
548
547
|
|
549
|
-
|
550
|
-
|
548
|
+
msg = messages.add("checking if directory #{dir} exists", options)
|
549
|
+
msg.parse_result(exec("test -d #{dir}")[:exit_code])
|
551
550
|
end
|
552
551
|
|
553
552
|
def autostart_service service, options = {}
|
554
553
|
options = default_options.merge options
|
555
554
|
|
556
|
-
|
555
|
+
msg = messages.add("autostart #{service} on boot", options)
|
557
556
|
|
558
557
|
if uses_rpm?
|
559
558
|
if file_exists? '/bin/systemctl', :quiet => true
|
560
|
-
|
559
|
+
msg.parse_result(exec("systemctl enable #{service}.service")[:exit_code])
|
561
560
|
else
|
562
|
-
|
561
|
+
msg.parse_result(exec("chkconfig #{service} on")[:exit_code])
|
563
562
|
end
|
564
563
|
|
565
564
|
elsif uses_apt?
|
566
|
-
|
565
|
+
msg.parse_result(exec("update-rc.d #{service} defaults")[:exit_code])
|
567
566
|
|
568
567
|
elsif uses_emerge?
|
569
|
-
|
568
|
+
msg.parse_result(exec("rc-update add #{service} default")[:exit_code])
|
570
569
|
|
571
570
|
# archlinux needs his autostart daemons in /etc/rc.conf, in the DAEMONS line
|
572
571
|
#elsif uses_pacman?
|
573
572
|
|
574
573
|
else
|
575
|
-
|
574
|
+
msg.failed
|
576
575
|
end
|
577
576
|
end
|
578
577
|
|
@@ -580,31 +579,31 @@ module Dust
|
|
580
579
|
def service service, command, options = {}
|
581
580
|
options = default_options.merge options
|
582
581
|
|
583
|
-
return
|
582
|
+
return messages.add("service: '#{service}' unknown", options).failed unless service.is_a? String
|
584
583
|
|
585
584
|
# try systemd, then upstart, then sysvconfig, then rc.d, then initscript
|
586
585
|
if file_exists? '/bin/systemctl', :quiet => true
|
587
|
-
|
586
|
+
msg = messages.add("#{command}ing #{service} (via systemd)", options)
|
588
587
|
ret = exec("systemctl #{command} #{service}.service")
|
589
588
|
|
590
589
|
elsif file_exists? "/etc/init/#{service}", :quiet => true
|
591
|
-
|
590
|
+
msg = messages.add("#{command}ing #{service} (via upstart)", options)
|
592
591
|
ret = exec("#{command} #{service}")
|
593
592
|
|
594
593
|
elsif file_exists? '/sbin/service', :quiet => true or file_exists? '/usr/sbin/service', :quiet => true
|
595
|
-
|
594
|
+
msg = messages.add("#{command}ing #{service} (via sysvconfig)", options)
|
596
595
|
ret = exec("service #{service} #{command}")
|
597
596
|
|
598
597
|
elsif file_exists? '/usr/sbin/rc.d', :quiet => true
|
599
|
-
|
598
|
+
msg = messages.add("#{command}ing #{service} (via rc.d)", options)
|
600
599
|
ret = exec("rc.d #{command} #{service}")
|
601
600
|
|
602
601
|
else
|
603
|
-
|
602
|
+
msg = messages.add("#{command}ing #{service} (via initscript)", options)
|
604
603
|
ret = exec("/etc/init.d/#{service} #{command}")
|
605
604
|
end
|
606
605
|
|
607
|
-
|
606
|
+
msg.parse_result(ret[:exit_code])
|
608
607
|
ret
|
609
608
|
end
|
610
609
|
|
@@ -623,7 +622,7 @@ module Dust
|
|
623
622
|
def print_service_status service, options = {}
|
624
623
|
options = default_options.merge options
|
625
624
|
ret = service service, 'status', options
|
626
|
-
|
625
|
+
messages.print_output(ret, options)
|
627
626
|
ret
|
628
627
|
end
|
629
628
|
|
@@ -631,8 +630,8 @@ module Dust
|
|
631
630
|
def user_exists? user, options = {}
|
632
631
|
options = default_options.merge options
|
633
632
|
|
634
|
-
|
635
|
-
|
633
|
+
msg = messages.add("checking if user #{user} exists", options)
|
634
|
+
msg.parse_result(exec("id #{user}")[:exit_code])
|
636
635
|
end
|
637
636
|
|
638
637
|
# create a user
|
@@ -643,20 +642,20 @@ module Dust
|
|
643
642
|
|
644
643
|
return true if user_exists? user, options
|
645
644
|
|
646
|
-
|
645
|
+
msg = messages.add("creating user #{user}", :indent => options[:indent])
|
647
646
|
cmd = "useradd #{user} -m"
|
648
647
|
cmd += " -d #{options[:home]}" if options[:home]
|
649
648
|
cmd += " -s #{options[:shell]}" if options[:shell]
|
650
|
-
|
649
|
+
msg.parse_result(exec(cmd)[:exit_code])
|
651
650
|
end
|
652
651
|
|
653
652
|
# returns the home directory of this user
|
654
653
|
def get_home user, options = {}
|
655
654
|
options = default_options(:quiet => true).merge options
|
656
655
|
|
657
|
-
|
656
|
+
msg = messages.add("getting home directory of #{user}", options)
|
658
657
|
ret = exec "getent passwd |cut -d':' -f1,6 |grep '^#{user}' |head -n1 |cut -d: -f2"
|
659
|
-
if
|
658
|
+
if msg.parse_result(ret[:exit_code])
|
660
659
|
return ret[:stdout].chomp
|
661
660
|
else
|
662
661
|
return false
|
@@ -667,9 +666,9 @@ module Dust
|
|
667
666
|
def get_shell user, options = {}
|
668
667
|
options = default_options(:quiet => true).merge options
|
669
668
|
|
670
|
-
|
669
|
+
msg = messages.add("getting shell of #{user}", options)
|
671
670
|
ret = exec "getent passwd |cut -d':' -f1,7 |grep '^#{user}' |head -n1 |cut -d: -f2"
|
672
|
-
if
|
671
|
+
if msg.parse_result(ret[:exit_code])
|
673
672
|
return ret[:stdout].chomp
|
674
673
|
else
|
675
674
|
return false
|
@@ -693,13 +692,13 @@ module Dust
|
|
693
692
|
return false unless install_package 'facter', :quiet => false
|
694
693
|
end
|
695
694
|
|
696
|
-
|
695
|
+
msg = messages.add("collecting additional system facts (using facter)", options)
|
697
696
|
|
698
697
|
# run facter with -y for yaml output, and merge results into @node
|
699
698
|
ret = exec 'facter -y'
|
700
699
|
@node.merge! YAML.load ret[:stdout]
|
701
700
|
|
702
|
-
|
701
|
+
msg.parse_result(ret[:exit_code])
|
703
702
|
end
|
704
703
|
|
705
704
|
# if file is a regular file, copy it using scp
|
@@ -715,7 +714,7 @@ module Dust
|
|
715
714
|
write destination, template.result(options[:binding]), options
|
716
715
|
|
717
716
|
else
|
718
|
-
|
717
|
+
messages.add("'#{file}' was not found.", options).failed
|
719
718
|
end
|
720
719
|
end
|
721
720
|
|