yyuu-capistrano-chef-solo 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -32,6 +32,7 @@ To setup your servers with `chef-solo`, add following in you `config/deploy.rb`.
32
32
  # in "config/deploy.rb"
33
33
  require "capistrano-chef-solo"
34
34
  set(:chef_solo_version, "11.4.0")
35
+ set(:rbenv_ruby_version, "1.9.3-p392")
35
36
  ```
36
37
 
37
38
  And then, now you can start using `chef-solo` via Capistrano.
@@ -76,7 +77,7 @@ After the bootstrap, you can deploy application normaly with `deploy` user.
76
77
 
77
78
  ### Using cookbooks
78
79
 
79
- #### Using cookbooks from local path
80
+ #### Using cookbooks in local path
80
81
 
81
82
  By default, `capistrano-chef-solo` searches cookbooks from local path of `config/cookbooks`.
82
83
  You can specify the cookbooks directory with using `chef_solo_cookbooks_subdir`.
@@ -86,7 +87,7 @@ set(:chef_solo_cookbooks_scm, :none)
86
87
  set(:chef_solo_cookbooks_subdir, "config/cookbooks")
87
88
  ```
88
89
 
89
- #### Using cookbooks from remote repository
90
+ #### Using cookbooks in remote repository
90
91
 
91
92
  You can use cookbooks in remote repository.
92
93
 
@@ -158,7 +159,7 @@ set(:chef_solo_role_run_list) {
158
159
  }
159
160
  ```
160
161
 
161
- #### Setting individual attributes per host
162
+ #### Setting individual attributes per hosts
162
163
 
163
164
  In some cases, you may want to apply individual `attributes` per hosts.
164
165
  (Something like `server_id` of mysqld or VRRP priority of keepalived)
@@ -186,7 +187,7 @@ set(:chef_solo_host_attributes) {
186
187
 
187
188
  You can check generated attributes with using `chef-solo:attributes` task.
188
189
 
189
- % cap HOST=foo.example.com chef-solo:attributes
190
+ % cap HOST=foo1.example.com chef-solo:attributes
190
191
 
191
192
 
192
193
  ## Reference
@@ -16,8 +16,8 @@ Gem::Specification.new do |gem|
16
16
  gem.require_paths = ["lib"]
17
17
  gem.version = Capistrano::ChefSolo::VERSION
18
18
 
19
- gem.add_dependency("capistrano")
20
- gem.add_dependency("capistrano-rbenv", "~> 1.0.0")
19
+ gem.add_dependency("capistrano", ">= 2.10.0")
20
+ gem.add_dependency("capistrano-rbenv", ">= 1.0.0")
21
21
  gem.add_development_dependency("net-scp", "~> 1.0.4")
22
22
  gem.add_development_dependency("net-ssh", "~> 2.2.2")
23
23
  gem.add_development_dependency("vagrant", "~> 1.0.6")
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module ChefSolo
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -59,52 +59,74 @@ module Capistrano
59
59
  auth_methods = ssh_options.fetch(:auth_methods, []).map { |m| m.to_sym }
60
60
  auth_methods.include?(:password) or auth_methods.empty?
61
61
  }
62
- def _bootstrap_settings(&block)
63
- if fetch(:_chef_solo_bootstrapped, false)
64
- yield
62
+
63
+ _cset(:_chef_solo_bootstrapped, false)
64
+ def _activate_settings(servers=[])
65
+ if _chef_solo_bootstrapped
66
+ false
65
67
  else
66
68
  # preserve original :user and :ssh_options
67
69
  set(:_chef_solo_bootstrap_user, fetch(:user))
68
70
  set(:_chef_solo_bootstrap_password, fetch(:password)) if chef_solo_use_password
69
71
  set(:_chef_solo_bootstrap_ssh_options, fetch(:ssh_options))
70
- servers = find_servers
71
- begin
72
- # we have to establish connections before teardown.
73
- # https://github.com/capistrano/capistrano/pull/416
74
- establish_connections_to(servers)
75
- logger.info("entering chef-solo bootstrap mode. reconnect to servers as `#{chef_solo_bootstrap_user}'.")
76
- # drop connection which is connected as standard :user.
77
- teardown_connections_to(servers)
78
- set(:user, chef_solo_bootstrap_user)
79
- set(:password, chef_solo_bootstrap_password) if chef_solo_use_password
80
- set(:ssh_options, chef_solo_bootstrap_ssh_options)
81
- set(:_chef_solo_bootstrapped, true)
82
- yield
83
- ensure
84
- set(:user, _chef_solo_bootstrap_user)
85
- set(:password, _chef_solo_bootstrap_password) if chef_solo_use_password
86
- set(:ssh_options, _chef_solo_bootstrap_ssh_options)
87
- set(:_chef_solo_bootstrapped, false)
88
- # we have to establish connections before teardown.
89
- # https://github.com/capistrano/capistrano/pull/416
90
- establish_connections_to(servers)
91
- logger.info("leaving chef-solo bootstrap mode. reconnect to servers as `#{user}'.")
92
- # drop connection which is connected as bootstrap :user.
93
- teardown_connections_to(servers)
94
- end
72
+ # we have to establish connections before teardown.
73
+ # https://github.com/capistrano/capistrano/pull/416
74
+ establish_connections_to(servers)
75
+ logger.info("entering chef-solo bootstrap mode. reconnect to servers as `#{chef_solo_bootstrap_user}'.")
76
+ # drop connection which is connected as standard :user.
77
+ teardown_connections_to(servers)
78
+ set(:user, chef_solo_bootstrap_user)
79
+ set(:password, chef_solo_bootstrap_password) if chef_solo_use_password
80
+ set(:ssh_options, chef_solo_bootstrap_ssh_options)
81
+ set(:_chef_solo_bootstrapped, true)
82
+ true
83
+ end
84
+ end
85
+
86
+ def _deactivate_settings(servers=[])
87
+ if _chef_solo_bootstrapped
88
+ set(:user, _chef_solo_bootstrap_user)
89
+ set(:password, _chef_solo_bootstrap_password) if chef_solo_use_password
90
+ set(:ssh_options, _chef_solo_bootstrap_ssh_options)
91
+ set(:_chef_solo_bootstrapped, false)
92
+ # we have to establish connections before teardown.
93
+ # https://github.com/capistrano/capistrano/pull/416
94
+ establish_connections_to(servers)
95
+ logger.info("leaving chef-solo bootstrap mode. reconnect to servers as `#{user}'.")
96
+ # drop connection which is connected as bootstrap :user.
97
+ teardown_connections_to(servers)
98
+ true
99
+ else
100
+ false
95
101
  end
