supply_drop 0.17.0 → 1.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -33
- data/lib/supply_drop.rb +11 -6
- data/lib/supply_drop/tasks.rb +182 -115
- metadata +13 -12
- data/lib/supply_drop/plugin.rb +0 -96
- data/lib/supply_drop/syntax_checker.rb +0 -21
- data/lib/supply_drop/writer/batched.rb +0 -22
- data/lib/supply_drop/writer/file.rb +0 -23
- data/lib/supply_drop/writer/streaming.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3b27cb3b06d1f255fa46628af3ca982d2132226
|
4
|
+
data.tar.gz: d68003e29224e7eaab419a3e5c8f2a66f819ffa7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e7aac0f6412780ba6bfb3e380253187e07a3a3cab6cce1987c9798f915271699ad8c67f3a1f3f817978dad493b9360202607281c96f969a903c238a37f7fc13
|
7
|
+
data.tar.gz: 3d9f198bbddcf4c7be91229336b12e8554922a78554c25dbe0214c25b5700038770f91725052eefadd92f4debe86c3c1bf486d47a3f72799bcc86cf3cc061fa2
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# supply_drop
|
2
2
|
|
3
|
+
*THIS IS THE DOCUMENTATION FOR THE 1.x VERSION OF SUPPLY DROP THAT IS COMPATIBLE WITH CAPISTRANO 3.x. 0.x [docs](https://github.com/pitluga/supply_drop/tree/cap-2x) available on the cap-2x branch*
|
4
|
+
|
3
5
|
supply_drop is a capistrano plugin to facitiate provisioning servers with puppet, without using the puppet server. It works by simply rsyncing your puppet configuration files to your servers and running puppet apply. It strives to allow you to write idiomatic puppet scripts while being as lightweight as possible.
|
4
6
|
|
5
7
|
[![Build Status](https://secure.travis-ci.org/pitluga/supply_drop.png)](http://travis-ci.org/pitluga/supply_drop)
|
@@ -14,43 +16,38 @@ or with Bundler
|
|
14
16
|
|
15
17
|
then at the top of your deploy.rb
|
16
18
|
|
17
|
-
require 'rubygems'
|
18
19
|
require 'supply_drop'
|
19
20
|
|
20
21
|
### Tasks
|
21
22
|
|
22
|
-
cap puppet:bootstrap:debian
|
23
|
-
cap puppet:bootstrap:ubuntu
|
24
|
-
cap puppet:bootstrap:osx
|
25
|
-
cap puppet:bootstrap:redhat
|
23
|
+
cap staging puppet:bootstrap:debian
|
24
|
+
cap staging puppet:bootstrap:ubuntu
|
25
|
+
cap staging puppet:bootstrap:osx
|
26
|
+
cap staging puppet:bootstrap:redhat
|
26
27
|
|
27
28
|
This does a simple apt-get install of puppet on the target servers.
|
28
29
|
|
29
|
-
cap puppet:bootstrap:puppetlabs:debian
|
30
|
-
cap puppet:bootstrap:puppetlabs:ubuntu
|
30
|
+
cap staging puppet:bootstrap:puppetlabs:debian
|
31
|
+
cap staging puppet:bootstrap:puppetlabs:ubuntu
|
31
32
|
|
32
33
|
This is the same as above, but it grabs the most recent versions of puppet via apt repositories provided by puppetlabs.
|
33
34
|
|
34
|
-
cap puppet:noop
|
35
|
+
cap staging puppet:noop
|
35
36
|
|
36
37
|
This will show you a list of the pending changes to be applied server-by-server.
|
37
38
|
|
38
|
-
cap puppet:apply
|
39
|
+
cap staging puppet:apply
|
39
40
|
|
40
41
|
Applies the pending changes to all the servers.
|
41
42
|
|
42
|
-
cap puppet:
|
43
|
-
|
44
|
-
Locally syntax checks all the puppet files and erb templates. Requires you to have puppet installed locally.
|
45
|
-
|
46
|
-
cap puppet:unlock
|
43
|
+
cap staging puppet:unlock
|
47
44
|
|
48
45
|
Remove any stale lock files created by supply_drop when locking is used and something went wrong.
|
49
46
|
|
50
47
|
|
51
|
-
|
48
|
+
Only servers in the puppet role will be puppeted.
|
52
49
|
|
53
|
-
role :
|
50
|
+
role :puppet, '33.33.33.33'
|
54
51
|
|
55
52
|
### Variables
|
56
53
|
|
@@ -88,23 +85,6 @@ determines whether the rsync commands for multiple servers are run in parallel t
|
|
88
85
|
|
89
86
|
sets the maximum number of rsync commands that are run concurrently
|
90
87
|
|
91
|
-
set :puppet_syntax_check, false
|
92
|
-
|
93
|
-
when true, will syntax check your puppet files and erb templates before rsyncing them to your servers. This is an
|
94
|
-
experimental feature and is quite slow at the moment.
|
95
|
-
|
96
|
-
set :puppet_stream_output, false
|
97
|
-
|
98
|
-
will write the incremental output from the hosts to the screen instead of waiting until complete and printing by host.
|
99
|
-
|
100
|
-
set :puppet_write_to_file, nil
|
101
|
-
|
102
|
-
a file to additionally write puppet output to, useful for large noops with small scrollbacks.
|
103
|
-
|
104
|
-
set :puppet_runner, nil
|
105
|
-
|
106
|
-
allows you to specify the user to execute the puppet command as. Like running sudo -u puppet args from the command line.
|
107
|
-
|
108
88
|
set :puppet_lock_file, '/tmp/puppet.lock'
|
109
89
|
|
110
90
|
sets a lockfile on each remote host to prevent multiple users from puppeting the same node simultaneously. Set to nil to disable locking. You can alternately temporarily disable locking by setting the NO_PUPPET_LOCKING environment variable to any value.
|
@@ -136,6 +116,7 @@ If you write anything complicated, write a test for it. Test that your changes w
|
|
136
116
|
* Mike Pilat [mikepilat](https://github.com/mikepilat "github")
|
137
117
|
* Dan Manges [dan-manges](https://github.com/dan-manges "github") (one soda's worth)
|
138
118
|
* Brian Cosgrove [cosgroveb](https://github.com/cosgroveb "github")
|
119
|
+
* Troy Howard [thoward](https://github.com/thoward "github")
|
139
120
|
|
140
121
|
Copyright (c) 2012-2013 Tony Pitluga
|
141
122
|
|
data/lib/supply_drop.rb
CHANGED
@@ -1,12 +1,17 @@
|
|
1
1
|
require 'supply_drop/rsync'
|
2
2
|
require 'supply_drop/async_enumerable'
|
3
|
-
require 'supply_drop/plugin'
|
4
|
-
require 'supply_drop/syntax_checker'
|
5
3
|
require 'supply_drop/thread_pool'
|
6
4
|
require 'supply_drop/util'
|
7
|
-
require 'supply_drop/writer/batched'
|
8
|
-
require 'supply_drop/writer/file'
|
9
|
-
require 'supply_drop/writer/streaming'
|
10
5
|
require 'supply_drop/tasks'
|
11
6
|
|
12
|
-
|
7
|
+
set :puppet_source, '.'
|
8
|
+
set :puppet_destination, '/var/tmp/supply_drop'
|
9
|
+
set :puppet_command, 'puppet apply'
|
10
|
+
set :puppet_lib, lambda { "#{fetch(:puppet_destination)}/modules" }
|
11
|
+
set :puppet_parameters, lambda { fetch(:puppet_verbose) ? '--debug --trace --color false puppet.pp' : '--color false puppet.pp' }
|
12
|
+
set :puppet_verbose, false
|
13
|
+
set :puppet_excludes, %w(.git .svn)
|
14
|
+
set :puppet_parallel_rsync, true
|
15
|
+
set :puppet_parallel_rsync_pool_size, 10
|
16
|
+
set :puppet_runner, nil
|
17
|
+
set :puppet_lock_file, '/tmp/puppet.lock'
|
data/lib/supply_drop/tasks.rb
CHANGED
@@ -1,148 +1,215 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
set :puppet_excludes, %w(.git .svn)
|
10
|
-
set :puppet_stream_output, false
|
11
|
-
set :puppet_parallel_rsync, true
|
12
|
-
set :puppet_parallel_rsync_pool_size, 10
|
13
|
-
set :puppet_syntax_check, false
|
14
|
-
set :puppet_write_to_file, nil
|
15
|
-
set :puppet_runner, nil
|
16
|
-
set :puppet_lock_file, '/tmp/puppet.lock'
|
17
|
-
set :hiera_package, nil
|
18
|
-
|
19
|
-
namespace :bootstrap do
|
20
|
-
desc "installs puppet and hiera via rubygems on an osx host"
|
21
|
-
task :osx do
|
1
|
+
namespace :puppet do
|
2
|
+
task :defaults do
|
3
|
+
end
|
4
|
+
|
5
|
+
namespace :bootstrap do
|
6
|
+
desc "installs puppet via rubygems on an osx host"
|
7
|
+
task :osx do
|
8
|
+
on roles(:puppet) do
|
22
9
|
if fetch(:use_sudo, true)
|
23
|
-
|
10
|
+
sudo :gem, "install puppet --no-ri --no-rdoc"
|
24
11
|
else
|
25
|
-
|
12
|
+
execute :gem, "install puppet --no-ri --no-rdoc"
|
26
13
|
end
|
27
14
|
end
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "installs puppet via apt on an ubuntu or debian host"
|
18
|
+
task :ubuntu do
|
19
|
+
on roles(:puppet) do
|
20
|
+
execute :mkdir, "-p #{fetch(:puppet_destination)}"
|
21
|
+
sudo "apt-get update"
|
22
|
+
sudo "apt-get install -y puppet rsync"
|
23
|
+
end
|
24
|
+
end
|
28
25
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
26
|
+
desc "installs puppet via yum on a centos/red hat host"
|
27
|
+
task :redhat do
|
28
|
+
on roles(:puppet) do
|
29
|
+
execute :mkdir, "-p #{fetch(:puppet_destination)}"
|
30
|
+
sudo :yum, "-y install puppet rsync"
|
34
31
|
end
|
32
|
+
end
|
35
33
|
|
36
|
-
|
34
|
+
namespace :puppetlabs do
|
35
|
+
desc "setup the puppetlabs repo, then install via the normal method"
|
37
36
|
task :ubuntu do
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
on roles(:puppet) do
|
38
|
+
execute :echo, :deb, "http://apt.puppetlabs.com/ $(lsb_release -sc) main | #{sudo} tee /etc/apt/sources.list.d/puppet.list"
|
39
|
+
execute :echo, :deb, "http://apt.puppetlabs.com/ $(lsb_release -sc) dependencies | #{sudo} tee -a /etc/apt/sources.list.d/puppet.list"
|
40
|
+
sudo "apt-key adv --keyserver keyserver.ubuntu.com --recv 4BD6EC30"
|
41
|
+
puppet.bootstrap.ubuntu
|
42
|
+
end
|
41
43
|
end
|
42
44
|
|
43
|
-
desc "
|
45
|
+
desc "setup the puppetlabs repo, then install via the normal method"
|
44
46
|
task :redhat do
|
45
|
-
|
46
|
-
run "#{sudo} yum -y install puppet rsync"
|
47
|
+
info "PuppetLabs::RedHat bootstrap is not implemented yet"
|
47
48
|
end
|
49
|
+
end
|
50
|
+
end
|
48
51
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
52
|
+
desc "runs puppet with --noop flag to show changes"
|
53
|
+
task :noop do
|
54
|
+
begin
|
55
|
+
on roles(:puppet) do
|
56
|
+
lock
|
57
|
+
prepare
|
58
|
+
end
|
59
|
+
run_locally do
|
60
|
+
update_code
|
61
|
+
end
|
62
|
+
on roles(:puppet) do
|
63
|
+
puppet(:noop)
|
64
|
+
end
|
65
|
+
ensure
|
66
|
+
on roles(:puppet) do
|
67
|
+
unlock
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
58
71
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
72
|
+
desc "an atomic way to noop and apply changes while maintaining a lock"
|
73
|
+
task :noop_apply do
|
74
|
+
begin
|
75
|
+
on roles(:puppet) do
|
76
|
+
lock
|
77
|
+
prepare
|
78
|
+
end
|
79
|
+
run_locally do
|
80
|
+
update_code
|
81
|
+
end
|
67
82
|
|
68
|
-
|
69
|
-
|
70
|
-
logger.info "PuppetLabs::RedHat bootstrap is not implemented yet"
|
71
|
-
end
|
83
|
+
on roles(:puppet) do
|
84
|
+
puppet(:noop)
|
72
85
|
end
|
73
|
-
end
|
74
86
|
|
75
|
-
|
76
|
-
|
77
|
-
checker = SupplyDrop::SyntaxChecker.new(puppet_source)
|
78
|
-
logger.info "Syntax Checking..."
|
79
|
-
errors = false
|
80
|
-
checker.validate_puppet_files.each do |file, error|
|
81
|
-
logger.important "Puppet error: #{file}"
|
82
|
-
logger.important error
|
83
|
-
errors = true
|
84
|
-
end
|
85
|
-
checker.validate_templates.each do |file, error|
|
86
|
-
logger.important "Template error: #{file}"
|
87
|
-
logger.important error
|
88
|
-
errors = true
|
89
|
-
end
|
90
|
-
raise "syntax errors" if errors
|
91
|
-
end
|
87
|
+
q = "Apply changes?".to_sym
|
88
|
+
ask(q, "y/N")
|
92
89
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
90
|
+
if (fetch(q).strip.downcase == "y")
|
91
|
+
puts "Applying changes"
|
92
|
+
on roles(:puppet) do
|
93
|
+
puppet(:apply)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
ensure
|
97
|
+
on roles(:puppet) do
|
98
|
+
unlock
|
99
|
+
end
|
97
100
|
end
|
101
|
+
end
|
98
102
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
103
|
+
desc "alias for noop_apply"
|
104
|
+
task :noopply => :noop_apply
|
105
|
+
|
106
|
+
desc "applies the current puppet config to the server"
|
107
|
+
task :apply do
|
108
|
+
begin
|
109
|
+
on roles(:puppet) do
|
110
|
+
lock
|
111
|
+
prepare
|
112
|
+
end
|
113
|
+
run_locally do
|
105
114
|
update_code
|
106
|
-
|
107
|
-
|
115
|
+
end
|
116
|
+
on roles(:puppet) do
|
117
|
+
puppet(:apply)
|
118
|
+
end
|
119
|
+
ensure
|
120
|
+
on roles(:puppet) do
|
121
|
+
unlock
|
108
122
|
end
|
109
123
|
end
|
124
|
+
end
|
110
125
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
supply_drop.prepare
|
117
|
-
update_code
|
118
|
-
supply_drop.noop
|
119
|
-
supply_drop.apply if Capistrano::CLI.ui.agree("Apply? (yes/no) ")
|
120
|
-
supply_drop.unlock
|
121
|
-
end
|
126
|
+
desc "clears the puppet lockfile on the server."
|
127
|
+
task :remove_lock do
|
128
|
+
on roles(:puppet) do
|
129
|
+
warn "WARNING: puppet:remove_lock is deprecated, please use puppet:unlock instead"
|
130
|
+
unlock
|
122
131
|
end
|
132
|
+
end
|
123
133
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
on_rollback { supply_drop.unlock }
|
129
|
-
supply_drop.prepare
|
130
|
-
update_code
|
131
|
-
supply_drop.apply
|
132
|
-
supply_drop.unlock
|
133
|
-
end
|
134
|
+
desc "clears the puppet lockfile on the server."
|
135
|
+
task :unlock do
|
136
|
+
on roles(:puppet) do
|
137
|
+
unlock
|
134
138
|
end
|
139
|
+
end
|
140
|
+
|
141
|
+
private
|
142
|
+
|
143
|
+
def update_code
|
144
|
+
SupplyDrop::Util.thread_pool_size = fetch(:puppet_parallel_rsync_pool_size)
|
145
|
+
servers = SupplyDrop::Util.optionally_async(roles(:puppet), fetch(:puppet_parallel_rsync))
|
146
|
+
global_overrides = {}
|
147
|
+
global_overrides[:user] = fetch(:user, ENV['USER'])
|
148
|
+
global_overrides[:port] = fetch(:port) if any?(:port)
|
149
|
+
failed_servers = servers.map do |server|
|
150
|
+
server_overrides = {}
|
151
|
+
server_overrides[:user] = server.user if server.user
|
152
|
+
server_overrides[:port] = server.port if server.port
|
153
|
+
rsync_cmd = SupplyDrop::Rsync.command(
|
154
|
+
fetch(:puppet_source),
|
155
|
+
SupplyDrop::Rsync.remote_address(server.user || fetch(:user, ENV['USER']), server.hostname, fetch(:puppet_destination)),
|
156
|
+
:delete => true,
|
157
|
+
:excludes => fetch(:puppet_excludes),
|
158
|
+
:ssh => (fetch(:ssh_options) || {}).merge(server.properties.ssh_options||{}).merge(global_overrides.merge(server_overrides))
|
159
|
+
)
|
160
|
+
info rsync_cmd
|
161
|
+
server.hostname unless system rsync_cmd
|
162
|
+
end.compact
|
163
|
+
|
164
|
+
raise "rsync failed on #{failed_servers.join(',')}" if failed_servers.any?
|
165
|
+
end
|
135
166
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
167
|
+
def prepare
|
168
|
+
execute :mkdir, "-p #{fetch(:puppet_destination)}"
|
169
|
+
sudo :chown, "-R $USER: #{fetch(:puppet_destination)}"
|
170
|
+
end
|
171
|
+
|
172
|
+
def apply
|
173
|
+
puppet(:apply)
|
174
|
+
end
|
175
|
+
|
176
|
+
def lock
|
177
|
+
if should_lock?
|
178
|
+
execute <<-CHECK_LOCK
|
179
|
+
if [ -f #{fetch(:puppet_lock_file)} ]; then stat -c "#{red_text("Puppet in progress, #{fetch(:puppet_lock_file)} owned by %U since %x")}" #{fetch(:puppet_lock_file)} >&2
|
180
|
+
exit 1
|
181
|
+
fi
|
182
|
+
echo 'ok'
|
183
|
+
exit 0
|
184
|
+
CHECK_LOCK
|
185
|
+
|
186
|
+
execute :touch, "#{fetch(:puppet_lock_file)}"
|
140
187
|
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def unlock
|
191
|
+
sudo :rm, "-f #{fetch(:puppet_lock_file)}; true" if should_lock?
|
192
|
+
end
|
141
193
|
|
142
|
-
|
143
|
-
|
144
|
-
|
194
|
+
def should_lock?
|
195
|
+
fetch(:puppet_lock_file) && !ENV['NO_PUPPET_LOCK']
|
196
|
+
end
|
197
|
+
|
198
|
+
def puppet(command = :noop)
|
199
|
+
puppet_cmd = "#{fetch(:puppet_command)} --modulepath=#{fetch(:puppet_lib)} #{fetch(:puppet_parameters)}"
|
200
|
+
flag = command == :noop ? '--noop' : ''
|
201
|
+
|
202
|
+
within fetch(:puppet_destination) do
|
203
|
+
begin
|
204
|
+
sudo "#{puppet_cmd} #{flag}"
|
205
|
+
info "Puppet #{command} complete."
|
206
|
+
rescue
|
207
|
+
error "Puppet #{command} failed."
|
208
|
+
end
|
145
209
|
end
|
146
210
|
end
|
147
|
-
end
|
148
211
|
|
212
|
+
def red_text(text)
|
213
|
+
"\033[0;31m#{text}\033[0m"
|
214
|
+
end
|
215
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: supply_drop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Pitluga
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-08-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capistrano
|
@@ -17,14 +17,20 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - '>='
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 3.0.1
|
21
|
+
- - <
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 4.0.0
|
21
24
|
type: :runtime
|
22
25
|
prerelease: false
|
23
26
|
version_requirements: !ruby/object:Gem::Requirement
|
24
27
|
requirements:
|
25
28
|
- - '>='
|
26
29
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
30
|
+
version: 3.0.1
|
31
|
+
- - <
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.0.0
|
28
34
|
description: See http://github.com/pitluga/supply_drop
|
29
35
|
email:
|
30
36
|
- tony.pitluga@gmail.com
|
@@ -37,15 +43,10 @@ files:
|
|
37
43
|
- Rakefile
|
38
44
|
- lib/supply_drop.rb
|
39
45
|
- lib/supply_drop/async_enumerable.rb
|
40
|
-
- lib/supply_drop/plugin.rb
|
41
46
|
- lib/supply_drop/rsync.rb
|
42
|
-
- lib/supply_drop/syntax_checker.rb
|
43
47
|
- lib/supply_drop/tasks.rb
|
44
48
|
- lib/supply_drop/thread_pool.rb
|
45
49
|
- lib/supply_drop/util.rb
|
46
|
-
- lib/supply_drop/writer/batched.rb
|
47
|
-
- lib/supply_drop/writer/file.rb
|
48
|
-
- lib/supply_drop/writer/streaming.rb
|
49
50
|
homepage: http://github.com/pitluga/supply_drop
|
50
51
|
licenses:
|
51
52
|
- MIT
|
@@ -61,12 +62,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
61
62
|
version: '0'
|
62
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
64
|
requirements:
|
64
|
-
- - '
|
65
|
+
- - '>'
|
65
66
|
- !ruby/object:Gem::Version
|
66
|
-
version:
|
67
|
+
version: 1.3.1
|
67
68
|
requirements: []
|
68
69
|
rubyforge_project:
|
69
|
-
rubygems_version: 2.
|
70
|
+
rubygems_version: 2.1.11
|
70
71
|
signing_key:
|
71
72
|
specification_version: 4
|
72
73
|
summary: Masterless puppet with capistrano
|
data/lib/supply_drop/plugin.rb
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
module SupplyDrop
|
2
|
-
module Plugin
|
3
|
-
|
4
|
-
def rsync
|
5
|
-
SupplyDrop::Util.thread_pool_size = puppet_parallel_rsync_pool_size
|
6
|
-
servers = SupplyDrop::Util.optionally_async(find_servers_for_task(current_task), puppet_parallel_rsync)
|
7
|
-
overrides = {}
|
8
|
-
overrides[:user] = fetch(:user, ENV['USER'])
|
9
|
-
overrides[:port] = fetch(:port) if exists?(:port)
|
10
|
-
failed_servers = servers.map do |server|
|
11
|
-
rsync_cmd = SupplyDrop::Rsync.command(
|
12
|
-
puppet_source,
|
13
|
-
SupplyDrop::Rsync.remote_address(server.user || fetch(:user, ENV['USER']), server.host, puppet_destination),
|
14
|
-
:delete => true,
|
15
|
-
:excludes => puppet_excludes,
|
16
|
-
:ssh => ssh_options.merge(server.options[:ssh_options]||{}).merge(overrides)
|
17
|
-
)
|
18
|
-
logger.debug rsync_cmd
|
19
|
-
server.host unless system rsync_cmd
|
20
|
-
end.compact
|
21
|
-
|
22
|
-
raise "rsync failed on #{failed_servers.join(',')}" if failed_servers.any?
|
23
|
-
end
|
24
|
-
|
25
|
-
def prepare
|
26
|
-
run "mkdir -p #{puppet_destination}"
|
27
|
-
run "#{sudo} chown -R $USER: #{puppet_destination}"
|
28
|
-
end
|
29
|
-
|
30
|
-
def noop
|
31
|
-
puppet(:noop)
|
32
|
-
end
|
33
|
-
|
34
|
-
def apply
|
35
|
-
puppet(:apply)
|
36
|
-
end
|
37
|
-
|
38
|
-
def lock
|
39
|
-
if should_lock?
|
40
|
-
run <<-CHECK_LOCK
|
41
|
-
if [ -f #{puppet_lock_file} ]; then
|
42
|
-
stat -c "#{red_text("Puppet in progress, #{puppet_lock_file} owned by %U since %x")}" #{puppet_lock_file} >&2;
|
43
|
-
exit 1;
|
44
|
-
fi
|
45
|
-
CHECK_LOCK
|
46
|
-
|
47
|
-
run "touch #{puppet_lock_file}"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def unlock
|
52
|
-
run "#{sudo} rm -f #{puppet_lock_file}; true" if should_lock?
|
53
|
-
end
|
54
|
-
|
55
|
-
private
|
56
|
-
|
57
|
-
def should_lock?
|
58
|
-
puppet_lock_file && !ENV['NO_PUPPET_LOCK']
|
59
|
-
end
|
60
|
-
|
61
|
-
def puppet(command = :noop)
|
62
|
-
puppet_cmd = "cd #{puppet_destination} && #{sudo_cmd} #{puppet_command} --modulepath=#{puppet_lib} #{puppet_parameters}"
|
63
|
-
flag = command == :noop ? '--noop' : ''
|
64
|
-
|
65
|
-
writer = if puppet_stream_output
|
66
|
-
SupplyDrop::Writer::Streaming.new(logger)
|
67
|
-
else
|
68
|
-
SupplyDrop::Writer::Batched.new(logger)
|
69
|
-
end
|
70
|
-
|
71
|
-
writer = SupplyDrop::Writer::File.new(writer, puppet_write_to_file) unless puppet_write_to_file.nil?
|
72
|
-
|
73
|
-
begin
|
74
|
-
run "#{puppet_cmd} #{flag}" do |channel, stream, data|
|
75
|
-
writer.collect_output(channel[:host], data)
|
76
|
-
end
|
77
|
-
logger.debug "Puppet #{command} complete."
|
78
|
-
ensure
|
79
|
-
writer.all_output_collected
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def red_text(text)
|
84
|
-
"\033[0;31m#{text}\033[0m"
|
85
|
-
end
|
86
|
-
|
87
|
-
def sudo_cmd
|
88
|
-
if fetch(:use_sudo, true)
|
89
|
-
sudo(:as => puppet_runner)
|
90
|
-
else
|
91
|
-
logger.info "NOTICE: puppet_runner configuration invalid when use_sudo is false, ignoring..." unless puppet_runner.nil?
|
92
|
-
''
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
@@ -1,21 +0,0 @@
|
|
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
|
@@ -1,22 +0,0 @@
|
|
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
|
@@ -1,23 +0,0 @@
|
|
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
|