chef-provisioning 0.18 → 0.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c4cefaa41a622f8b28242c0d77384e123f88562
4
- data.tar.gz: 354056ddabbf9c6010af17895a069c4ece6240f9
3
+ metadata.gz: 35d07c9ee156834b006ec670fa2ad4f9fdaa467d
4
+ data.tar.gz: 746b88dd6944cdf449513dee69ef5c8bbfdb91a8
5
5
  SHA512:
6
- metadata.gz: c447345478be4935d4e55de75f197bb4f182d1cb153ddf6142eee50679bd99922438a63789c5c6cefe46261a7e6bda8d2929e9dc3d2bbec413d72b7b1532e81f
7
- data.tar.gz: c2ebf41170f13d2d8537327393410b2f91756955c3d4b3c2bc59d1ab0a86e82cdf55694a0b2fa3bfa7025ced2bbf7be2df5832992c254d5dde8464a99537e6c0
6
+ metadata.gz: bf65fd08788dcb554a21f2cf75d7284bbe4e030abb2ea96d13b108e2f9be7a5f88927d2eafcc430746c5092888438eb2e4dfea32f2767242e99c1462c7744bac
7
+ data.tar.gz: aa704ae71a32b3fd590d16e848a62d01d048c10570f5b60780da65da590aa54901fa5464572d3784f7451646e5901758b99eff47db14d7de59e479b3cef16fe3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Chef Provisioning Changelog
2
2
 
