supply_drop 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -19,6 +19,7 @@ then at the top of your deploy.rb
19
19
 
20
20
  cap puppet:bootstrap:ubuntu
21
21
  cap puppet:bootstrap:osx
22
+ cap puppet:bootstrap:redhat
22
23
 
23
24
  This does a simple apt-get install of puppet on the target servers.
24
25
 
@@ -30,6 +31,11 @@ This will show you a list of the pending changes to be applied server-by-server.
30
31
 
31
32
  Applies the pending changes to all the servers.
32
33
 
34
+ cap puppet:syntax_check
35
+
36
+ Locally syntax checks all the puppet files and erb templates. Requires you to have puppet installed locally.
37
+
38
+
33
39
  You can specify that one of your servers should not be puppeted by setting the :nopuppet flag to true, like so. It will then be skipped by all the above commands.
34
40
 
35
41
  role :weird_thing, '33.33.33.33', :nopuppet => true
@@ -66,6 +72,13 @@ these are patterns that are passed as rsync --exclude flags when pushing your pu
66
72
 
67
73
  determines whether the rsync commands for multiple servers are run in parallel threads or serially
68
74
 
75
+ set :puppet_syntax_check, true
76
+
77
+ when true, will syntax check your puppet files and erb templates before rsyncing them to your servers.
78
+
79
+ set :puppet_write_to_file, nil
80
+
81
+ a file to additionally write puppet output to, useful for large noops with small scrollbacks.
69
82
 
70
83
  ### Handling Legacy Puppet
71
84
 
@@ -14,6 +14,8 @@ require 'supply_drop'
14
14
  set :puppet_destination, "~/supply_drop"
15
15
  set :puppet_command, "puppet"
16
16
  set :puppet_stream_output, true
17
+ set :puppet_syntax_check, false
18
+ set :puppet_write_to_file, "puppet_output.txt"
17
19
 
18
20
  server '33.33.33.10', :web, :app
19
21
  role :db, '33.33.33.11', :nopuppet => true
@@ -1,6 +1,6 @@
1
1
  Vagrant::Config.run do |config|
2
2
  config.vm.box = "lucid32"
3
- config.vm.define(:web) { |c| c.vm.network("33.33.33.10") }
4
- config.vm.define(:db) { |c| c.vm.network("33.33.33.11") }
3
+ config.vm.define(:web) { |c| c.vm.network(:hostonly, "33.33.33.10") }
4
+ config.vm.define(:db) { |c| c.vm.network(:hostonly, "33.33.33.11") }
5
5
  end
6
6
 
@@ -1,6 +1,6 @@
1
1
  Vagrant::Config.run do |config|
2
2
  config.vm.box = "lucid32"
3
- config.vm.define(:web) { |c| c.vm.network("33.33.33.10") }
4
- config.vm.define(:db) { |c| c.vm.network("33.33.33.11") }
3
+ config.vm.define(:web) { |c| c.vm.network(:hostonly, "33.33.33.10") }
4
+ config.vm.define(:db) { |c| c.vm.network(:hostonly, "33.33.33.11") }
5
5
  end
6
6
 
@@ -1,6 +1,10 @@
1
1
  require 'supply_drop/rsync'
2
2
  require 'supply_drop/async_enumerable'
3
+ require 'supply_drop/syntax_checker'
3
4
  require 'supply_drop/util'
5
+ require 'supply_drop/writer/batched'
6
+ require 'supply_drop/writer/file'
7
+ require 'supply_drop/writer/streaming'
4
8
 
5
9
  Capistrano::Configuration.instance.load do
6
10
  namespace :puppet do
@@ -13,6 +17,8 @@ Capistrano::Configuration.instance.load do
13
17
  set :puppet_excludes, %w(.git .svn)
14
18
  set :puppet_stream_output, false
15
19
  set :puppet_parallel_rsync, true
20
+ set :puppet_syntax_check, true
21
+ set :puppet_write_to_file, nil
16
22
 
17
23
  namespace :bootstrap do
18
24
  desc "installs puppet via rubygems on an osx host"
@@ -38,6 +44,24 @@ Capistrano::Configuration.instance.load do
38
44
  end
39
45
  end
40
46
 
