dust-deploy 0.15.1 → 0.15.2

Sign up to get free protection for your applications and to get access to all the features.
data/changelog.md CHANGED
@@ -1,6 +1,13 @@
1
1
  Changelog
2
2
  =============
3
3
 
4
+ 0.15.2
5
+ ------------
6
+
7
+ - fixes a bug in node.manage_user, now returns correctly if user is already set up
8
+ - node.manage_user now honors options correctly
9
+
10
+
4
11
  0.15.1
5
12
  ------------
6
13
 
data/lib/dust.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  require 'dust/runner'
2
2
  require 'dust/version'
3
3
  require 'dust/helper'
4
- require 'dust/print_status'
5
4
  require 'dust/messaging'
6
5
  require 'dust/server'
7
6
  require 'dust/recipe'
data/lib/dust/helper.rb CHANGED
@@ -43,7 +43,7 @@ class Hash
43
43
 
44
44
  # converts each value to an array, so .each and .combine won't get hickups
45
45
  def values_to_array!
46
- self.keys.each { |k| self[k] = [ self[k] ] unless self[k].is_a? Array }
46
+ self.keys.each { |k| self[k] = Array(self[k]) }
47
47
  end
48
48
 
49
49
  # converts each value that is a boolean to 'yes' resp. 'no' strings
@@ -1,9 +1,9 @@
1
1
  class Newrelic < Recipe
2
2
  desc 'newrelic:deploy', 'installs and configures newrelic system monitoring'
3
3
  def deploy
4
- return Dust.print_failed 'no key specified' unless @config
4
+ return @node.messages.add('no key specified').failed unless @config
5
5
 
6
- unless @node.install_package 'newrelic-sysmond'
6
+ unless @node.install_package('newrelic-sysmond')
7
7
  @node.messages.add('installing newrelic monitoring daemon failed, did you setup the newrelic repositories?').failed
8
8
  return
9
9
  end
@@ -10,8 +10,8 @@ class Pacemaker < Recipe
10
10
 
11
11
  # return if no authkey is given
12
12
  unless @config['authkey']
13
- return ::Dust.print_failed 'no authkey given. generate it using "corosync-keygen" ' +
14
- 'and convert it to base64 using "base64 -w0 /etc/corosync/authkey"'
13
+ return @node.messages.add('no authkey given. generate it using "corosync-keygen" ' +
14
+ 'and convert it to base64 using "base64 -w0 /etc/corosync/authkey"').failed
15
15
  end
16
16
 
17
17
  @node.collect_facts
data/lib/dust/runner.rb CHANGED
@@ -35,7 +35,7 @@ module Dust
35
35
  def deploy
36
36
  return unless check_dust_dir
37
37
  initialize_thorfiles
38
- Dust.print_failed 'no servers match this filter' if load_servers.empty?
38
+ puts 'no servers match this filter'.red if load_servers.empty?
39
39
 
40
40
  # set global variables
41
41
  $summary = options['summary']
@@ -46,10 +46,10 @@ module Dust
46
46
  @nodes.each_with_index do |node, i|
47
47
  if $parallel
48
48
  threads[i] = Thread.new do
49
- Thread.current['hostname'] = node['hostname'] if run_recipes node, 'deploy'
49
+ Thread.current['hostname'] = node['hostname'] if run_recipes(node, 'deploy')
50
50
  end
51
51
  else
52
- run_recipes node, 'deploy'
52
+ run_recipes(node, 'deploy')
53
53
  end
54
54
  end
55
55
 
@@ -73,7 +73,7 @@ module Dust
73
73
  def status
74
74
  return unless check_dust_dir
75
75
  initialize_thorfiles
76
- Dust.print_failed 'no servers match this filter' if load_servers.empty?
76
+ puts 'no servers match this filter'.red if load_servers.empty?
77
77
 
78
78
  # set global variables
79
79
  $summary = options['summary']
@@ -84,10 +84,10 @@ module Dust
84
84
  @nodes.each_with_index do |node, i|
85
85
  if $parallel
86
86
  threads[i] = Thread.new do
87
- Thread.current['hostname'] = node['hostname'] if run_recipes node, 'status'
87
+ Thread.current['hostname'] = node['hostname'] if run_recipes(node, 'status')
88
88
  end
89
89
  else
90
- run_recipes node, 'status'
90
+ run_recipes(node, 'status')
91
91
  end
92
92
  end
93
93
 
@@ -110,7 +110,7 @@ module Dust
110
110
  def system_update
111
111
  return unless check_dust_dir
112
112
  initialize_thorfiles
113
- Dust.print_failed 'no servers match this filter' if load_servers.empty?
113
+ puts 'no servers match this filter'.red if load_servers.empty?
114
114
 
115
115
  # set global variables
116
116
  $summary = options['summary']
@@ -148,7 +148,7 @@ module Dust
148
148
  def exec cmd, yaml=''
149
149
  return unless check_dust_dir
150
150
  initialize_thorfiles
151
- Dust.print_failed 'no servers match this filter' if load_servers.empty?
151
+ puts 'no servers match this filter'.red if load_servers.empty?
152
152
 
153
153
  # set global variables
154
154
  $summary = options['summary']
@@ -182,10 +182,9 @@ module Dust
182
182
 
183
183
  # creates directory skeleton for a dust setup
184
184
  desc 'new <name>', 'creates a dust directory skeleton for your network'
185
- def new name
186
- Dust.print_msg "spawning new dust directory skeleton with examples into '#{name}.dust'"
187
- FileUtils.cp_r File.dirname(__FILE__) + '/examples', "#{name}.dust"
188
- Dust.print_ok
185
+ def new(name)
186
+ puts "spawning new dust directory skeleton with examples into '#{name}.dust'"
187
+ FileUtils.cp_r(File.dirname(__FILE__) + '/examples', "#{name}.dust")
189
188
  end
190
189
 
191
190
  desc 'version', 'displays version number'
@@ -198,13 +197,13 @@ module Dust
198
197
 
199
198
  def check_dust_dir
200
199
  if Dir.pwd.split('.').last != 'dust'
201
- Dust.print_failed 'current directory does not end with .dust, are you in your dust directory?'
202
- Dust.print_msg "try running 'dust new mynetwork' to let me create one for you with tons of examples!\n", :indent => 0
200
+ puts 'current directory does not end with .dust, are you in your dust directory?'.red
201
+ puts "try running 'dust new mynetwork' to let me create one for you with tons of examples!\n"
203
202
  return false
204
203
  end
205
204
 
206
- unless File.directory? './nodes'
207
- Dust.print_failed 'could not find \'nodes\' folder in your dust directory. cannot continue.'
205
+ unless File.directory?('./nodes')
206
+ puts 'could not find \'nodes\' folder in your dust directory. cannot continue.'.red
208
207
  return false
209
208
  end
210
209
 
@@ -218,7 +217,7 @@ module Dust
218
217
  # skip this node if there are no recipes found
219
218
  return false unless node['recipes']
220
219
 
221
- recipes = generate_recipes node, context
220
+ recipes = generate_recipes(node, context)
222
221
 
223
222
  # skip this node unless we're actually having recipes to cook
224
223
  return false if recipes.empty?
@@ -230,7 +229,7 @@ module Dust
230
229
  # runs the method with the recipe name, defined and included in recipe/*.rb
231
230
  # call recipes for each recipe that is defined for this node
232
231
  recipes.each do |recipe, config|
233
- send recipe, 'prepare', node['server'], recipe, context, config, options
232
+ send(recipe, 'prepare', node['server'], recipe, context, config, options)
234
233
  end
235
234
 
236
235
  node['server'].disconnect
@@ -252,7 +251,7 @@ module Dust
252
251
  end
253
252
 
254
253
  # generate list of recipes for this node
255
- def generate_recipes node, context
254
+ def generate_recipes(node, context)
256
255
  recipes = {}
257
256
  node['recipes'].each do |recipe, config|
258
257
 
@@ -263,9 +262,9 @@ module Dust
263
262
  next if config == 'disabled' or config.is_a? FalseClass
264
263
 
265
264
  # check if method and thor task actually exist
266
- k = Thor::Util.find_by_namespace recipe
265
+ k = Thor::Util.find_by_namespace(recipe)
267
266
  next unless k
268
- next unless k.method_defined? context
267
+ next unless k.method_defined?(context)
269
268
 
270
269
  recipes[recipe] = config
271
270
  end
@@ -308,9 +307,9 @@ module Dust
308
307
  # if the argument is a directory, load yaml files in this directory