3
+ ## 0.19 (2/25/2015)
4
+
5
+ - Support for different versions of Chef with the :chef_version and :prerelease arguments (`machine_options convergence_options: { chef_version: '12.0.1' }` or `prerelease: true`)
6
+ - Support HTTPS proxy (@causton1)
7
+ - Automatically configure HTTPS proxy when specifying `machine_options convergence_options: { http_proxy: '...' }`
8
+ - Support for arbitrary configuration using `machine_options convergence_options: { chef_config: "anything you want dumped in /etc/chef/client.rb (will be appended to the standard options already placed in the file)" }`
9
+
10
+ - Make load_balancer :destroy work (@lynchc)
11
+ - Default to SSL for Chef install download (@xeon22)
12
+ - Fix Chef overwriting attributes on first converge in `machine_batch` (#209)
13
+ - Fix node permissions on Hosted / Enterprise Chef: no more adding your clients to the `admins` group (ewww). (#59)
14
+ - Always pass an array (never nil) to the driver, even when there are no machines to add to it (partial fix for chef/chef-provisioning-aws#81)
15
+ -
16
+
17
+
18
+ 915eac3 (origin/jk/install-sh-version, jk/install-sh-version) Add chef_version, prerelease and install_sh_arguments to InstallSh
19
+
3
20
  ## 0.18 (1/27/2015)
4
21
 
5
22
  - Allow `ssl_verify_mode` to be overridden (@mivok)
data/README.md CHANGED
@@ -86,9 +86,10 @@ Chef Provisioning has two major abstractions: the machine resource, and drivers.
86
86
 
87
87
  You declare what your machines do (recipes, tags, etc.) with the `machine` resource, the fundamental unit of Chef Provisioning. You will typically declare `machine` resources in a separate, OS/provisioning-independent file that declares the *topology* of your app--your machines and the recipes that will run on them.
88
88
 
89
- The machine resources from the example [myapp::small](https://github.com/chef/chef-provisioning/blob/master/cookbooks/myapp/recipes/small.rb) are pretty straightforward. Here's a copy/paste:
89
+ The machine resources from the [cluster.rb example](https://github.com/chef/chef-provisioning/blob/master/docs/examples/cluster.rb) are pretty straightforward. Here's a copy/paste:
90
90
 
91
91
  ```ruby
92
+ # Database!
92
93
  machine 'mario' do
93
94
  recipe 'postgresql'
94
95
  recipe 'mydb'
@@ -97,6 +98,7 @@ end
97
98
 
98
99
  num_webservers = 1
99
100
 
101
+ # Web servers!
100
102
  1.upto(num_webservers) do |i|
101
103
  machine "luigi#{i}" do
102
104
  recipe 'apache'
@@ -25,7 +25,7 @@ class Chef
25
25
  Chef::Provisioning::ChefLoadBalancerSpec.empty(new_resource.name)
26
26
 
27
27
  Chef::Log.debug "Creating load balancer: #{new_resource.name}; loaded #{lb_spec.inspect}"
28
- machine_specs = new_resource.machines ? new_resource.machines.map { |machine| get_machine_spec(machine) } : nil
28
+ machine_specs = new_resource.machines ? new_resource.machines.map { |machine| get_machine_spec(machine) } : []
29
29
 
30
30
  new_driver.allocate_load_balancer(action_handler, lb_spec, lb_options, machine_specs)
31
31
  lb_spec.save(action_handler)
@@ -19,12 +19,12 @@ class Machine < Chef::Provider::LWRPBase
19
19
  end
20
20
 
21
21
  action :allocate do
22
- if current_driver && current_driver.driver_url != new_driver.driver_url
23
- raise "Cannot move '#{machine_spec.name}' from #{current_driver.driver_url} to #{new_driver.driver_url}: machine moving is not supported. Destroy and recreate."
24
- end
25
22
  if !new_driver
26
23
  raise "Driver not specified for machine #{machine_spec.name}"
27
24
  end
25
+ if current_driver && current_driver.driver_url != new_driver.driver_url
26
+ raise "Cannot move '#{machine_spec.name}' from #{current_driver.driver_url} to #{new_driver.driver_url}: machine moving is not supported. Destroy and recreate."
27
+ end
28
28
  new_driver.allocate_machine(action_handler, machine_spec, new_machine_options)
29
29
  machine_spec.save(action_handler)
30
30
  end
@@ -137,7 +137,8 @@ class Machine < Chef::Provider::LWRPBase
137
137
  :private_key_options,
138
138
  :ohai_hints,
139
139
  :public_key_path, :public_key_format,
140
- :admin, :validator
140
+ :admin, :validator,
141
+ :chef_config
141
142
  ].inject({}) do |result, key|
142
143
  result[key] = new_resource.send(key)
143
144
  result
@@ -54,15 +54,12 @@ class MachineBatch < Chef::Provider::LWRPBase
54
54
  if m[:resource] && m[:resource].converge
55
55
  Chef::Log.info("Converging #{m[:spec].name} because 'converge true' is set ...")
56
56
  m[:machine].converge(m[:action_handler])
57
- m[:spec].save(m[:action_handler])
58
57
  elsif (!m[:resource] || m[:resource].converge.nil?) && m[:action_handler].locally_updated
59
58
  Chef::Log.info("Converging #{m[:spec].name} because the resource was updated ...")
60
59
  m[:machine].converge(m[:action_handler])
61
- m[:spec].save(m[:action_handler])
62
60
  elsif !m[:spec].node['automatic'] || m[:spec].node['automatic'].size == 0
63
61
  Chef::Log.info("Converging #{m[:spec].name} because it has never been converged (automatic attributes are empty) ...")
64
62
  m[:machine].converge(m[:action_handler])
65
- m[:spec].save(m[:action_handler])
66
63
  elsif m[:resource] && m[:resource].converge == false
67
64
  Chef::Log.debug("Not converging #{m[:spec].name} because 'converge false' is set.")
68
65
  end
@@ -76,7 +76,7 @@ module Provisioning
76
76
  chef_data_bag_item _self.name do
77
77
  data_bag 'loadbalancers'
78
78
  chef_server _chef_server
79
- action :destroy
79
+ action :delete
80
80
  end
81
81
  end
82
82
  end
@@ -9,7 +9,7 @@ module Provisioning
9
9
 
10
10
  def initialize(convergence_options, config)
11
11
  super
12
- @install_msi_url = convergence_options[:install_msi_url] || 'http://www.chef.io/chef/install.msi'
12
+ @install_msi_url = convergence_options[:install_msi_url] || 'https://www.chef.io/chef/install.msi'
13
13
  @install_msi_path = convergence_options[:install_msi_path] || "$env:TEMP\\#{File.basename(@install_msi_url)}"
14
14
  @chef_client_timeout = convergence_options.has_key?(:chef_client_timeout) ? convergence_options[:chef_client_timeout] : 120*60 # Default: 2 hours
15
15
  end
@@ -13,16 +13,29 @@ module Provisioning
13
13
  :client_pem_path => '/etc/chef/client.pem'
14
14
  })
15
15
  super(convergence_options, config)
16
- @install_sh_url = convergence_options[:install_sh_url] || 'http://www.chef.io/chef/install.sh'
16
+ @install_sh_url = convergence_options[:install_sh_url] || 'https://www.chef.io/chef/install.sh'
17
17
  @install_sh_path = convergence_options[:install_sh_path] || '/tmp/chef-install.sh'
18
- @bootstrap_env = convergence_options[:bootstrap_proxy] ? "http_proxy=#{convergence_options[:bootstrap_proxy]}" : ""
18
+ @chef_version = convergence_options[:chef_version]
19
+ @prerelease = convergence_options[:prerelease]
20
+ @install_sh_arguments = convergence_options[:install_sh_arguments]
21
+ @bootstrap_env = convergence_options[:bootstrap_proxy] ? "http_proxy=#{convergence_options[:bootstrap_proxy]} https_proxy=$http_proxy " : ""
19
22
  @chef_client_timeout = convergence_options.has_key?(:chef_client_timeout) ? convergence_options[:chef_client_timeout] : 120*60 # Default: 2 hours
20
23
  end
21
24
 
25
+ attr_reader :chef_version
26
+ attr_reader :prerelease
22
27
  attr_reader :install_sh_url
23
28
  attr_reader :install_sh_path
29
+ attr_reader :install_sh_arguments
24
30
  attr_reader :bootstrap_env
25
31
 
32
+ def install_sh_command_line
33
+ arguments = install_sh_arguments ? " #{install_sh_arguments}" : ""
34
+ arguments << " -v #{chef_version}" if chef_version
35
+ arguments << " -p" if prerelease
36
+ "bash -c '#{bootstrap_env} bash #{install_sh_path}#{arguments}'"
37
+ end
38
+
26
39
  def setup_convergence(action_handler, machine)
27
40
  super
28
41
 
@@ -31,7 +44,7 @@ module Provisioning
31
44
  # TODO ssh verification of install.sh before running arbtrary code would be nice?
32
45
  @@install_sh_cache[install_sh_url] ||= Net::HTTP.get(URI(install_sh_url))
33
46
  machine.write_file(action_handler, install_sh_path, @@install_sh_cache[install_sh_url], :ensure_dir => true)
34
- machine.execute(action_handler, "bash -c '#{bootstrap_env} bash #{install_sh_path}'")
47
+ machine.execute(action_handler, install_sh_command_line)
35
48
  end
36
49
  end
37
50
 
@@ -6,10 +6,6 @@ class Chef
6
6
  module Provisioning
7
7
  class ConvergenceStrategy
8
8
  class NoConverge < ConvergenceStrategy
9
- def initialize(convergence_options, config)
10
- super
11
- end
12
-
13
9
  def chef_server
14
10
  @chef_server ||= convergence_options[:chef_server] || Cheffish.default_chef_server(config)
15
11
  end
@@ -6,19 +6,15 @@ class Chef
6
6
  module Provisioning
7
7
  class ConvergenceStrategy
8
8
  class PrecreateChefObjects < ConvergenceStrategy
9
- def initialize(convergence_options, config)
10
- super
11
- end
12
-
13
9
  def chef_server
14
10
  @chef_server ||= convergence_options[:chef_server] || Cheffish.default_chef_server(config)
15
11
  end
16
12
 
17
13
  def setup_convergence(action_handler, machine)
18
14
  # Create keys on machine
19
- public_key = create_keys(action_handler, machine)
15
+ private_key, public_key = create_keys(action_handler, machine)
20
16
  # Create node and client on chef server
21
- create_chef_objects(action_handler, machine, public_key)
17
+ create_chef_objects(action_handler, machine, private_key, public_key)
22
18
 
23
19
  # If the chef server lives on localhost, tunnel the port through to the guest
24
20
  # (we need to know what got tunneled!)
@@ -93,7 +89,8 @@ module Provisioning
93
89
  machine.write_file(action_handler, convergence_options[:client_pem_path], server_private_key.to_pem, :ensure_dir => true)
94
90
  end
95
91
 
96
- server_private_key.public_key
92
+ # We shouldn't be returning this: see https://github.com/chef/chef-provisioning/issues/292
93
+ [ server_private_key, server_private_key.public_key ]
97
94
  end
98
95
 
99
96
  def is_localhost(host)
@@ -125,7 +122,7 @@ module Provisioning
125
122
  end
126
123
  end
127
124
 
128
- def create_chef_objects(action_handler, machine, public_key)
125
+ def create_chef_objects(action_handler, machine, private_key, public_key)
129
126
  _convergence_options = convergence_options
130
127
  _chef_server = chef_server
131
128
  # Save the node and create the client keys and client.
@@ -150,21 +147,41 @@ module Provisioning
150
147
 
151
148
  # If using enterprise/hosted chef, fix acls
152
149
  if chef_server[:chef_server_url] =~ /\/+organizations\/.+/
153
- grant_client_node_permissions(action_handler, chef_server, machine.name, ["read", "update"])
150
+ grant_client_node_permissions(action_handler, chef_server, machine, ["read", "update"], private_key)
154
151
  end
155
152
  end
156
153
 
157
154
  # Grant the client permissions to the node
158
155
  # This procedure assumes that the client name and node name are the same
159
- def grant_client_node_permissions(action_handler, chef_server, node_name, perms)
156
+ def grant_client_node_permissions(action_handler, chef_server, machine, perms, private_key)
157
+ node_name = machine.name
160
158
  api = Cheffish.chef_server_api(chef_server)
161
159
  node_perms = api.get("/nodes/#{node_name}/_acl")
162
- perms.each do |p|
163
- if !node_perms[p]['actors'].include?(node_name)
164
- action_handler.perform_action "Add #{node_name} to client #{p} ACLs" do
165
- node_perms[p]['actors'] << node_name
166
- api.put("/nodes/#{node_name}/_acl/#{p}", p => node_perms[p])
160
+
161
+ begin
162
+ perms.each do |p|
163
+ if !node_perms[p]['actors'].include?(node_name)
164
+ action_handler.perform_action "Add #{node_name} to client #{p} ACLs" do
165
+ node_perms[p]['actors'] << node_name
166
+ api.put("/nodes/#{node_name}/_acl/#{p}", p => node_perms[p])
167
+ end
168
+ end
169
+ end
170
+ rescue Net::HTTPServerException => e
171
+ if e.response.code == "400"
172
+ action_handler.perform_action "Delete #{node_name} and recreate as client #{node_name}" do
173
+ api.delete("/nodes/#{node_name}")
174
+ as_user = chef_server.dup
175
+ as_user[:options] = as_user[:options].merge(
176
+ client_name: node_name,
177
+ signing_key_filename: nil,
178
+ raw_key: private_key.to_pem
179
+ )
180
+ as_user_api = Cheffish.chef_server_api(as_user)
181
+ as_user_api.post("/nodes", machine.node)
167
182
  end
183
+ else
184
+ raise
168
185
  end
169
186
  end
170
187
  end
@@ -177,18 +194,20 @@ module Provisioning
177
194
  :verify_none
178
195
  end
179
196
 
180
- content = <<EOM
181
- chef_server_url #{chef_server_url.inspect}
182
- node_name #{node_name.inspect}
183
- client_key #{convergence_options[:client_pem_path].inspect}
184
- ssl_verify_mode #{ssl_verify_mode.to_sym.inspect}
185
- EOM
186
- unless convergence_options[:bootstrap_proxy].nil?
187
- content << <<EOM
188
- http_proxy #{convergence_options[:bootstrap_proxy].inspect}
189
- https_proxy #{convergence_options[:bootstrap_proxy].inspect}
190
- EOM
197
+ content = <<-EOM
198
+ chef_server_url #{chef_server_url.inspect}
199
+ node_name #{node_name.inspect}
200
+ client_key #{convergence_options[:client_pem_path].inspect}
201
+ ssl_verify_mode #{ssl_verify_mode.to_sym.inspect}
202
+ EOM
203
+ if convergence_options[:bootstrap_proxy]
204
+ content << <<-EOM
205
+ http_proxy #{convergence_options[:bootstrap_proxy].inspect}
206
+ https_proxy #{convergence_options[:bootstrap_proxy].inspect}
207
+ EOM
191
208
  end
209
+ content.gsub!(/^\s+/, "")
210
+ content << convergence_options[:chef_config] if convergence_options[:chef_config]
192
211
  content
193
212
  end
194
213
  end
@@ -144,7 +144,7 @@ prerelease="false"
144
144
  project="chef"
145
145
 
146
146
  report_bug() {
147
- echo "Please file a bug report at http://tickets.opscode.com"
147
+ echo "Please file a bug report at https://github.com/chef/chef-provisioning/issues"
148
148
  echo "Project: Chef"
149
149
  echo "Component: Packages"
150
150
  echo "Label: Omnibus"
@@ -1,5 +1,5 @@
1
1
  class Chef
2
2
  module Provisioning
3
- VERSION = '0.18'
3
+ VERSION = '0.19'
4
4
  end
5
5
  end
@@ -51,6 +51,9 @@ class Machine < Chef::Resource::LWRPBase
51
51
  # e.g. ohai_hint 'ec2' => { 'a' => 'b' } creates file ec2.json with json contents { 'a': 'b' }
52
52
  attribute :ohai_hints, :kind_of => Hash
53
53
 
54
+ # A string containing extra configuration for the machine
55
+ attribute :chef_config, :kind_of => String
56
+
54
57
  # Allows you to turn convergence off in the :create action by writing "converge false"
55
58
  # or force it with "true"
56
59
  attribute :converge, :kind_of => [TrueClass, FalseClass]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-provisioning
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.18'
4
+ version: '0.19'
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Keiser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-27 00:00:00.000000000 Z
11
+ date: 2015-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh