yyuu-capistrano-chef-solo 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +42 -6
- data/capistrano-chef-solo.gemspec +1 -1
- data/lib/capistrano-chef-solo.rb +46 -19
- data/lib/capistrano-chef-solo/version.rb +1 -1
- metadata +4 -5
data/README.md
CHANGED
@@ -28,11 +28,11 @@ This recipe will try to bootstrap your servers with `chef-solo`. Following proce
|
|
28
28
|
To setup your servers with `chef-solo`, add following in you `config/deploy.rb`.
|
29
29
|
|
30
30
|
# in "config/deploy.rb"
|
31
|
-
require
|
32
|
-
set(:chef_solo_version, "10.
|
31
|
+
require "capistrano-chef-solo"
|
32
|
+
set(:chef_solo_version, "10.16.4")
|
33
33
|
set(:chef_solo_cookbooks_repository, "git@example.com:foo/bar.git")
|
34
34
|
|
35
|
-
And then, now you can start `chef-solo` via capistrano.
|
35
|
+
And then, now you can start using `chef-solo` via capistrano.
|
36
36
|
|
37
37
|
$ cap chef-solo
|
38
38
|
|
@@ -46,9 +46,45 @@ Following options are available to manage your `chef-solo`.
|
|
46
46
|
* `:chef_solo_cookbooks_revision` - the `branch` in the repository.
|
47
47
|
* `:chef_solo_cookbooks_subdir` - the path to the `cookbooks` directory in the repository. use `config/cookbooks` by default.
|
48
48
|
* `:chef_solo_cookbooks` - an alternative way to specify cookbooks repository. you can set multiple repositories from here.
|
49
|
-
* `:chef_solo_attributes` - the `attributes`
|
50
|
-
* `:
|
51
|
-
* `:
|
49
|
+
* `:chef_solo_attributes` - the `attributes` of chef-solo. must be a `Hash<String,String>`. will be converted into JSON.
|
50
|
+
* `:chef_solo_run_list` - the `run_list` of chef-solo. must be an `Array<String>`. will be merged into `:chef_solo_attributes`.
|
51
|
+
* `:chef_solo_host_attributes` - per-host `attributes` of chef-solo. must be a `Hash<String,Hash<String,String>>`.
|
52
|
+
* `:chef_solo_host_run_list` - per-host `run_list` of chef-solo. must be a `Hash<String,Array<String>>`.
|
53
|
+
|
54
|
+
## Examples
|
55
|
+
|
56
|
+
### Setting `attributes` and `run_list`
|
57
|
+
|
58
|
+
To apply some `attributes` to your hosts, set something like following in your `config/deploy.rb` or so.
|
59
|
+
|
60
|
+
set(:chef_solo_attributes) {{
|
61
|
+
"locales" => { "language" => "ja" },
|
62
|
+
"tzdata" => { "timezone" => "Asia/Tokyo" },
|
63
|
+
}}
|
64
|
+
set(:chef_solo_run_list, ["recipe[build-essential]", "recipe[locales]", "recipe[tzdata]"])
|
65
|
+
|
66
|
+
### Setting individual `attributes` and `run_list` per host
|
67
|
+
|
68
|
+
In some cases, you may want to apply individual `attributes` per host.
|
69
|
+
(Something like `server_id` of mysqld or VRRP priority of keepalived)
|
70
|
+
|
71
|
+
set(:chef_solo_host_attributes) {
|
72
|
+
"foo1.example.com" => {
|
73
|
+
"keepalived" => {
|
74
|
+
"virtual_router_id" => 1,
|
75
|
+
"priority" => 100, #=> MASTER
|
76
|
+
"virtual_ipaddress" => "192.168.0.1/24",
|
77
|
+
},
|
78
|
+
},
|
79
|
+
"foo2.example.com" => {
|
80
|
+
"keepalived" => {
|
81
|
+
"virtual_router_id" => 1,
|
82
|
+
"priority" => 50, #=> BACKUP
|
83
|
+
"virtual_ipaddress" => "192.168.0.1/24",
|
84
|
+
},
|
85
|
+
},
|
86
|
+
}
|
87
|
+
|
52
88
|
|
53
89
|
## Contributing
|
54
90
|
|
data/lib/capistrano-chef-solo.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require 'tmpdir'
|
8
|
-
require 'uri'
|
1
|
+
require "capistrano-chef-solo/version"
|
2
|
+
require "capistrano-rbenv"
|
3
|
+
require "capistrano/configuration"
|
4
|
+
require "capistrano/recipes/deploy/scm"
|
5
|
+
require "json"
|
6
|
+
require "uri"
|
9
7
|
|
10
8
|
module Capistrano
|
11
9
|
module ChefSolo
|
@@ -15,7 +13,7 @@ module Capistrano
|
|
15
13
|
_cset(:chef_solo_home) {
|
16
14
|
capture('echo $HOME').strip
|
17
15
|
}
|
18
|
-
_cset(:chef_solo_version,
|
16
|
+
_cset(:chef_solo_version, "10.16.4")
|
19
17
|
_cset(:chef_solo_path) { File.join(chef_solo_home, 'chef') }
|
20
18
|
_cset(:chef_solo_path_children, %w(bundle cache config cookbooks))
|
21
19
|
|
@@ -38,6 +36,15 @@ module Capistrano
|
|
38
36
|
end
|
39
37
|
end
|
40
38
|
|
39
|
+
desc("Setup chef-solo.")
|
40
|
+
task(:setup) {
|
41
|
+
connect_with_settings {
|
42
|
+
transaction {
|
43
|
+
bootstrap
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
41
48
|
desc("Run chef-solo.")
|
42
49
|
task(:default) {
|
43
50
|
connect_with_settings {
|
@@ -86,8 +93,8 @@ module Capistrano
|
|
86
93
|
}
|
87
94
|
|
88
95
|
task(:update_cookbooks) {
|
89
|
-
tmpdir =
|
90
|
-
remote_tmpdir = capture("mktemp -d").chomp
|
96
|
+
tmpdir = `mktemp -d /tmp/capistrano-chef-solo.XXXXXXXXXX`.chomp
|
97
|
+
remote_tmpdir = capture("mktemp -d /tmp/capistrano-chef-solo.XXXXXXXXXX").chomp
|
91
98
|
destination = File.join(tmpdir, 'cookbooks')
|
92
99
|
remote_destination = File.join(chef_solo_path, 'cookbooks')
|
93
100
|
filename = File.join(tmpdir, 'cookbooks.tar.gz')
|
@@ -184,12 +191,12 @@ module Capistrano
|
|
184
191
|
}
|
185
192
|
|
186
193
|
# merge nested hashes
|
187
|
-
def
|
194
|
+
def deep_merge(a, b)
|
188
195
|
f = lambda { |key, val1, val2| Hash === val1 && Hash === val2 ? val1.merge(val2, &f) : val2 }
|
189
196
|
a.merge(b, &f)
|
190
197
|
end
|
191
198
|
|
192
|
-
def
|
199
|
+
def json(x)
|
193
200
|
if fetch(:chef_solo_pretty_json, true)
|
194
201
|
JSON.pretty_generate(x)
|
195
202
|
else
|
@@ -197,18 +204,38 @@ module Capistrano
|
|
197
204
|
end
|
198
205
|
end
|
199
206
|
|
207
|
+
_cset(:chef_solo_capistrano_attributes) {
|
208
|
+
# reject lazy variables since they might have side-effects.
|
209
|
+
Hash[variables.reject { |key, value| value.respond_to?(:call) }]
|
210
|
+
}
|
200
211
|
_cset(:chef_solo_attributes, {})
|
201
212
|
_cset(:chef_solo_host_attributes, {})
|
213
|
+
_cset(:chef_solo_run_list, [])
|
214
|
+
_cset(:chef_solo_host_run_list, {})
|
215
|
+
|
216
|
+
def generate_attributes(options={})
|
217
|
+
attributes = deep_merge(chef_solo_capistrano_attributes, chef_solo_attributes)
|
218
|
+
attributes = deep_merge(attributes, {"run_list" => chef_solo_run_list})
|
219
|
+
if options.has_key?(:host)
|
220
|
+
attributes = deep_merge(attributes, chef_solo_host_attributes.fetch(options[:host], {}))
|
221
|
+
attributes = deep_merge(attributes, {"run_list" => chef_solo_host_run_list.fetch(options[:host], [])})
|
222
|
+
end
|
223
|
+
attributes
|
224
|
+
end
|
225
|
+
|
226
|
+
desc("Show chef-solo attributes.")
|
227
|
+
task(:show_attributes) {
|
228
|
+
STDOUT.puts(json(generate_attributes))
|
229
|
+
}
|
230
|
+
|
202
231
|
task(:update_attributes) {
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
put(_json(attributes), to)
|
232
|
+
to = File.join(chef_solo_path, "config", "solo.json")
|
233
|
+
if chef_solo_host_attributes.empty? and chef_solo_host_run_list.empty?
|
234
|
+
put(json(generate_attributes), to)
|
207
235
|
else
|
208
236
|
execute_on_servers { |servers|
|
209
237
|
servers.each { |server|
|
210
|
-
|
211
|
-
Capistrano::Transfer.process(:up, StringIO.new(_json(host_attributes)), to, [sessions[server]], :logger => logger)
|
238
|
+
put(json(generate_attributes(:host => server.host), to, :hosts => server.host))
|
212
239
|
}
|
213
240
|
}
|
214
241
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yyuu-capistrano-chef-solo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
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: 2013-
|
12
|
+
date: 2013-03-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capistrano
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
|
-
- -
|
35
|
+
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
37
|
version: 0.0.3
|
38
38
|
type: :runtime
|
@@ -40,7 +40,7 @@ dependencies:
|
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
|
-
- -
|
43
|
+
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: 0.0.3
|
46
46
|
description: a capistrano recipe to invoke chef-solo.
|
@@ -83,4 +83,3 @@ signing_key:
|
|
83
83
|
specification_version: 3
|
84
84
|
summary: a capistrano recipe to invoke chef-solo.
|
85
85
|
test_files: []
|
86
|
-
has_rdoc:
|