dust-deploy 0.2.3 → 0.3.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/README.md +12 -203
- data/bin/dust +58 -13
- data/changelog.md +13 -0
- data/lib/dust/examples/templates/postgres/pacemaker.sh.erb +1 -1
- data/lib/dust/examples/templates/zabbix_agent/zabbix_agentd.conf.erb +9 -9
- data/lib/dust/print_status.rb +30 -20
- data/lib/dust/recipes/aliases.rb +1 -1
- data/lib/dust/recipes/basic_setup.rb +12 -12
- data/lib/dust/recipes/debsecan.rb +4 -2
- data/lib/dust/recipes/duplicity.rb +8 -8
- data/lib/dust/recipes/etc_hosts.rb +1 -1
- data/lib/dust/recipes/iptables.rb +25 -18
- data/lib/dust/recipes/locale.rb +4 -4
- data/lib/dust/recipes/memory_limit.rb +1 -1
- data/lib/dust/recipes/mysql.rb +5 -5
- data/lib/dust/recipes/newrelic.rb +1 -1
- data/lib/dust/recipes/nginx.rb +3 -3
- data/lib/dust/recipes/postgres.rb +12 -10
- data/lib/dust/recipes/rc_local.rb +2 -2
- data/lib/dust/recipes/repositories.rb +13 -14
- data/lib/dust/recipes/resolv_conf.rb +4 -4
- data/lib/dust/recipes/ssh_authorized_keys.rb +4 -4
- data/lib/dust/recipes/zabbix_agent.rb +12 -12
- data/lib/dust/server.rb +204 -207
- data/lib/dust/version.rb +1 -1
- metadata +3 -3
@@ -13,25 +13,25 @@ class ResolvConf < Thor
|
|
13
13
|
|
14
14
|
# configures whether daily reports are sent
|
15
15
|
if config['search']
|
16
|
-
::Dust.print_msg "adding search #{config['search']}", 2
|
16
|
+
::Dust.print_msg "adding search #{config['search']}", :indent => 2
|
17
17
|
config_file += "search #{config['search']}\n"
|
18
18
|
::Dust.print_ok
|
19
19
|
end
|
20
20
|
|
21
21
|
if config['domain']
|
22
|
-
::Dust.print_msg "adding domain #{config['domain']}", 2
|
22
|
+
::Dust.print_msg "adding domain #{config['domain']}", :indent => 2
|
23
23
|
config_file += "domain #{config['domain']}\n"
|
24
24
|
::Dust.print_ok
|
25
25
|
end
|
26
26
|
|
27
27
|
if config['options']
|
28
|
-
::Dust.print_msg "adding options #{config['options']}", 2
|
28
|
+
::Dust.print_msg "adding options #{config['options']}", :indent => 2
|
29
29
|
config_file += "options #{config['options']}\n"
|
30
30
|
::Dust.print_ok
|
31
31
|
end
|
32
32
|
|
33
33
|
config['nameservers'].each do |nameserver|
|
34
|
-
::Dust.print_msg "adding nameserver #{nameserver}", 2
|
34
|
+
::Dust.print_msg "adding nameserver #{nameserver}", :indent => 2
|
35
35
|
config_file += "nameserver #{nameserver}\n"
|
36
36
|
::Dust.print_ok
|
37
37
|
end
|
@@ -16,7 +16,7 @@ class SshAuthorizedKeys < Thor
|
|
16
16
|
# create the authorized_keys hash for this user
|
17
17
|
ssh_users.each do |ssh_user|
|
18
18
|
users[ssh_user]['name'] ||= ssh_user
|
19
|
-
::Dust.print_msg "adding user #{users[ssh_user]['name']}", 2
|
19
|
+
::Dust.print_msg "adding user #{users[ssh_user]['name']}", :indent => 2
|
20
20
|
users[ssh_user]['keys'].each do |key|
|
21
21
|
authorized_keys += "#{key}"
|
22
22
|
authorized_keys += " #{users[ssh_user]['name']}" if users[ssh_user]['name']
|
@@ -45,10 +45,10 @@ class SshAuthorizedKeys < Thor
|
|
45
45
|
# remove authorized_keys files for all other users
|
46
46
|
if options.cleanup?
|
47
47
|
::Dust.print_msg "deleting other authorized_keys files\n"
|
48
|
-
node.get_system_users(true).each do |user|
|
48
|
+
node.get_system_users(:quiet => true).each do |user|
|
49
49
|
next if users.keys.include? user
|
50
|
-
if node.file_exists? "~#{user}/.ssh/authorized_keys", true
|
51
|
-
node.rm "~#{user}/.ssh/authorized_keys", 2
|
50
|
+
if node.file_exists? "~#{user}/.ssh/authorized_keys", :quiet => true
|
51
|
+
node.rm "~#{user}/.ssh/authorized_keys", :indent => 2
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
@@ -10,11 +10,11 @@ class ZabbixAgent < Thor
|
|
10
10
|
# configure node using erb template
|
11
11
|
template = ERB.new File.read("#{template_path}/zabbix_agentd.conf.erb"), nil, '%<>'
|
12
12
|
::Dust.print_msg 'adjusting and deploying zabbix_agentd.conf'
|
13
|
-
node.write '/etc/zabbix/zabbix_agentd.conf', template.result(binding), true
|
13
|
+
node.write '/etc/zabbix/zabbix_agentd.conf', template.result(binding), :quiet => true
|
14
14
|
::Dust.print_ok
|
15
15
|
|
16
16
|
# restart using new configuration
|
17
|
-
if node.uses_emerge? true
|
17
|
+
if node.uses_emerge? :quiet => true
|
18
18
|
node.autostart_service 'zabbix-agentd'
|
19
19
|
node.restart_service 'zabbix-agentd' if options.restart?
|
20
20
|
else
|
@@ -27,20 +27,20 @@ class ZabbixAgent < Thor
|
|
27
27
|
# installs zabbix and its dependencies
|
28
28
|
def install_zabbix node
|
29
29
|
|
30
|
-
if node.uses_apt?
|
31
|
-
return false unless node.install_package
|
30
|
+
if node.uses_apt?
|
31
|
+
return false unless node.install_package 'zabbix-agent'
|
32
32
|
|
33
33
|
# debsecan is needed for zabbix checks (security updates)
|
34
|
-
return false unless node.install_package
|
34
|
+
return false unless node.install_package 'debsecan'
|
35
35
|
|
36
|
-
elsif node.uses_emerge?
|
37
|
-
return false unless node.install_package
|
36
|
+
elsif node.uses_emerge?
|
37
|
+
return false unless node.install_package 'zabbix', :env => 'USE=agent'
|
38
38
|
|
39
39
|
# glsa-check (part of gentoolkit) is needed for zabbix checks (security updates)
|
40
|
-
return false unless node.install_package
|
40
|
+
return false unless node.install_package 'gentoolkit'
|
41
41
|
|
42
|
-
elsif node.uses_rpm?
|
43
|
-
return false unless node.install_package
|
42
|
+
elsif node.uses_rpm?
|
43
|
+
return false unless node.install_package 'zabbix-agent'
|
44
44
|
|
45
45
|
else
|
46
46
|
::Dust.print_msg 'os not supported'
|
@@ -54,7 +54,7 @@ class ZabbixAgent < Thor
|
|
54
54
|
# TODO (not yet finished)
|
55
55
|
desc 'zabbix_agent:postgres', 'configure postgres database for zabbix monitoring'
|
56
56
|
def postgres node, ingredients, options
|
57
|
-
next unless node.uses_emerge?
|
57
|
+
next unless node.uses_emerge? :quiet=>false
|
58
58
|
next unless node.package_installed?('postgresql-node')
|
59
59
|
|
60
60
|
::Dust.print_msg 'add zabbix system user to postgres group'
|
@@ -67,7 +67,7 @@ class ZabbixAgent < Thor
|
|
67
67
|
|
68
68
|
# if user was not found, create him
|
69
69
|
unless ret
|
70
|
-
::Dust.print_msg 'create zabbix user in postgres', 2
|
70
|
+
::Dust.print_msg 'create zabbix user in postgres', :indent => 2
|
71
71
|
::Dust.print_result( node.exec('createuser -U postgres zabbix -RSD')[:exit_code] )
|
72
72
|
end
|
73
73
|
|
data/lib/dust/server.rb
CHANGED
@@ -23,13 +23,17 @@ module Dust
|
|
23
23
|
Dust.print_hostname @attr['hostname']
|
24
24
|
begin
|
25
25
|
# connect to proxy if given
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
if @attr['proxy']
|
27
|
+
host, port = @attr['proxy'].split ':'
|
28
|
+
proxy = Net::SSH::Proxy::SOCKS5.new host, port
|
29
|
+
else
|
30
|
+
proxy = nil
|
31
|
+
end
|
32
|
+
|
33
|
+
@ssh = Net::SSH.start @attr['fqdn'], @attr['user'],
|
30
34
|
{ :password => @attr['password'],
|
31
35
|
:port => @attr['port'],
|
32
|
-
:proxy => proxy }
|
36
|
+
:proxy => proxy }
|
33
37
|
rescue Exception
|
34
38
|
error_message = " - coudln't connect to #{@attr['fqdn']}"
|
35
39
|
error_message += " (via socks5 proxy #{@attr['proxy']})" if proxy
|
@@ -45,31 +49,18 @@ module Dust
|
|
45
49
|
end
|
46
50
|
|
47
51
|
def exec command
|
48
|
-
stdout =
|
49
|
-
stderr =
|
52
|
+
stdout = ''
|
53
|
+
stderr = ''
|
50
54
|
exit_code = nil
|
51
55
|
exit_signal = nil
|
52
56
|
|
53
57
|
@ssh.open_channel do |channel|
|
54
|
-
channel.exec
|
55
|
-
unless success
|
56
|
-
|
57
|
-
|
58
|
-
channel.
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
channel.on_extended_data do |ch, type, data|
|
63
|
-
stderr += data
|
64
|
-
end
|
65
|
-
|
66
|
-
channel.on_request("exit-status") do |ch, data|
|
67
|
-
exit_code = data.read_long
|
68
|
-
end
|
69
|
-
|
70
|
-
channel.on_request("exit-signal") do |ch, data|
|
71
|
-
exit_signal = data.read_long
|
72
|
-
end
|
58
|
+
channel.exec command do |ch, success|
|
59
|
+
abort "FAILED: couldn't execute command (ssh.channel.exec)" unless success
|
60
|
+
channel.on_data { |ch, data| stdout += data }
|
61
|
+
channel.on_extended_data { |ch, type, data| stderr += data }
|
62
|
+
channel.on_request('exit-status') { |ch, data| exit_code = data.read_long }
|
63
|
+
channel.on_request('exit-signal') { |ch, data| exit_signal = data.read_long }
|
73
64
|
end
|
74
65
|
end
|
75
66
|
|
@@ -77,86 +68,83 @@ module Dust
|
|
77
68
|
|
78
69
|
{ :stdout => stdout, :stderr => stderr, :exit_code => exit_code, :exit_signal => exit_signal }
|
79
70
|
end
|
80
|
-
|
81
|
-
|
82
|
-
|
71
|
+
|
72
|
+
|
73
|
+
def write target, text, options={:quiet => false, :indent => 1}
|
74
|
+
Dust.print_msg "deploying #{File.basename target}", options
|
83
75
|
|
84
76
|
# escape $ signs and \ at the end of line
|
85
|
-
text.gsub!
|
86
|
-
text.gsub!
|
77
|
+
text.gsub! '$','\$'
|
78
|
+
text.gsub! /\\$/, '\\\\\\'
|
87
79
|
|
80
|
+
# note: ` (backticks) somehow cannot be escaped.. don't use them
|
81
|
+
# in bash, use $(cmd) instead of `cmd` as a workaround
|
88
82
|
if exec("cat << EOF > #{target}\n#{text}\nEOF")[:exit_code] != 0
|
89
|
-
|
83
|
+
Dust.print_failed '', options
|
84
|
+
return false
|
90
85
|
end
|
91
86
|
|
92
|
-
Dust.print_ok
|
93
|
-
restorecon
|
87
|
+
Dust.print_ok '', options
|
88
|
+
restorecon target, options # restore SELinux labels
|
94
89
|
end
|
95
90
|
|
96
|
-
def append target, text, quiet
|
97
|
-
Dust.print_msg
|
98
|
-
Dust.print_result
|
91
|
+
def append target, text, options={:quiet => false, :indent => 1}
|
92
|
+
Dust.print_msg "appending to #{File.basename target}", options
|
93
|
+
Dust.print_result exec("cat << EOF >> #{target}\n#{text}\nEOF")[:exit_code], options
|
99
94
|
end
|
100
95
|
|
101
|
-
def scp source, destination, quiet
|
102
|
-
Dust.print_msg
|
103
|
-
@ssh.scp.upload!
|
104
|
-
Dust.
|
105
|
-
restorecon
|
96
|
+
def scp source, destination, options={:quiet => false, :indent => 1}
|
97
|
+
Dust.print_msg "deploying #{File.basename(source)}", options
|
98
|
+
@ssh.scp.upload! source, destination
|
99
|
+
Dust.print_ok '', options
|
100
|
+
restorecon destination, options # restore SELinux labels
|
106
101
|
end
|
107
102
|
|
108
|
-
def symlink source, destination, quiet
|
109
|
-
Dust.print_msg
|
110
|
-
|
111
|
-
|
112
|
-
end
|
113
|
-
|
114
|
-
Dust.print_ok unless quiet
|
115
|
-
restorecon(destination, quiet, indent) # restore SELinux labels
|
103
|
+
def symlink source, destination, options={:quiet => false, :indent => 1}
|
104
|
+
Dust.print_msg "symlinking #{File.basename(source)} to '#{destination}'", options
|
105
|
+
Dust.print_result exec("ln -s #{source} #{destination}")[:exit_code], options
|
106
|
+
restorecon destination, options # restore SELinux labels
|
116
107
|
end
|
117
108
|
|
118
|
-
def chmod mode, file, quiet
|
119
|
-
Dust.print_msg
|
120
|
-
Dust.print_result
|
109
|
+
def chmod mode, file, options={:quiet => false, :indent => 1}
|
110
|
+
Dust.print_msg "setting mode of #{File.basename(file)} to #{mode}", options
|
111
|
+
Dust.print_result exec("chmod -R #{mode} #{file}")[:exit_code], options
|
121
112
|
end
|
122
113
|
|
123
|
-
def chown user, file, quiet
|
124
|
-
Dust.print_msg
|
125
|
-
Dust.print_result
|
114
|
+
def chown user, file, options={:quiet => false, :indent => 1}
|
115
|
+
Dust.print_msg "setting owner of #{File.basename(file)} to #{user}", options
|
116
|
+
Dust.print_result exec("chown -R #{user} #{file}")[:exit_code], options
|
126
117
|
end
|
127
118
|
|
128
|
-
def rm file, quiet
|
129
|
-
Dust.print_msg
|
130
|
-
Dust.print_result
|
119
|
+
def rm file, options={:quiet => false, :indent => 1}
|
120
|
+
Dust.print_msg "deleting #{file}", options
|
121
|
+
Dust.print_result exec("rm -rf #{file}")[:exit_code], options
|
131
122
|
end
|
132
123
|
|
133
|
-
def mkdir dir, quiet
|
134
|
-
return true if dir_exists? dir, true
|
135
|
-
Dust.print_msg("creating directory #{dir}", indent) unless quiet
|
136
|
-
if exec("mkdir -p #{dir}")[:exit_code] != 0
|
137
|
-
return Dust.print_result(false, quiet)
|
138
|
-
end
|
124
|
+
def mkdir dir, options={:quiet => false, :indent => 1}
|
125
|
+
return true if dir_exists? dir, :quiet => true
|
139
126
|
|
140
|
-
Dust.
|
141
|
-
|
127
|
+
Dust.print_msg "creating directory #{dir}", options
|
128
|
+
Dust.print_result exec("mkdir -p #{dir}")[:exit_code], options
|
129
|
+
restorecon dir, options # restore SELinux labels
|
142
130
|
end
|
143
131
|
|
144
132
|
# check if restorecon (selinux) is available
|
145
133
|
# if so, run it on "path" recursively
|
146
|
-
def restorecon path, quiet
|
134
|
+
def restorecon path, options={:quiet => false, :indent => 1}
|
147
135
|
|
148
136
|
# if restorecon is not installed, just return true
|
149
|
-
ret = exec
|
137
|
+
ret = exec 'which restorecon'
|
150
138
|
return true unless ret[:exit_code] == 0
|
151
139
|
|
152
|
-
Dust.print_msg
|
153
|
-
Dust.print_result
|
140
|
+
Dust.print_msg "restoring selinux labels for #{path}", options
|
141
|
+
Dust.print_result exec("#{ret[:stdout].chomp} -R #{path}")[:exit_code], options
|
154
142
|
end
|
155
143
|
|
156
|
-
def get_system_users quiet
|
157
|
-
Dust.print_msg
|
158
|
-
ret = exec
|
159
|
-
Dust.print_result ret[:exit_code]
|
144
|
+
def get_system_users options={:quiet => false, :indent => 1}
|
145
|
+
Dust.print_msg "getting all system users", options
|
146
|
+
ret = exec 'getent passwd |cut -d: -f1'
|
147
|
+
Dust.print_result ret[:exit_code], options
|
160
148
|
|
161
149
|
users = []
|
162
150
|
ret[:stdout].each do |user|
|
@@ -166,214 +154,223 @@ module Dust
|
|
166
154
|
end
|
167
155
|
|
168
156
|
# checks if one of the packages is installed
|
169
|
-
def package_installed? packages, quiet
|
170
|
-
packages = [ packages ] if packages.
|
157
|
+
def package_installed? packages, options={:quiet => false, :indent => 1}
|
158
|
+
packages = [ packages ] if packages.is_a? String
|
171
159
|
|
172
|
-
Dust.print_msg
|
160
|
+
Dust.print_msg "checking if #{packages.join(' or ')} is installed", options
|
173
161
|
|
174
162
|
packages.each do |package|
|
175
|
-
if uses_apt?
|
176
|
-
return Dust.
|
177
|
-
elsif uses_emerge?
|
178
|
-
return Dust.
|
179
|
-
elsif uses_rpm?
|
180
|
-
return Dust.
|
163
|
+
if uses_apt?
|
164
|
+
return Dust.print_ok '', options unless exec("dpkg -s #{package} |grep 'install ok'")[:stdout].empty?
|
165
|
+
elsif uses_emerge?
|
166
|
+
return Dust.print_ok '', options unless exec("qlist -I #{package}")[:stdout].empty?
|
167
|
+
elsif uses_rpm?
|
168
|
+
return Dust.print_ok '', options if exec("rpm -q #{package}")[:exit_code] == 0
|
181
169
|
end
|
182
170
|
end
|
183
171
|
|
184
|
-
Dust.
|
172
|
+
Dust.print_failed '', options
|
185
173
|
end
|
186
174
|
|
187
|
-
def install_package package, quiet
|
188
|
-
return true if package_installed? package,
|
189
|
-
|
190
|
-
Dust.print_msg
|
191
|
-
if uses_apt?
|
192
|
-
|
193
|
-
elsif uses_emerge?
|
194
|
-
|
195
|
-
elsif uses_rpm?
|
196
|
-
|
175
|
+
def install_package package, options={:quiet => false, :indent => 1, :env => ''}
|
176
|
+
return true if package_installed? package, options
|
177
|
+
|
178
|
+
Dust.print_msg "installing #{package}", {:quiet => options[:quiet], :indent => options[:indent] + 1}
|
179
|
+
if uses_apt?
|
180
|
+
exec "DEBIAN_FRONTEND=noninteractive aptitude install -y #{package}"
|
181
|
+
elsif uses_emerge?
|
182
|
+
exec "#{options[:env]} emerge #{package}"
|
183
|
+
elsif uses_rpm?
|
184
|
+
exec "yum install -y #{package}"
|
197
185
|
else
|
198
|
-
Dust.
|
186
|
+
Dust.print_failed 'install_package only supports apt, emerge and rpm systems at the moment'
|
199
187
|
end
|
188
|
+
|
189
|
+
# check if package actually was installed
|
190
|
+
Dust.print_result package_installed? package, :quiet => true
|
200
191
|
end
|
201
192
|
|
202
|
-
def remove_package package, quiet
|
203
|
-
|
193
|
+
def remove_package package, options={:quiet => false, :indent => 1}
|
194
|
+
unless package_installed? package, :quiet => true
|
195
|
+
return Dust.print_ok "package #{package} not installed", options
|
196
|
+
end
|
204
197
|
|
205
|
-
Dust.print_msg
|
206
|
-
if uses_apt?
|
207
|
-
Dust.print_result exec("DEBIAN_FRONTEND=noninteractive aptitude purge -y #{package}")[:exit_code],
|
208
|
-
elsif uses_emerge?
|
209
|
-
Dust.print_result exec("emerge --unmerge #{package}")[:exit_code],
|
210
|
-
elsif uses_rpm?
|
211
|
-
Dust.print_result exec("yum erase -y #{package}")[:exit_code],
|
198
|
+
Dust.print_msg "removing #{package}", options
|
199
|
+
if uses_apt?
|
200
|
+
Dust.print_result exec("DEBIAN_FRONTEND=noninteractive aptitude purge -y #{package}")[:exit_code], options
|
201
|
+
elsif uses_emerge?
|
202
|
+
Dust.print_result exec("emerge --unmerge #{package}")[:exit_code], options
|
203
|
+
elsif uses_rpm?
|
204
|
+
Dust.print_result exec("yum erase -y #{package}")[:exit_code], options
|
212
205
|
else
|
213
|
-
Dust.
|
206
|
+
Dust.print_failed '', options
|
214
207
|
end
|
215
208
|
end
|
216
209
|
|
217
|
-
def update_repos quiet
|
218
|
-
Dust.print_msg
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
210
|
+
def update_repos options={:quiet => false, :indent => 1}
|
211
|
+
Dust.print_msg 'updating system repositories', options
|
212
|
+
|
213
|
+
if uses_apt?
|
214
|
+
Dust.print_result exec('aptitude update')[:exit_code], options
|
215
|
+
elsif uses_emerge?
|
216
|
+
Dust.print_result exec('emerge --sync')[:exit_code], options
|
217
|
+
elsif uses_rpm?
|
218
|
+
Dust.print_result exec('yum check-update')[:exit_code], options
|
225
219
|
else
|
226
|
-
Dust.
|
220
|
+
Dust.print_failed '', options
|
227
221
|
end
|
228
|
-
|
229
222
|
end
|
230
223
|
|
231
|
-
def system_update quiet
|
232
|
-
Dust.print_msg
|
224
|
+
def system_update options={:quiet => false, :indent => 1}
|
225
|
+
Dust.print_msg 'installing system updates', options
|
233
226
|
|
234
|
-
if uses_apt?
|
235
|
-
|
236
|
-
elsif uses_emerge?
|
237
|
-
|
238
|
-
elsif uses_rpm?
|
239
|
-
|
227
|
+
if uses_apt?
|
228
|
+
ret = exec 'DEBIAN_FRONTEND=noninteractive aptitude full-upgrade -y'
|
229
|
+
elsif uses_emerge?
|
230
|
+
ret = exec 'emerge -uND @world'
|
231
|
+
elsif uses_rpm?
|
232
|
+
ret = exec 'yum upgrade -y'
|
240
233
|
else
|
241
|
-
Dust.
|
234
|
+
Dust.print_failed "\nsystem not (yet) supported", options
|
235
|
+
return false
|
242
236
|
end
|
237
|
+
|
238
|
+
Dust.print_result ret[:exit_code], options
|
239
|
+
|
240
|
+
# display stderr and stdout
|
241
|
+
puts
|
242
|
+
puts "#{Dust.grey}#{ret[:stdout]}#{Dust.none}"
|
243
|
+
puts "#{Dust.red}#{ret[:stderr]}#{Dust.none}"
|
243
244
|
end
|
244
245
|
|
245
246
|
# determining the system packet manager has to be done without facter
|
246
247
|
# because it's used to find out whether facter is installed / install facter
|
247
|
-
def uses_apt? quiet
|
248
|
-
Dust.print_msg
|
249
|
-
Dust.print_result exec('test -e /etc/debian_version')[:exit_code]
|
248
|
+
def uses_apt? options={:quiet => true, :indent => 1}
|
249
|
+
Dust.print_msg 'determining whether node uses apt', options
|
250
|
+
Dust.print_result exec('test -e /etc/debian_version')[:exit_code], options
|
250
251
|
end
|
251
252
|
|
252
|
-
def uses_rpm? quiet
|
253
|
-
Dust.print_msg
|
254
|
-
Dust.print_result exec('test -e /etc/redhat-release')[:exit_code]
|
253
|
+
def uses_rpm? options={:quiet => true, :indent => 1}
|
254
|
+
Dust.print_msg 'determining whether node uses rpm', options
|
255
|
+
Dust.print_result exec('test -e /etc/redhat-release')[:exit_code], options
|
255
256
|
end
|
256
257
|
|
257
|
-
def uses_emerge? quiet
|
258
|
-
Dust.print_msg
|
259
|
-
Dust.print_result exec('test -e /etc/gentoo-release')[:exit_code]
|
258
|
+
def uses_emerge? options={:quiet => true, :indent => 1}
|
259
|
+
Dust.print_msg 'determining whether node uses emerge', options
|
260
|
+
Dust.print_result exec('test -e /etc/gentoo-release')[:exit_code], options
|
260
261
|
end
|
261
262
|
|
262
|
-
def is_os? os_list, quiet
|
263
|
-
Dust.print_msg
|
264
|
-
collect_facts
|
263
|
+
def is_os? os_list, options={:quiet => true, :indent => 1}
|
264
|
+
Dust.print_msg "checking if this machine runs #{os_list.join(' or ')}", options
|
265
|
+
collect_facts options unless @attr['operatingsystem']
|
265
266
|
|
266
267
|
os_list.each do |os|
|
267
|
-
|
268
|
+
if @attr['operatingsystem'].downcase == os.downcase
|
269
|
+
return Dust.print_ok '', options
|
270
|
+
end
|
268
271
|
end
|
269
|
-
|
272
|
+
|
273
|
+
Dust.print_failed '', options
|
274
|
+
false
|
270
275
|
end
|
271
276
|
|
272
|
-
def is_debian? quiet
|
273
|
-
is_os? [
|
277
|
+
def is_debian? options={:quiet => true, :indent => 1}
|
278
|
+
is_os? ['debian'], options
|
274
279
|
end
|
275
280
|
|
276
|
-
def is_ubuntu? quiet
|
277
|
-
is_os? [
|
281
|
+
def is_ubuntu? options={:quiet => true, :indent => 1}
|
282
|
+
is_os? ['ubuntu'], options
|
278
283
|
end
|
279
284
|
|
280
|
-
def is_gentoo? quiet
|
281
|
-
is_os? [
|
285
|
+
def is_gentoo? options={:quiet => true, :indent => 1}
|
286
|
+
is_os? ['gentoo'], options
|
282
287
|
end
|
283
288
|
|
284
|
-
def is_centos? quiet
|
285
|
-
is_os? [
|
289
|
+
def is_centos? options={:quiet => true, :indent => 1}
|
290
|
+
is_os? ['centos'], options
|
286
291
|
end
|
287
292
|
|
288
|
-
def is_scientific? quiet
|
289
|
-
is_os? [
|
293
|
+
def is_scientific? options={:quiet => true, :indent => 1}
|
294
|
+
is_os? ['scientific'], options
|
290
295
|
end
|
291
296
|
|
292
|
-
def is_fedora? quiet
|
293
|
-
is_os? [
|
297
|
+
def is_fedora? options={:quiet => true, :indent => 1}
|
298
|
+
is_os? ['fedora'], options
|
294
299
|
end
|
295
300
|
|
296
|
-
def is_executable? file, quiet
|
297
|
-
Dust.print_msg
|
298
|
-
Dust.print_result
|
301
|
+
def is_executable? file, options={:quiet => false, :indent => 1}
|
302
|
+
Dust.print_msg "checking if file #{file} exists and is executeable", options
|
303
|
+
Dust.print_result exec("test -x $(which #{file})")[:exit_code], options
|
299
304
|
end
|
300
305
|
|
301
|
-
def file_exists? file, quiet
|
302
|
-
Dust.print_msg
|
303
|
-
Dust.print_result
|
306
|
+
def file_exists? file, options={:quiet => false, :indent => 1}
|
307
|
+
Dust.print_msg "checking if file #{file} exists", options
|
308
|
+
Dust.print_result exec("test -e #{file}")[:exit_code], options
|
304
309
|
end
|
305
310
|
|
306
|
-
def dir_exists? dir, quiet
|
307
|
-
Dust.print_msg
|
308
|
-
Dust.print_result
|
311
|
+
def dir_exists? dir, options={:quiet => false, :indent => 1}
|
312
|
+
Dust.print_msg "checking if directory #{dir} exists", options
|
313
|
+
Dust.print_result exec("test -d #{dir}")[:exit_code], options
|
309
314
|
end
|
310
315
|
|
311
|
-
def autostart_service service, quiet
|
312
|
-
Dust.print_msg
|
313
|
-
if uses_rpm?
|
314
|
-
Dust.print_result
|
315
|
-
elsif uses_apt?
|
316
|
-
Dust.print_result
|
317
|
-
elsif uses_emerge?
|
318
|
-
Dust.print_result
|
316
|
+
def autostart_service service, options={:quiet => false, :indent => 1}
|
317
|
+
Dust.print_msg "autostart #{service} on boot", options
|
318
|
+
if uses_rpm?
|
319
|
+
Dust.print_result exec("chkconfig #{service} on")[:exit_code], options
|
320
|
+
elsif uses_apt?
|
321
|
+
Dust.print_result exec("update-rc.d #{service} defaults")[:exit_code], options
|
322
|
+
elsif uses_emerge?
|
323
|
+
Dust.print_result exec("rc-update add #{service} default")[:exit_code], options
|
319
324
|
end
|
320
325
|
end
|
321
326
|
|
322
|
-
def restart_service service, quiet
|
323
|
-
Dust.print_msg
|
324
|
-
Dust.print_result
|
327
|
+
def restart_service service, options={:quiet => false, :indent => 1}
|
328
|
+
Dust.print_msg "restarting #{service}", options
|
329
|
+
Dust.print_result exec("/etc/init.d/#{service} restart")[:exit_code], options
|
325
330
|
end
|
326
331
|
|
327
|
-
def reload_service service, quiet
|
328
|
-
Dust.print_msg
|
329
|
-
Dust.print_result
|
332
|
+
def reload_service service, options={:quiet => false, :indent => 1}
|
333
|
+
Dust.print_msg "reloading #{service}", options
|
334
|
+
Dust.print_result exec("/etc/init.d/#{service} reload")[:exit_code], options
|
330
335
|
end
|
331
336
|
|
332
|
-
def qm_list name, quiet=false, indent=1
|
333
|
-
if name
|
334
|
-
Dust.print_msg("looking for a vm with name #{name}", indent) unless quiet
|
335
|
-
ret = exec("qm list |grep #{name}")
|
336
|
-
else
|
337
|
-
Dust.print_msg("looking for vms", indent) unless quiet
|
338
|
-
ret = exec('qm list |grep -v VMID')
|
339
|
-
end
|
340
|
-
|
341
|
-
if Dust.print_result(ret[:exit_code], quiet)
|
342
|
-
return "\t#{ret[:stdout].gsub(/\n/, "\n\t")}"
|
343
|
-
end
|
344
|
-
|
345
|
-
return ''
|
346
|
-
end
|
347
|
-
|
348
337
|
# check whether a user exists on this node
|
349
|
-
def user_exists? user, quiet
|
350
|
-
Dust.print_msg "checking if user #{user} exists",
|
351
|
-
Dust.print_result
|
338
|
+
def user_exists? user, options={:quiet => false, :indent => 1}
|
339
|
+
Dust.print_msg "checking if user #{user} exists", options
|
340
|
+
Dust.print_result exec("id #{user}")[:exit_code], options
|
352
341
|
end
|
353
342
|
|
354
343
|
# create a user
|
355
|
-
def create_user user, home
|
356
|
-
return true if user_exists? user,
|
344
|
+
def create_user user, options={:home => nil, :shell => nil, :quiet => false, :indent => 1}
|
345
|
+
return true if user_exists? user, options
|
357
346
|
|
358
|
-
Dust.print_msg "creating user #{user}", indent + 1
|
347
|
+
Dust.print_msg "creating user #{user}", {:quiet => options[:quiet], :indent => options[:indent] + 1}
|
359
348
|
cmd = "useradd #{user} -m"
|
360
|
-
cmd += " -d #{home}" if home
|
361
|
-
cmd += " -s #{
|
362
|
-
Dust.print_result
|
349
|
+
cmd += " -d #{options[:home]}" if options[:home]
|
350
|
+
cmd += " -s #{options[:shell]}" if options[:shell]
|
351
|
+
Dust.print_result exec(cmd)[:exit_code], options
|
363
352
|
end
|
364
353
|
|
365
|
-
|
366
|
-
|
354
|
+
# collect additional system facts using puppets facter
|
355
|
+
def collect_facts options={:quiet => false, :indent => 1}
|
356
|
+
|
357
|
+
# check if lsb-release (on apt systems) and facter are installed
|
358
|
+
# and install them if not
|
359
|
+
if uses_apt? and not package_installed? 'lsb-release', :quiet => true
|
360
|
+
install_package 'lsb-release', :quiet => false
|
361
|
+
end
|
362
|
+
|
363
|
+
unless package_installed? 'facter', :quiet => true
|
364
|
+
install_package 'facter', :quiet => false
|
365
|
+
end
|
367
366
|
|
368
|
-
|
369
|
-
install_package 'lsb-release', false, 2 if uses_apt?(true) and not package_installed?('lsb-release', true)
|
370
|
-
install_package 'facter', false, 2 unless package_installed? 'facter', true
|
367
|
+
Dust.print_msg "collecting additional system facts (using facter)", options
|
371
368
|
|
372
|
-
|
369
|
+
# run facter with -y for yaml output, and merge results into @attr
|
373
370
|
ret = exec 'facter -y'
|
374
371
|
@attr.merge! YAML.load ret[:stdout]
|
375
|
-
|
376
|
-
|
372
|
+
|
373
|
+
Dust.print_result ret[:exit_code], options
|
377
374
|
end
|
378
375
|
|
379
376
|
private
|