309
308
  # if the argument is a file, load the file.
310
309
  if options['yaml']
311
- if File.directory? options['yaml']
310
+ if File.directory?(options['yaml'])
312
311
  yaml_files = Dir["#{options['yaml']}/**/*.yaml"]
313
- elsif File.exists? options['yaml']
312
+ elsif File.exists?(options['yaml'])
314
313
  yaml_files = options['yaml']
315
314
  end
316
315
  else
@@ -318,7 +317,7 @@ module Dust
318
317
  end
319
318
 
320
319
  unless yaml_files
321
- Dust.print_failed "#{yaml} doesn't exist. exiting."
320
+ puts "#{yaml} doesn't exist. exiting.".red
322
321
  exit
323
322
  end
324
323
 
@@ -356,7 +355,7 @@ module Dust
356
355
 
357
356
  # if hostname is a valid ip address, don't add domain
358
357
  # so we can connect via ip address only
359
- unless IPAddress.valid? hostname
358
+ unless IPAddress.valid?(hostname)
360
359
  n['fqdn'] += '.' + n['domain'] if n['domain']
361
360
  end
362
361
 
@@ -364,7 +363,7 @@ module Dust
364
363
  n['proxy'] = options['proxy'] if options['proxy']
365
364
 
366
365
  # add this node to the global node array
367
- @nodes.push n unless filtered? n
366
+ @nodes.push(n) unless filtered?(n)
368
367
  end
369
368
  end
370
369
  end
@@ -372,7 +371,7 @@ module Dust
372
371
  # checks if this node was filtered out by command line argument
373
372
  # e.g. --filter environment:staging filters out all machines but
374
373
  # those in the environment staging
375
- def filtered? node
374
+ def filtered?(node)
376
375
 
377
376
  # if filter is not specified, instantly return false
378
377
  return false unless options['filter']
data/lib/dust/server.rb CHANGED
@@ -722,11 +722,11 @@ module Dust
722
722
  # delete user from system
723
723
  if options['remove']
724
724
  if user_exists?(user, :quiet => true)
725
- msg = messages.add("deleting user #{user} from system", :indent => options[:indent])
725
+ msg = messages.add("deleting user #{user} from system", { :indent => options[:indent] }.merge(options))
726
726
  return msg.parse_result(exec("userdel --remove #{user}")[:exit_code])
727
727
  end
728
728
 
729
- return messages.add("user #{user} not present in system").ok
729
+ return messages.add("user #{user} not present in system", options).ok
730
730
  end
731
731
 
732
732
  if user_exists?(user, :quiet => true)
@@ -737,8 +737,10 @@ module Dust
737
737
  args << " --gid #{options['gid']}" if options['gid']
738
738
  args << " --append --groups #{Array(options['groups']).join(',')}" if options['groups']
739
739
 
740
- unless args.empty?
741
- msg = messages.add("modifying user #{user}", :indent => options[:indent])
740
+ if args.empty?
741
+ return messages.add("user #{user} already set up correctly", options).ok
742
+ else
743
+ msg = messages.add("modifying user #{user}", { :indent => options[:indent] }.merge(options))
742
744
  return msg.parse_result(exec("usermod #{user} #{args}")[:exit_code])
743
745
  end
744
746
 
@@ -752,7 +754,7 @@ module Dust
752
754
  args << " --gid #{options['gid']}" if options['gid']
753
755
  args << " --groups #{Array(options['groups']).join(',')}" if options['groups']
754
756
 
755
- msg = messages.add("creating user #{user}", :indent => options[:indent])
757
+ msg = messages.add("creating user #{user}", { :indent => options[:indent] }.merge(options))
756
758
  return msg.parse_result(exec("useradd #{user} #{args}")[:exit_code])
757
759
  end
758
760
  end
data/lib/dust/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dust
2
- VERSION = "0.15.1"
2
+ VERSION = "0.15.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dust-deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.1
4
+ version: 0.15.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-26 00:00:00.000000000 Z
12
+ date: 2012-07-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -165,7 +165,6 @@ files:
165
165
  - lib/dust/examples/templates/ssh_authorized_keys/users.yaml
166
166
  - lib/dust/helper.rb
167
167
  - lib/dust/messaging.rb