96
102
  end
103
+
97
104
  _cset(:chef_solo_bootstrap, false)
98
105
  def connect_with_settings(&block)
99
106
  if chef_solo_bootstrap
100
- _bootstrap_settings do
101
- yield
107
+ servers = find_servers
108
+ if block_given?
109
+ begin
110
+ activated = _activate_settings(servers)
111
+ yield
112
+ ensure
113
+ _deactivate_settings(servers) if activated
114
+ end
115
+ else
116
+ _activate_settings(servers)
102
117
  end
103
118
  else
104
- yield
119
+ yield if block_given?
105
120
  end
106
121
  end
107
122
 
123
+ # FIXME:
124
+ # Some variables (such like :default_environment set by capistrano-rbenv) may be
125
+ # initialized without bootstrap settings during `on :start`.
126
+ # Is there any way to avoid this without setting `:rbenv_setup_default_environment`
127
+ # as false?
128
+ set(:rbenv_setup_default_environment, false)
129
+
108
130
  desc("Setup chef-solo.")
109
131
  task(:setup, :except => { :no_release => true }) {
110
132
  connect_with_settings do
@@ -136,10 +158,12 @@ module Capistrano
136
158
  end
137
159
  end
138
160
 
161
+ _cset(:chef_solo_cmd, "chef-solo")
162
+
139
163
  desc("Show chef-solo version.")
140
164
  task(:version, :except => { :no_release => true }) {
141
165
  connect_with_settings do
142
- run("cd #{chef_solo_path.dump} && #{bundle_cmd} exec chef-solo --version")
166
+ run("cd #{chef_solo_path.dump} && #{bundle_cmd} exec #{chef_solo_cmd} --version")
143
167
  end
144
168
  }
145
169
 
@@ -170,7 +194,7 @@ module Capistrano
170
194
  }
171
195
  task(:install_chef, :except => { :no_release => true }) {
172
196
  begin
173
- version = capture("cd #{chef_solo_path.dump} && #{bundle_cmd} exec chef-solo --version")
197
+ version = capture("cd #{chef_solo_path.dump} && #{bundle_cmd} exec #{chef_solo_cmd} --version")
174
198
  installed = Regexp.new(Regexp.escape(chef_solo_version)) =~ version
175
199
  rescue
176
200
  installed = false
@@ -402,11 +426,10 @@ module Capistrano
402
426
  end
403
427
 
404
428
  def invoke(options={})
405
- bin = fetch(:chef_solo_executable, "chef-solo")
406
429
  args = fetch(:chef_solo_options, [])
407
430
  args << "-c #{chef_solo_config_file.dump}"
408
431
  args << "-j #{chef_solo_attributes_file.dump}"
409
- run("cd #{chef_solo_path.dump} && #{sudo} #{bundle_cmd} exec #{bin.dump} #{args.join(" ")}", options)
432
+ run("cd #{chef_solo_path.dump} && #{sudo} #{bundle_cmd} exec #{chef_solo_cmd} #{args.join(" ")}", options)
410
433
  end
411
434
  }
412
435
  }
@@ -2,6 +2,6 @@
2
2
 
3
3
  bundle exec vagrant up
4
4
  bundle exec cap test_all
5
- bundle exec vagrant destroy -f
5
+ bundle exec vagrant halt
6
6
 
7
7
  # vim:set ft=sh :
@@ -2,6 +2,6 @@
2
2
 
3
3
  bundle exec vagrant up
4
4
  bundle exec cap test_all
5
- bundle exec vagrant destroy -f
5
+ bundle exec vagrant halt
6
6
 
7
7
  # vim:set ft=sh :
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.1.0
4
+ version: 0.1.1
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-03-13 00:00:00.000000000 Z
12
+ date: 2013-03-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: 2.10.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,13 +26,13 @@ dependencies:
26
26
  requirements:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: '0'
29
+ version: 2.10.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: capistrano-rbenv
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: 1.0.0
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: 1.0.0
46
46
  - !ruby/object:Gem::Dependency