Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 199 lines (172 sloc) 5.77 kb
25d7cc8 @pitluga extracted rsync class, only using ssh keys that exist
authored
1 require 'supply_drop/rsync'
46ee81f fixes and tests for async code
dave and phinze authored
2 require 'supply_drop/async_enumerable'
cc6073d @pitluga adds syntax checking before an rsync
authored
3 require 'supply_drop/syntax_checker'
a287d37 @braintreeps use threadpool so we can set max concurrent rsyncs
braintreeps authored
4 require 'supply_drop/thread_pool'
46ee81f fixes and tests for async code
dave and phinze authored
5 require 'supply_drop/util'
24f7e12 @pitluga allows you to configure a file to write output to, fixes #22
authored
6 require 'supply_drop/writer/batched'
7 require 'supply_drop/writer/file'
8 require 'supply_drop/writer/streaming'
25d7cc8 @pitluga extracted rsync class, only using ssh keys that exist
authored
9
be20be1 @braintreeps got rid of the subdirectory
braintreeps authored
10 Capistrano::Configuration.instance.load do
11 namespace :puppet do
dda4084 @pitluga changed puppet_target to puppet_destination, added puppet_source
authored
12 set :puppet_source, '.'
13 set :puppet_destination, '/tmp/supply_drop'
dfdff1f @phinze fix puppet apply; note how to support old puppets
phinze authored
14 set :puppet_command, 'puppet apply'
eb941e8 @braintreeps delay evaluation of puppet_lib, fixes #16
braintreeps authored
15 set :puppet_lib, lambda { "#{puppet_destination}/modules" }
e2cf5b7 @phinze Added puppet_verbose option for puppet debugging
phinze authored
16 set :puppet_parameters, lambda { puppet_verbose ? '--debug --trace puppet.pp' : 'puppet.pp' }
17 set :puppet_verbose, false
a767464 @pitluga made the exclude flags passed to rsync configurable
authored
18 set :puppet_excludes, %w(.git .svn)
06f7677 @phinze Added stream_output option for faster feedback
phinze authored
19 set :puppet_stream_output, false
5399ea1 draft implementation of async rsync
dave and phinze authored
20 set :puppet_parallel_rsync, true
a287d37 @braintreeps use threadpool so we can set max concurrent rsyncs
braintreeps authored
21 set :puppet_parallel_rsync_pool_size, 10
a1deac3 @pitluga defaults syntax checking to off until we can make it faster
authored
22 set :puppet_syntax_check, false
24f7e12 @pitluga allows you to configure a file to write output to, fixes #22
authored
23 set :puppet_write_to_file, nil
60c9712 @pitluga adds a puppet_runner configuration
authored
24 set :puppet_runner, nil
08084a7 @braintreeps Add lockfile support to prevent conflict when puppeting to shared dir…
braintreeps authored
25 set :puppet_lock_file, '/tmp/puppet.lock'
db7de5e @pitluga added capistrano example
authored
26
cf3c15d @phinze Add OSX bootstrap and respect use_sudo option
phinze authored
27 namespace :bootstrap do
28 desc "installs puppet via rubygems on an osx host"
29 task :osx do
30 if fetch(:use_sudo, true)
31 run "#{sudo} gem install puppet --no-ri --no-rdoc"
32 else
33 run "gem install puppet --no-ri --no-rdoc"
34 end
35 end
36
37 desc "installs puppet via apt on an ubuntu host"
38 task :ubuntu do
39 run "mkdir -p #{puppet_destination}"
40 run "#{sudo} apt-get update"
41 run "#{sudo} apt-get install -y puppet rsync"
42 end
713546d @msnodderly added yum support
msnodderly authored
43
44 desc "installs puppet via yum on a centos/red hat host"
45 task :redhat do
46 run "mkdir -p #{puppet_destination}"
47 run "#{sudo} yum -y install puppet rsync"
48 end
be20be1 @braintreeps got rid of the subdirectory
braintreeps authored
49 end
50
cc6073d @pitluga adds syntax checking before an rsync
authored
51 desc "checks the syntax of all *.pp and *.erb files"
52 task :syntax_check do
53 checker = SupplyDrop::SyntaxChecker.new(puppet_source)
54 logger.info "Sytax Checking..."
55 errors = false
56 checker.validate_puppet_files.each do |file, error|
57 logger.important "Puppet error: #{file}"
58 logger.important error
59 errors = true
60 end
61 checker.validate_templates.each do |file, error|
62 logger.important "Template error: #{file}"
63 logger.important error
64 errors = true
65 end
66 raise "syntax errors" if errors
67 end
68
be20be1 @braintreeps got rid of the subdirectory
braintreeps authored
69 desc "pushes the current puppet configuration to the server"
70 task :update_code, :except => { :nopuppet => true } do
5399ea1 draft implementation of async rsync
dave and phinze authored
71 servers = SupplyDrop::Util.optionally_async(find_servers_for_task(current_task), puppet_parallel_rsync)
83cbeed @pitluga stop progress if rsyncing fails on a box, fixes #18
authored
72 failed_servers = servers.map do |server|
a2e0b1a put Rsync in SupplyDrop module
dave and phinze authored
73 rsync_cmd = SupplyDrop::Rsync.command(
dda4084 @pitluga changed puppet_target to puppet_destination, added puppet_source
authored
74 puppet_source,
e8e4097 @phinze balls. missed this when putting Rsync in a module
phinze authored
75 SupplyDrop::Rsync.remote_address(server.user || fetch(:user, ENV['USER']), server.host, puppet_destination),
25d7cc8 @pitluga extracted rsync class, only using ssh keys that exist
authored
76 :delete => true,
a767464 @pitluga made the exclude flags passed to rsync configurable
authored
77 :excludes => puppet_excludes,
ea9b468 @pitluga respect capistrano's port parameter when rsyncing, fixes #17
authored
78 :ssh => { :keys => ssh_options[:keys], :config => ssh_options[:config], :port => fetch(:port, nil) }
25d7cc8 @pitluga extracted rsync class, only using ssh keys that exist
authored
79 )
be20be1 @braintreeps got rid of the subdirectory
braintreeps authored
80 logger.debug rsync_cmd
83cbeed @pitluga stop progress if rsyncing fails on a box, fixes #18
authored
81 server.host unless system rsync_cmd
82 end.compact
83
84 raise "rsync failed on #{failed_servers.join(',')}" if failed_servers.any?
be20be1 @braintreeps got rid of the subdirectory
braintreeps authored
85 end
86
cc6073d @pitluga adds syntax checking before an rsync
authored
87 before :'puppet:update_code' do
a287d37 @braintreeps use threadpool so we can set max concurrent rsyncs
braintreeps authored
88 _set_threadpool_size
a58d835 @phinze chown the supply_drop target instead of setting permissions.
phinze authored
89 syntax_check if puppet_syntax_check
cc6073d @pitluga adds syntax checking before an rsync
authored
90 end
91
08084a7 @braintreeps Add lockfile support to prevent conflict when puppeting to shared dir…
braintreeps authored
92 before 'puppet:noop' do
a58d835 @phinze chown the supply_drop target instead of setting permissions.
phinze authored
93 _prep_destination
94 _lock
08084a7 @braintreeps Add lockfile support to prevent conflict when puppeting to shared dir…
braintreeps authored
95 end
96
97 before 'puppet:apply' do
a58d835 @phinze chown the supply_drop target instead of setting permissions.
phinze authored
98 _prep_destination
99 _lock
08084a7 @braintreeps Add lockfile support to prevent conflict when puppeting to shared dir…
braintreeps authored
100 end
101
be20be1 @braintreeps got rid of the subdirectory
braintreeps authored
102 desc "runs puppet with --noop flag to show changes"
103 task :noop, :except => { :nopuppet => true } do
08084a7 @braintreeps Add lockfile support to prevent conflict when puppeting to shared dir…
braintreeps authored
104 transaction do
105 on_rollback { _unlock }
106 update_code
107 _puppet :noop
108 end
be20be1 @braintreeps got rid of the subdirectory
braintreeps authored
109 end
110
111 desc "applies the current puppet config to the server"
112 task :apply, :except => { :nopuppet => true } do
08084a7 @braintreeps Add lockfile support to prevent conflict when puppeting to shared dir…
braintreeps authored
113 transaction do
114 on_rollback { _unlock }
115 update_code
116 _puppet :apply
117 end
be20be1 @braintreeps got rid of the subdirectory
braintreeps authored
118 end
08084a7 @braintreeps Add lockfile support to prevent conflict when puppeting to shared dir…
braintreeps authored
119
120 desc "clears the puppet lockfile on the server."
121 task :remove_lock, :except => { :nopuppet => true} do
122 _unlock
123 end
124
125 after 'puppet:noop' do
126 _unlock
127 end
128
129 after 'puppet:apply' do
130 _unlock
131 end
132 end
133
a287d37 @braintreeps use threadpool so we can set max concurrent rsyncs
braintreeps authored
134 def _set_threadpool_size
135 SupplyDrop::Util.thread_pool_size = puppet_parallel_rsync_pool_size
136 end
137
08084a7 @braintreeps Add lockfile support to prevent conflict when puppeting to shared dir…
braintreeps authored
138 def _red_text(text)
139 "\033[0;31m#{text}\033[0m"
140 end
141
a58d835 @phinze chown the supply_drop target instead of setting permissions.
phinze authored
142 def _prep_destination
143 run "mkdir -p #{puppet_destination}"
144 run "#{sudo} chown -R $USER: #{puppet_destination}"
145 end
146
08084a7 @braintreeps Add lockfile support to prevent conflict when puppeting to shared dir…
braintreeps authored
147 def _lock
a58d835 @phinze chown the supply_drop target instead of setting permissions.
phinze authored
148 if _should_lock?
08084a7 @braintreeps Add lockfile support to prevent conflict when puppeting to shared dir…
braintreeps authored
149 run <<-GETLOCK
150 if [ ! -f #{puppet_lock_file} ]; then
0d2fcc8 @braintreeps Fix lock shell string and bump version.
braintreeps authored
151 touch #{puppet_lock_file};
08084a7 @braintreeps Add lockfile support to prevent conflict when puppeting to shared dir…
braintreeps authored
152 else
0d2fcc8 @braintreeps Fix lock shell string and bump version.
braintreeps authored
153 stat -c "#{_red_text("Puppet in progress, #{puppet_lock_file} owned by %U since %x")}" #{puppet_lock_file} >&2;
154 exit 1;
155 fi
08084a7 @braintreeps Add lockfile support to prevent conflict when puppeting to shared dir…
braintreeps authored
156 GETLOCK
157 end
158 end
159
160 def _unlock
65a3916 @phinze use sudo when unlocking
phinze authored
161 run "#{sudo} rm -f #{puppet_lock_file}; true" if _should_lock?
08084a7 @braintreeps Add lockfile support to prevent conflict when puppeting to shared dir…
braintreeps authored
162 end
163
164 def _should_lock?
165 puppet_lock_file && !ENV['NO_PUPPET_LOCK']
be20be1 @braintreeps got rid of the subdirectory
braintreeps authored
166 end
167
eace8c4 @benmills Renamed puppet function _puppet to fix conflict with the namespace
benmills authored
168 def _puppet(command = :noop)
60c9712 @pitluga adds a puppet_runner configuration
authored
169 puppet_cmd = "cd #{puppet_destination} && #{_sudo_cmd} #{puppet_command} --modulepath=#{puppet_lib} #{puppet_parameters}"
be20be1 @braintreeps got rid of the subdirectory
braintreeps authored
170 flag = command == :noop ? '--noop' : ''
171
24f7e12 @pitluga allows you to configure a file to write output to, fixes #22
authored
172 writer = if puppet_stream_output
173 SupplyDrop::Writer::Streaming.new(logger)
174 else
175 SupplyDrop::Writer::Batched.new(logger)
176 end
177
178 writer = SupplyDrop::Writer::File.new(writer, puppet_write_to_file) unless puppet_write_to_file.nil?
179
be20be1 @braintreeps got rid of the subdirectory
braintreeps authored
180 begin
181 run "#{puppet_cmd} #{flag}" do |channel, stream, data|
24f7e12 @pitluga allows you to configure a file to write output to, fixes #22
authored
182 writer.collect_output(channel[:host], data)
be20be1 @braintreeps got rid of the subdirectory
braintreeps authored
183 end
184 logger.debug "Puppet #{command} complete."
185 ensure
24f7e12 @pitluga allows you to configure a file to write output to, fixes #22
authored
186 writer.all_output_collected
be20be1 @braintreeps got rid of the subdirectory
braintreeps authored
187 end
188 end
60c9712 @pitluga adds a puppet_runner configuration
authored
189
190 def _sudo_cmd
191 if fetch(:use_sudo, true)
192 sudo(:as => puppet_runner)
193 else
194 logger.info "NOTICE: puppet_runner configuration invalid when use_sudo is false, ignoring..." unless puppet_runner.nil?
195 ''
196 end
197 end
be20be1 @braintreeps got rid of the subdirectory
braintreeps authored
198 end
Something went wrong with that request. Please try again.