168
- - lib/dust/print_status.rb
169
168
  - lib/dust/recipe.rb
170
169
  - lib/dust/recipes/aliases.rb
171
170
  - lib/dust/recipes/apt.rb
@@ -183,7 +182,6 @@ files:
183
182
  - lib/dust/recipes/limits.rb
184
183
  - lib/dust/recipes/locale.rb
185
184
  - lib/dust/recipes/logrotate.rb
186
- - lib/dust/recipes/make.rb
187
185
  - lib/dust/recipes/motd.rb
188
186
  - lib/dust/recipes/mysql.rb
189
187
  - lib/dust/recipes/newrelic.rb
@@ -1,70 +0,0 @@
1
- require 'colorize'
2
-
3
- module Dust
4
- $stdout.sync = true # autoflush
5
-
6
- def self.print_result ret, options={:quiet => false, :indent => 1}
7
- if ret == 0 or ret.is_a? TrueClass
8
- print_ok '', options
9
- return true
10
- else
11
- print_failed '', options
12
- return false
13
- end
14
- end
15
-
16
- def self.print_ok string='', options={:quiet => false, :indent => 1}
17
- opts = options.clone
18
- opts[:indent] = 0 if string.empty?
19
- print_msg "#{string} #{'[ ok ]'.green}\n", opts
20
- true
21
- end
22
-
23
- def self.print_failed string='', options={:quiet => false, :indent => 1}
24
- opts = options.clone
25
- opts[:indent] = 0 if string.empty?
26
- print_msg "#{string} #{'[ failed ]'.red}\n", opts
27
- false
28
- end
29
-
30
- def self.print_warning string='', options={:quiet => false, :indent => 1}
31
- opts = options.clone
32
- opts[:indent] = 0 if string.empty?
33
- print_msg "#{string} #{'[ warning ]'.yellow}\n", opts
34
- end
35
-
36
- def self.print_hostname hostname, options={:quiet => false, :indent => 0}
37
- print_msg "\n[ #{hostname.blue} ]\n\n", options
38
- end
39
-
40
- def self.print_recipe recipe, options={:quiet => false, :indent => 0}
41
- print_msg "|#{recipe}|\n".green, options
42
- end
43
-
44
- # prints stdout in grey and stderr in red (if existend)
45
- def self.print_ret ret, options={:quiet => false, :indent => -1}
46
- opts = options.clone
47
-
48
- opts[:indent] += 1
49
- print_msg "#{ret[:stdout].chomp.green}\n", opts unless ret[:stdout].empty?
50
- print_msg "#{ret[:stderr].chomp.red}\n", opts unless ret[:stderr].empty?
51
- end
52
-
53
- # indent according to options[:indent]
54
- # indent 0
55
- # - indent 1
56
- # - indent 2
57
- def self.print_msg string, options={:quiet => false, :indent => 1}
58
- # just return if in quiet mode
59
- return if options[:quiet]
60
-
61
- options[:indent] ||= 1
62
-
63
- if options[:indent] == 0
64
- print string
65
- else
66
- print ' ' + ' ' * (options[:indent] - 1) + '- ' + string
67
- end
68
- end
69
-
70
- end
@@ -1,29 +0,0 @@
1
- class Make < Recipe
2
- desc 'make:deploy', 'configure, make, make install'
3
- def deploy
4
- # install dependencies (defaults, build-essential | make, gcc)
5
- @node.install_package 'build-essential'
6
-
7
- # create temporary directory
8
- ret = @node.exec 'mktemp -d --tmpdir dust_make.XXXXXXXXX'
9
- return ::Dust.print_failed 'error creating temporary directory' if ret[:exit_code] != 0
10
- tempdir = ret[:stdout].chomp
11
-
12
- url = 'http://www.securixlive.com/download/barnyard2/barnyard2-1.9.tar.gz'
13
-
14
- if url =~ /\.(tar.gz|tgz)$/
15
- elsif url.end_with? '.tar.bz2'
16
- elsif url.end_with? '.zip'
17
- else
18
- end
19
-
20
- # if @config['svn']
21
- # if @config['git']
22
-
23
- # get url, svn, git repository
24
- # unpack bz2, tgz, zip
25
-
26
- # run commands (default [ './configure --prefix=/usr/local/', 'make', 'make install' ]
27
- # symlink
28
- end
29
- end