yyuu-capistrano-chef-solo 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -46,6 +46,7 @@ Following options are available to manage your `chef-solo`.
46
46
  * `:chef_solo_cookbooks_subdir` - the path to the `cookbooks` directory in the repository. use `config/cookbooks` by default.
47
47
  * `:chef_solo_cookbooks` - an alternative way to specify cookbooks repository. you can set multiple repositories from here.
48
48
  * `:chef_solo_attributes` - the `attributes` to apply to `chef-solo`.
49
+ * `:chef_solo_host_attributes` - per host `attributes` to apply to `chef-solo`. the key should be the name of the targeted host.
49
50
  * `:chef_solo_run_list` - the `run_list` to apply to `chef-solo`.
50
51
 
51
52
  ## Contributing
@@ -2,6 +2,7 @@ require 'capistrano-chef-solo/version'
2
2
  require 'capistrano-rbenv'
3
3
  require 'capistrano/configuration'
4
4
  require 'capistrano/recipes/deploy/scm'
5
+ require 'capistrano/transfer'
5
6
  require 'json'
6
7
  require 'tmpdir'
7
8
  require 'uri'
@@ -164,10 +165,27 @@ module Capistrano
164
165
  put(chef_solo_config, File.join(chef_solo_path, 'config', 'solo.rb'))
165
166
  }
166
167
 
168
+ # merge nested hashes
169
+ def _deep_merge(a, b)
170
+ f = lambda { |key, val1, val2| Hash === val1 && Hash === val2 ? val1.merge(val2, &f) : val2 }
171
+ a.merge(b, &f)
172
+ end
173
+
167
174
  _cset(:chef_solo_attributes, {})
175
+ _cset(:chef_solo_host_attributes, {})
168
176
  task(:update_attributes) {
169
- attributes = chef_solo_attributes.merge('run_list' => fetch(:chef_solo_run_list, []))
170
- put(attributes.to_json, File.join(chef_solo_path, 'config', 'solo.json'))
177
+ attributes = _deep_merge(chef_solo_attributes, {'run_list' => fetch(:chef_solo_run_list, [])})
178
+ to = File.join(chef_solo_path, 'config', 'solo.json')
179
+ if chef_solo_host_attributes.empty?
180
+ put(attributes.to_json, to)
181
+ else
182
+ execute_on_servers { |servers|
183
+ servers.each { |server|
184
+ host_attributes = _deep_merge(attributes, chef_solo_host_attributes.fetch(server.host, {}))
185
+ Capistrano::Transfer.process(:up, StringIO.new(host_attributes.to_json), to, [sessions[server]], :logger => logger)
186
+ }
187
+ }
188
+ end
171
189
  }
172
190
 
173
191
  task(:invoke) {
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module ChefSolo
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  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.3
4
+ version: 0.0.4
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: 2012-10-24 00:00:00.000000000 Z
12
+ date: 2012-10-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano