capistrano-scope 0.0.8 → 0.1.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/lib/capistrano/scope.rb +23 -4
- metadata +6 -7
- data/README +0 -369
data/lib/capistrano/scope.rb
CHANGED
@@ -6,6 +6,10 @@
|
|
6
6
|
|
7
7
|
module Scope
|
8
8
|
@@servers = Hash.new {|h,k| h[k] = {:ip_address => nil, :roles => [] } }
|
9
|
+
|
10
|
+
def task_list
|
11
|
+
@@servers.keys.map {|key| "@:#{key}"}
|
12
|
+
end
|
9
13
|
|
10
14
|
def role(role, server_name, options={})
|
11
15
|
@@servers[server_name][:roles] << {:name => role, :options => options}
|
@@ -17,6 +21,7 @@ module Scope
|
|
17
21
|
|
18
22
|
def create_task(name, pattern, ns)
|
19
23
|
ns.task(name) do
|
24
|
+
set :current_scope, true
|
20
25
|
keys = @@servers.keys.grep(/^#{pattern}/)
|
21
26
|
|
22
27
|
keys.each do |key|
|
@@ -43,7 +48,7 @@ module Scope
|
|
43
48
|
end
|
44
49
|
|
45
50
|
# Execution starts here.
|
46
|
-
def
|
51
|
+
def create_server_tasks(ns)
|
47
52
|
@@servers.keys.each do |name|
|
48
53
|
namespace_task name.split(':').reverse, ns
|
49
54
|
end
|
@@ -84,8 +89,9 @@ Capistrano.plugin :scope, Scope
|
|
84
89
|
Capistrano::Configuration.instance.load do
|
85
90
|
namespace '@'.to_sym do
|
86
91
|
|
87
|
-
|
88
|
-
|
92
|
+
desc "[internal] create the scope tasks."
|
93
|
+
task :create_server_tasks do
|
94
|
+
scope.create_server_tasks self
|
89
95
|
end
|
90
96
|
|
91
97
|
desc "Scope all defined servers"
|
@@ -104,9 +110,22 @@ Capistrano::Configuration.instance.load do
|
|
104
110
|
puts " #{defined_server}"
|
105
111
|
end
|
106
112
|
end
|
113
|
+
|
114
|
+
desc "[internal] Ensure that a stage has been selected."
|
115
|
+
task :ensure do
|
116
|
+
if !exists?(:current_scope)
|
117
|
+
if exists?(:default_scope)
|
118
|
+
logger.important "Defaulting to `#{default_scope}'"
|
119
|
+
find_and_execute_task(default_scope)
|
120
|
+
# else
|
121
|
+
# abort "No scope specified. Please specify one of: #{stages.join(', ')} (e.g. `cap #{stages.first} #{ARGV.last}')"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
107
125
|
|
108
126
|
end
|
109
127
|
|
110
|
-
on :load, '@:
|
128
|
+
on :load, '@:create_server_tasks'
|
129
|
+
on :start, '@:ensure', :except => scope.task_list + ['@:all', '@:create_server_tasks']
|
111
130
|
end
|
112
131
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-scope
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.8
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kirt Fitzpatrick
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-09-
|
18
|
+
date: 2010-09-24 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -40,10 +40,9 @@ executables: []
|
|
40
40
|
|
41
41
|
extensions: []
|
42
42
|
|
43
|
-
extra_rdoc_files:
|
44
|
-
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
45
|
files:
|
46
|
-
- README
|
47
46
|
- lib/capistrano/scope.rb
|
48
47
|
has_rdoc: true
|
49
48
|
homepage: http://github.com/kirtfitzpatrick/capistrano-scope
|
data/README
DELETED
@@ -1,369 +0,0 @@
|
|
1
|
-
Lightweight command line server selection for capistrano. Rather than having
|
2
|
-
to blast a task across all servers with a given role or as with
|
3
|
-
multistage having to group all of your servers into separate files ahead of
|
4
|
-
time. With this package you can pick groups or sub groups of servers or even
|
5
|
-
individual servers to execute tasks on via the command line. For example:
|
6
|
-
|
7
|
-
$ cap @:clienta:projectx:production:app:1 app:install_bundler
|
8
|
-
$ cap @:clienta:projecty:all server:deploy_authorized_keys USERS='john_doe jane_doe'
|
9
|
-
$ cap @:all nagios:nrpe:deploy
|
10
|
-
|
11
|
-
Keep in mind that this offers additional functionality
|
12
|
-
to capistrano and takes away nothing. It can be used this in combination
|
13
|
-
with multistage and role based server and task definitions.
|
14
|
-
|
15
|
-
|
16
|
-
From a config file perspective the only new functionality is the scope.server
|
17
|
-
and scope.role methods. From a command line persective all that has been
|
18
|
-
added is the @: namespace which contains all the server scope tasks.
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
-------------------------------------------------------------------------
|
23
|
-
= Capfile
|
24
|
-
|
25
|
-
require 'capistrano/scope'
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
= clientx.rb capistrano config file
|
31
|
-
|
32
|
-
The order you specify servers or roles doesn't matter, you can define
|
33
|
-
scope.role for a server before you define scope.server or visa versa.
|
34
|
-
You can give servers any name you like but they are broken into logical
|
35
|
-
groups by using the ":" separator.
|
36
|
-
|
37
|
-
scope.server 'clienta:projectx:staging:lb:1', '123.456.567.1'
|
38
|
-
scope.server 'clienta:projectx:staging:lb:2', '123.456.567.2'
|
39
|
-
scope.server 'clienta:projectx:staging:app:1', '123.456.567.3'
|
40
|
-
scope.server 'clienta:projectx:staging:app:2', '123.456.567.4'
|
41
|
-
scope.server 'clienta:projectx:staging:db:1', '123.456.567.5'
|
42
|
-
scope.server 'clienta:projectx:staging:db:2', '123.456.567.6'
|
43
|
-
|
44
|
-
scope.server 'clienta:projectx:production:lb:1', '123.456.567.7'
|
45
|
-
scope.server 'clienta:projectx:production:lb:2', '123.456.567.8'
|
46
|
-
scope.server 'clienta:projectx:production:app:1', '123.456.567.9'
|
47
|
-
scope.server 'clienta:projectx:production:app:2', '123.456.567.10'
|
48
|
-
scope.server 'clienta:projectx:production:db:1', '123.456.567.12'
|
49
|
-
scope.server 'clienta:projectx:production:db:2', '123.456.567.13'
|
50
|
-
|
51
|
-
scope.server 'clienta:projecty:staging:lb:1', '123.456.567.1'
|
52
|
-
scope.server 'clienta:projecty:staging:lb:2', '123.456.567.2'
|
53
|
-
scope.server 'clienta:projecty:staging:app:1', '123.456.567.3'
|
54
|
-
scope.server 'clienta:projecty:staging:app:2', '123.456.567.4'
|
55
|
-
scope.server 'clienta:projecty:staging:db:1', '123.456.567.5'
|
56
|
-
scope.server 'clienta:projecty:staging:db:2', '123.456.567.6'
|
57
|
-
|
58
|
-
scope.server 'clienta:projecty:production:lb:1', '123.456.567.7'
|
59
|
-
scope.server 'clienta:projecty:production:lb:2', '123.456.567.8'
|
60
|
-
scope.server 'clienta:projecty:production:app:1', '123.456.567.9'
|
61
|
-
scope.server 'clienta:projecty:production:app:2', '123.456.567.10'
|
62
|
-
scope.server 'clienta:projecty:production:db:1', '123.456.567.12'
|
63
|
-
scope.server 'clienta:projecty:production:db:2', '123.456.567.13'
|
64
|
-
|
65
|
-
|
66
|
-
scope.role :server, 'clienta:projectx:staging:lb:1'
|
67
|
-
scope.role :server, 'clienta:projectx:staging:lb:2'
|
68
|
-
scope.role :server, 'clienta:projectx:staging:app:1'
|
69
|
-
scope.role :server, 'clienta:projectx:staging:app:2'
|
70
|
-
scope.role :server, 'clienta:projectx:staging:db:1'
|
71
|
-
scope.role :server, 'clienta:projectx:staging:db:2'
|
72
|
-
scope.role :server, 'clienta:projectx:production:lb:1'
|
73
|
-
scope.role :server, 'clienta:projectx:production:lb:2'
|
74
|
-
scope.role :server, 'clienta:projectx:production:app:1'
|
75
|
-
scope.role :server, 'clienta:projectx:production:app:2'
|
76
|
-
scope.role :server, 'clienta:projectx:production:db:1'
|
77
|
-
scope.role :server, 'clienta:projectx:production:db:2'
|
78
|
-
scope.role :server, 'clienta:projecty:staging:lb:1'
|
79
|
-
scope.role :server, 'clienta:projecty:staging:lb:2'
|
80
|
-
scope.role :server, 'clienta:projecty:staging:app:1'
|
81
|
-
scope.role :server, 'clienta:projecty:staging:app:2'
|
82
|
-
scope.role :server, 'clienta:projecty:staging:db:1'
|
83
|
-
scope.role :server, 'clienta:projecty:staging:db:2'
|
84
|
-
scope.role :server, 'clienta:projecty:production:lb:1'
|
85
|
-
scope.role :server, 'clienta:projecty:production:lb:2'
|
86
|
-
scope.role :server, 'clienta:projecty:production:app:1'
|
87
|
-
scope.role :server, 'clienta:projecty:production:app:2'
|
88
|
-
scope.role :server, 'clienta:projecty:production:db:1'
|
89
|
-
scope.role :server, 'clienta:projecty:production:db:2'
|
90
|
-
|
91
|
-
scope.role :load_balancer, 'clienta:projectx:staging:lb:1'
|
92
|
-
scope.role :load_balancer, 'clienta:projectx:staging:lb:2'
|
93
|
-
scope.role :load_balancer, 'clienta:projectx:production:lb:1'
|
94
|
-
scope.role :load_balancer, 'clienta:projectx:production:lb:2'
|
95
|
-
scope.role :load_balancer, 'clienta:projecty:staging:lb:1'
|
96
|
-
scope.role :load_balancer, 'clienta:projecty:staging:lb:2'
|
97
|
-
scope.role :load_balancer, 'clienta:projecty:production:lb:1'
|
98
|
-
scope.role :load_balancer, 'clienta:projecty:production:lb:2'
|
99
|
-
|
100
|
-
scope.role :app, 'clienta:projectx:staging:app:1'
|
101
|
-
scope.role :app, 'clienta:projectx:staging:app:2'
|
102
|
-
scope.role :app, 'clienta:projectx:production:app:1'
|
103
|
-
scope.role :app, 'clienta:projectx:production:app:2'
|
104
|
-
scope.role :app, 'clienta:projecty:staging:app:1'
|
105
|
-
scope.role :app, 'clienta:projecty:staging:app:2'
|
106
|
-
scope.role :app, 'clienta:projecty:production:app:1'
|
107
|
-
scope.role :app, 'clienta:projecty:production:app:2'
|
108
|
-
|
109
|
-
scope.role :db, 'clienta:projectx:staging:db:1', :primary => true
|
110
|
-
scope.role :db, 'clienta:projectx:staging:db:2'
|
111
|
-
scope.role :db, 'clienta:projectx:production:db:1', :primary => true
|
112
|
-
scope.role :db, 'clienta:projectx:production:db:2'
|
113
|
-
scope.role :db, 'clienta:projecty:staging:db:1', :primary => true
|
114
|
-
scope.role :db, 'clienta:projecty:staging:db:2'
|
115
|
-
scope.role :db, 'clienta:projecty:production:db:1', :primary => true
|
116
|
-
scope.role :db, 'clienta:projecty:production:db:2'
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
# For the sake of demonstration lets assume we also have the following tasks
|
123
|
-
# defined and included from somewhere else.
|
124
|
-
# -------------------------------------------------------------------------
|
125
|
-
# recipes.rb
|
126
|
-
|
127
|
-
namespace :server do
|
128
|
-
desc "Concatenate Keys and upload new authorized_keys file to the server."
|
129
|
-
task :authorized_keys, :roles => :server do
|
130
|
-
...
|
131
|
-
end
|
132
|
-
|
133
|
-
desc "Install Subversion"
|
134
|
-
task :install_subversion, :roles => :server do
|
135
|
-
...
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
namespace :mysql do
|
140
|
-
desc "Backup Database"
|
141
|
-
task :backup, :roles => :db do
|
142
|
-
...
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
namespace :app do
|
147
|
-
desc "Install bundler"
|
148
|
-
task :install_bundler, :roles => :app do
|
149
|
-
...
|
150
|
-
end
|
151
|
-
|
152
|
-
desc "Install nginx"
|
153
|
-
task :install_nginx, :roles => :app do
|
154
|
-
...
|
155
|
-
end
|
156
|
-
|
157
|
-
desc "Install imagemagick"
|
158
|
-
task :install_imagemagick, :roles => :app do
|
159
|
-
...
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
namespace :nagios do
|
164
|
-
desc "Update nagios config on the admin server and restart nagios service"
|
165
|
-
task :deploy, :roles => :admin do
|
166
|
-
...
|
167
|
-
end
|
168
|
-
|
169
|
-
desc "Restart the nagios SMF Service"
|
170
|
-
task :restart, :roles => :admin do
|
171
|
-
...
|
172
|
-
end
|
173
|
-
|
174
|
-
namespace :nrpe do
|
175
|
-
desc "Install NRPE"
|
176
|
-
task :install, :roles => :server do
|
177
|
-
...
|
178
|
-
end
|
179
|
-
|
180
|
-
desc "Update NRPE Configuration"
|
181
|
-
task :deploy, :roles => :server do
|
182
|
-
...
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
namespace :plugins do
|
187
|
-
desc "Copy plugins to servers"
|
188
|
-
task :deploy, :roles => :server do
|
189
|
-
...
|
190
|
-
end
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
# end of recipes.rb
|
195
|
-
# -------------------------------------------------------------------------
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
# Now on the command line you can see the tasks that you normally would
|
200
|
-
# by listing out tasks with descriptions.
|
201
|
-
|
202
|
-
$ cap -T
|
203
|
-
|
204
|
-
cap @:all # Scope all defined servers
|
205
|
-
cap @:show # Show the roles and servers ...
|
206
|
-
cap app:install_bundler
|
207
|
-
cap app:install_nginx
|
208
|
-
cap app:install_image_magick
|
209
|
-
cap mysql:backup
|
210
|
-
cap nagios:deploy
|
211
|
-
cap nagios:restart
|
212
|
-
cap nagios:nrpe:install
|
213
|
-
cap nagios:nrpe:deploy
|
214
|
-
cap nagios:plugins:deploy
|
215
|
-
cap server:authorized_keys
|
216
|
-
cap server:install_subversion
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
# And if you want to see a list of all the server scopes that you have
|
221
|
-
# defined use the verbose flag. Since we used the '@' as the top level
|
222
|
-
# namespace for our scoping tasks they should all sort to the top of the
|
223
|
-
# list and then be followed by your normal capistrano tasks.
|
224
|
-
|
225
|
-
$ cap -vT
|
226
|
-
|
227
|
-
cap @:all # Scope all defined servers
|
228
|
-
cap @:clienta:all #
|
229
|
-
cap @:clienta:projectx:all #
|
230
|
-
cap @:clienta:projectx:production:all #
|
231
|
-
cap @:clienta:projectx:production:app:1 #
|
232
|
-
cap @:clienta:projectx:production:app:2 #
|
233
|
-
cap @:clienta:projectx:production:app:all #
|
234
|
-
cap @:clienta:projectx:production:db:1 #
|
235
|
-
cap @:clienta:projectx:production:db:2 #
|
236
|
-
cap @:clienta:projectx:production:db:all #
|
237
|
-
cap @:clienta:projectx:production:lb:1 #
|
238
|
-
cap @:clienta:projectx:production:lb:2 #
|
239
|
-
cap @:clienta:projectx:production:lb:all #
|
240
|
-
cap @:clienta:projectx:staging:all #
|
241
|
-
cap @:clienta:projectx:staging:app:1 #
|
242
|
-
cap @:clienta:projectx:staging:app:2 #
|
243
|
-
cap @:clienta:projectx:staging:app:all #
|
244
|
-
cap @:clienta:projectx:staging:db:1 #
|
245
|
-
cap @:clienta:projectx:staging:db:2 #
|
246
|
-
cap @:clienta:projectx:staging:db:all #
|
247
|
-
cap @:clienta:projectx:staging:lb:1 #
|
248
|
-
cap @:clienta:projectx:staging:lb:2 #
|
249
|
-
cap @:clienta:projectx:staging:lb:all #
|
250
|
-
cap @:clienta:projecty:all #
|
251
|
-
cap @:clienta:projecty:production:all #
|
252
|
-
cap @:clienta:projecty:production:app:1 #
|
253
|
-
cap @:clienta:projecty:production:app:2 #
|
254
|
-
cap @:clienta:projecty:production:app:all #
|
255
|
-
cap @:clienta:projecty:production:db:1 #
|
256
|
-
cap @:clienta:projecty:production:db:2 #
|
257
|
-
cap @:clienta:projecty:production:db:all #
|
258
|
-
cap @:clienta:projecty:production:lb:1 #
|
259
|
-
cap @:clienta:projecty:production:lb:2 #
|
260
|
-
cap @:clienta:projecty:production:lb:all #
|
261
|
-
cap @:clienta:projecty:staging:all #
|
262
|
-
cap @:clienta:projecty:staging:app:1 #
|
263
|
-
cap @:clienta:projecty:staging:app:2 #
|
264
|
-
cap @:clienta:projecty:staging:app:all #
|
265
|
-
cap @:clienta:projecty:staging:db:1 #
|
266
|
-
cap @:clienta:projecty:staging:db:2 #
|
267
|
-
cap @:clienta:projecty:staging:db:all #
|
268
|
-
cap @:clienta:projecty:staging:lb:1 #
|
269
|
-
cap @:clienta:projecty:staging:lb:2 #
|
270
|
-
cap @:clienta:projecty:staging:lb:all #
|
271
|
-
cap @:create_role_tasks #
|
272
|
-
cap @:show # Show the roles and servers ...
|
273
|
-
cap app:install_bundler
|
274
|
-
cap app:install_nginx
|
275
|
-
cap app:install_image_magick
|
276
|
-
cap mysql:backup
|
277
|
-
cap nagios:deploy
|
278
|
-
cap nagios:restart
|
279
|
-
cap nagios:nrpe:install
|
280
|
-
cap nagios:nrpe:deploy
|
281
|
-
cap nagios:plugins:deploy
|
282
|
-
cap server:authorized_keys
|
283
|
-
cap server:install_subversion
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
# Now to execute a task on a single server you can precede the task with the
|
289
|
-
# scope task for that server.
|
290
|
-
|
291
|
-
$ cap @:clienta:projectx:production:app:1 app:install_bundler
|
292
|
-
|
293
|
-
|
294
|
-
# Or if you want to execute that task on a group of servers you can use the
|
295
|
-
# all task that is defined for you at each level.
|
296
|
-
|
297
|
-
$ cap @:clienta:projectx:production:app:all
|
298
|
-
|
299
|
-
|
300
|
-
# Since we have added roles to our tasks and servers we can still execute
|
301
|
-
# tasks on larger groups of servers that include servers that we don't want
|
302
|
-
# the command to run on. Because the task is role based it will only execute
|
303
|
-
# the task on the correct servers. For example if we wanted to install nginx
|
304
|
-
# on all app servers of clientx but not clienty we could do this:
|
305
|
-
|
306
|
-
$ cap @:clientx:all app:install_nginx
|
307
|
-
|
308
|
-
# And if we really wanted to go global we can execute something across all
|
309
|
-
# servers with the @:all scope. Lets say we want to deploy they updated
|
310
|
-
# nrpe config file and a new plugin we wrote to all our servers.
|
311
|
-
|
312
|
-
$ cap @:all nagios:nrpe:deploy nagios:plugins:deploy
|
313
|
-
|
314
|
-
|
315
|
-
# Included with this package is a @:show task that will list out all the
|
316
|
-
# servers and roles that are defined for a given scope.
|
317
|
-
|
318
|
-
$ cap @:clienta:projectx:all @:show
|
319
|
-
|
320
|
-
triggering load callbacks
|
321
|
-
* executing `@:create_role_tasks'
|
322
|
-
* executing `@:clienta:projectx:all'
|
323
|
-
* executing `@:show'
|
324
|
-
Roles:
|
325
|
-
app
|
326
|
-
db
|
327
|
-
load_balancer
|
328
|
-
server
|
329
|
-
Servers:
|
330
|
-
clienta:projectx:production:app:1
|
331
|
-
clienta:projectx:production:app:2
|
332
|
-
clienta:projectx:production:db:1
|
333
|
-
clienta:projectx:production:db:2
|
334
|
-
clienta:projectx:staging:app:1
|
335
|
-
clienta:projectx:staging:app:2
|
336
|
-
clienta:projectx:staging:db:2
|
337
|
-
clienta:projecty:production:lb:1
|
338
|
-
clienta:projecty:production:lb:2
|
339
|
-
clienta:projecty:staging:db:1
|
340
|
-
clienta:projecty:staging:lb:1
|
341
|
-
clienta:projecty:staging:lb:2
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
$ cap @:clienta:projectx:staging:db:all @:show
|
347
|
-
|
348
|
-
triggering load callbacks
|
349
|
-
* executing `@:create_role_tasks'
|
350
|
-
* executing `@:clienta:projectx:staging:db:all'
|
351
|
-
* executing `@:show'
|
352
|
-
Roles:
|
353
|
-
db
|
354
|
-
server
|
355
|
-
Servers:
|
356
|
-
clienta:projectx:staging:db:2
|
357
|
-
clienta:projecty:staging:db:1
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
= How it Works
|
363
|
-
|
364
|
-
The implementation behind this is simple. When the configuration is
|
365
|
-
loaded it generates tasks for each server and server group in memory. Each of these
|
366
|
-
tasks is not much more than a list of capistrano server and role method calls.
|
367
|
-
When you call one of the scope tasks from the command line the task executes
|
368
|
-
and the roles and servers are defined just in time for the next task on the
|
369
|
-
command line to execute on them.
|