47
+ desc "checks the syntax of all *.pp and *.erb files"
48
+ task :syntax_check do
49
+ checker = SupplyDrop::SyntaxChecker.new(puppet_source)
50
+ logger.info "Sytax Checking..."
51
+ errors = false
52
+ checker.validate_puppet_files.each do |file, error|
53
+ logger.important "Puppet error: #{file}"
54
+ logger.important error
55
+ errors = true
56
+ end
57
+ checker.validate_templates.each do |file, error|
58
+ logger.important "Template error: #{file}"
59
+ logger.important error
60
+ errors = true
61
+ end
62
+ raise "syntax errors" if errors
63
+ end
64
+
41
65
  desc "pushes the current puppet configuration to the server"
42
66
  task :update_code, :except => { :nopuppet => true } do
43
67
  servers = SupplyDrop::Util.optionally_async(find_servers_for_task(current_task), puppet_parallel_rsync)
@@ -56,6 +80,10 @@ Capistrano::Configuration.instance.load do
56
80
  raise "rsync failed on #{failed_servers.join(',')}" if failed_servers.any?
57
81
  end
58
82
 
83
+ before :'puppet:update_code' do
84
+ syntax_check if puppet_syntax_check
85
+ end
86
+
59
87
  desc "runs puppet with --noop flag to show changes"
60
88
  task :noop, :except => { :nopuppet => true } do
61
89
  update_code
@@ -74,25 +102,21 @@ Capistrano::Configuration.instance.load do
74
102
  puppet_cmd = "cd #{puppet_destination} && #{sudo_cmd} #{puppet_command} --modulepath=#{puppet_lib} #{puppet_parameters}"
75
103
  flag = command == :noop ? '--noop' : ''
76
104
 
77
- outputs = {}
105
+ writer = if puppet_stream_output
106
+ SupplyDrop::Writer::Streaming.new(logger)
107
+ else
108
+ SupplyDrop::Writer::Batched.new(logger)
109
+ end
110
+
111
+ writer = SupplyDrop::Writer::File.new(writer, puppet_write_to_file) unless puppet_write_to_file.nil?
112
+
78
113
  begin
79
114
  run "#{puppet_cmd} #{flag}" do |channel, stream, data|
80
- if puppet_stream_output
81
- print data
82
- $stdout.flush
83
- else
84
- outputs[channel[:host]] ||= ""
85
- outputs[channel[:host]] << data
86
- end
115
+ writer.collect_output(channel[:host], data)
87
116
  end
88
117
  logger.debug "Puppet #{command} complete."
89
118
  ensure
90
- unless puppet_stream_output
91
- outputs.each_pair do |host, output|
92
- logger.info "Puppet output for #{host}"
93
- logger.debug output, "#{host}"
94
- end
95
- end
119
+ writer.all_output_collected
96
120
  end
97
121
  end
98
122
  end
@@ -0,0 +1,21 @@
1
+ module SupplyDrop
2
+ class SyntaxChecker
3
+ def initialize(path)
4
+ @path = path
5
+ end
6
+
7
+ def validate_puppet_files
8
+ Dir.glob("#{@path}/**/*.pp").map do |puppet_file|
9
+ output = `puppet parser validate #{puppet_file}`
10
+ $?.to_i == 0 ? nil : [puppet_file, output]
11
+ end.compact
12
+ end
13
+
14
+ def validate_templates
15
+ Dir.glob("#{@path}/**/*.erb").map do |template_file|
16
+ output = `erb -x -T '-' #{template_file} | ruby -c 2>&1`
17
+ $?.to_i == 0 ? nil : [template_file, output]
18
+ end.compact
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ module SupplyDrop
2
+ module Writer
3
+ class Batched
4
+ def initialize(logger)
5
+ @outputs = {}
6
+ @logger = logger
7
+ end
8
+
9
+ def collect_output(host, data)
10
+ @outputs[host] ||= ""
11
+ @outputs[host] << data
12
+ end
13
+
14
+ def all_output_collected
15
+ @outputs.keys.sort.each do |host|
16
+ @logger.info "Puppet output for #{host}"
17
+ @logger.debug @outputs[host], host
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ module SupplyDrop
2
+ module Writer
3
+ class File
4
+ def initialize(writer, file)
5
+ @wrapped_writer = writer
6
+ @logger = Capistrano::Logger.new(:output => file)
7
+ @logger.level = Capistrano::Logger::TRACE
8
+ @file_writer = Batched.new(@logger)
9
+ end
10
+
11
+ def collect_output(host, data)
12
+ @wrapped_writer.collect_output(host, data)
13
+ @file_writer.collect_output(host, data)
14
+ end
15
+
16
+ def all_output_collected
17
+ @wrapped_writer.all_output_collected
18
+ @file_writer.all_output_collected
19
+ @logger.close
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ module SupplyDrop
2
+ module Writer
3
+ class Streaming
4
+ def initialize(logger)
5
+ @logger = logger
6
+ end
7
+
8
+ def collect_output(host, data)
9
+ @logger.debug data, host
10
+ end
11
+
12
+ def all_output_collected
13
+ end
14
+ end
15
+ end
16
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: supply_drop
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
5
- prerelease:
4
+ hash: 63
5
+ prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 7
8
+ - 8
9
9
  - 0
10
- version: 0.7.0
10
+ version: 0.8.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tony Pitluga
@@ -15,7 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-02-13 00:00:00 Z
18
+ date: 2012-03-26 00:00:00 -05:00
19
+ default_executable:
19
20
  dependencies: []
20
21
 
21
22
  description: See http://github.com/pitluga/supply_drop
@@ -31,10 +32,12 @@ files:
31
32
  - Rakefile
32
33
  - lib/supply_drop/async_enumerable.rb
33
34
  - lib/supply_drop/rsync.rb
35
+ - lib/supply_drop/syntax_checker.rb
34
36
  - lib/supply_drop/util.rb
37
+ - lib/supply_drop/writer/batched.rb
38
+ - lib/supply_drop/writer/file.rb
39
+ - lib/supply_drop/writer/streaming.rb
35
40
  - lib/supply_drop.rb
36
- - examples/Capfile
37
- - examples/config/deploy.rb
38
41
  - examples/ec2/Capfile
39
42
  - examples/ec2/puppet.pp
40
43
  - examples/vagrant/Capfile
@@ -1867,6 +1870,7 @@ files:
1867
1870
  - examples/vendored-puppet/vendor/puppet-2.7.8/test/util/storage.rb
1868
1871
  - examples/vendored-puppet/vendor/puppet-2.7.8/test/util/subclass_loader.rb
1869
1872
  - examples/vendored-puppet/vendor/puppet-2.7.8/test/util/utiltest.rb
1873
+ has_rdoc: true
1870
1874
  homepage: http://github.com/pitluga/supply_drop
1871
1875
  licenses: []
1872
1876
 
@@ -1896,7 +1900,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1896
1900
  requirements: []
1897
1901
 
1898
1902
  rubyforge_project:
1899
- rubygems_version: 1.8.6
1903
+ rubygems_version: 1.3.7
1900
1904
  signing_key:
1901
1905
  specification_version: 3
1902
1906
  summary: Masterless puppet with capistrano
@@ -1,4 +0,0 @@
1
- load 'deploy' if respond_to?(:namespace) # cap2 differentiator
2
- Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
3
-
4
- load 'config/deploy' # remove this line to skip loading any of the default tasks
@@ -1,22 +0,0 @@
1
- set :application, "set your application name here"
2
- set :repository, "set your repository location here"
3
-
4
- set :scm, :subversion
5
- # Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
6
-
7
- role :web, "your web-server here" # Your HTTP server, Apache/etc
8
- role :app, "your app-server here" # This may be the same as your `Web` server
9
- role :db, "your primary db-server here", :primary => true # This is where Rails migrations will run
10
- role :db, "your slave db-server here"
11
-
12
- # if you're still using the script/reaper helper you will need
13
- # these http://github.com/rails/irs_process_scripts
14
-
15
- # If you are using Passenger mod_rails uncomment this:
16
- # namespace :deploy do
17
- # task :start do ; end
18
- # task :stop do ; end
19
- # task :restart, :roles => :app, :except => { :no_release => true } do
20
- # run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
21
- # end
22
- # end