chef-metal 0.10.2 → 0.11.beta
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -5
- data/README.md +3 -3
- data/bin/metal +5 -9
- data/lib/chef/provider/machine.rb +81 -32
- data/lib/chef/provider/machine_batch.rb +67 -58
- data/lib/chef/provider/machine_execute.rb +7 -7
- data/lib/chef/provider/machine_file.rb +11 -11
- data/lib/chef/resource/machine.rb +11 -15
- data/lib/chef/resource/machine_batch.rb +1 -1
- data/lib/chef/resource/machine_execute.rb +3 -4
- data/lib/chef/resource/machine_file.rb +3 -4
- data/lib/chef_metal.rb +26 -28
- data/lib/chef_metal/action_handler.rb +9 -7
- data/lib/chef_metal/add_prefix_action_handler.rb +7 -5
- data/lib/chef_metal/chef_machine_spec.rb +64 -0
- data/lib/chef_metal/{provider_action_handler.rb → chef_provider_action_handler.rb} +27 -14
- data/lib/chef_metal/chef_run_data.rb +68 -7
- data/lib/chef_metal/convergence_strategy.rb +14 -3
- data/lib/chef_metal/convergence_strategy/install_cached.rb +24 -10
- data/lib/chef_metal/convergence_strategy/install_msi.rb +17 -10
- data/lib/chef_metal/convergence_strategy/install_sh.rb +20 -10
- data/lib/chef_metal/convergence_strategy/no_converge.rb +20 -13
- data/lib/chef_metal/convergence_strategy/precreate_chef_objects.rb +51 -47
- data/lib/chef_metal/{provider.rb → driver.rb} +103 -79
- data/lib/chef_metal/machine.rb +13 -5
- data/lib/chef_metal/machine/basic_machine.rb +11 -11
- data/lib/chef_metal/machine/unix_machine.rb +6 -6
- data/lib/chef_metal/machine/windows_machine.rb +3 -3
- data/lib/chef_metal/machine_spec.rb +22 -25
- data/lib/chef_metal/recipe_dsl.rb +34 -9
- data/lib/chef_metal/transport.rb +7 -2
- data/lib/chef_metal/transport/ssh.rb +42 -9
- data/lib/chef_metal/transport/winrm.rb +8 -5
- data/lib/chef_metal/version.rb +1 -1
- data/spec/integration/machine.rb +29 -0
- metadata +21 -9
- data/lib/chef_metal/aws_credentials.rb +0 -58
- data/lib/chef_metal/openstack_credentials.rb +0 -44
- data/lib/chef_metal/provisioner.rb +0 -121
@@ -1,19 +1,80 @@
|
|
1
|
-
require 'cheffish/with_pattern'
|
2
1
|
require 'chef/mixin/deep_merge'
|
2
|
+
require 'cheffish/with_pattern'
|
3
|
+
require 'cheffish/merged_config'
|
4
|
+
require 'chef_metal/chef_machine_spec'
|
3
5
|
|
4
6
|
module ChefMetal
|
5
7
|
class ChefRunData
|
6
8
|
extend Cheffish::WithPattern
|
7
|
-
|
8
|
-
|
9
|
+
def initialize(config)
|
10
|
+
@config = config
|
11
|
+
@drivers = {}
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :config
|
15
|
+
attr_reader :drivers
|
16
|
+
|
17
|
+
with :driver
|
18
|
+
with :machine_options
|
9
19
|
with :machine_batch
|
10
20
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
21
|
+
def current_driver
|
22
|
+
@current_driver || config[:driver]
|
23
|
+
end
|
24
|
+
|
25
|
+
def current_machine_options
|
26
|
+
if @current_machine_options
|
27
|
+
@current_machine_options
|
28
|
+
elsif config[:drivers] && driver_for(current_driver) && config[:drivers][driver_for(current_driver).driver_url]
|
29
|
+
Cheffish::MergedConfig.new(config[:drivers][driver_for(current_driver).driver_url], config)[:machine_options] || {}
|
14
30
|
else
|
15
|
-
|
31
|
+
config[:machine_options] || {}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_machine_options(options, &block)
|
36
|
+
with_machine_options(Chef::Mixin::DeepMerge.hash_only_merge(current_machine_options, options), &block)
|
37
|
+
end
|
38
|
+
|
39
|
+
def driver_for(driver)
|
40
|
+
driver.is_a?(String) ? driver_for_url(driver) : driver
|
41
|
+
end
|
42
|
+
|
43
|
+
def driver_config_for(driver)
|
44
|
+
ChefMetal.config_for_url(driver_for(driver).driver_url, config)
|
45
|
+
end
|
46
|
+
|
47
|
+
def driver_for_url(driver_url)
|
48
|
+
drivers[driver_url] ||= begin
|
49
|
+
driver = ChefMetal.driver_for_url(driver_url, config)
|
50
|
+
# Check the canonicalized driver_url from the driver
|
51
|
+
if driver.driver_url != driver_url
|
52
|
+
drivers[driver.driver_url] ||= driver
|
53
|
+
else
|
54
|
+
driver
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def connect_to_machine(name, chef_server = nil)
|
60
|
+
if name.is_a?(MachineSpec)
|
61
|
+
machine_spec = name
|
62
|
+
else
|
63
|
+
machine_spec = ChefMetal::ChefMachineSpec.get(name, chef_server)
|
64
|
+
end
|
65
|
+
ChefMetal.connect_to_machine(machine_spec, config)
|
66
|
+
end
|
67
|
+
|
68
|
+
def keys
|
69
|
+
result = (config.keys || {}).dup
|
70
|
+
Array(config.key_path) do |key_path|
|
71
|
+
Dir.entries(key_path).each do |key|
|
72
|
+
if File.extname(key) == '.pem'
|
73
|
+
result[File.basename(key)[0..-5]] ||= key
|
74
|
+
end
|
75
|
+
end
|
16
76
|
end
|
77
|
+
result
|
17
78
|
end
|
18
79
|
end
|
19
80
|
end
|
@@ -1,14 +1,25 @@
|
|
1
1
|
module ChefMetal
|
2
2
|
class ConvergenceStrategy
|
3
|
-
|
3
|
+
# convergence_options - a freeform hash of options to the converger.
|
4
|
+
# config - a Chef::Config-like object with global config like :log_level
|
5
|
+
def initialize(convergence_options, config)
|
6
|
+
@convergence_options = convergence_options || {}
|
7
|
+
@config = config
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :convergence_options
|
11
|
+
attr_reader :config
|
12
|
+
|
13
|
+
# Get the machine ready to converge, but do not converge.
|
14
|
+
def setup_convergence(action_handler, machine)
|
4
15
|
raise "setup_convergence not overridden on #{self.class}"
|
5
16
|
end
|
6
17
|
|
7
|
-
def converge(action_handler, machine
|
18
|
+
def converge(action_handler, machine)
|
8
19
|
raise "converge not overridden on #{self.class}"
|
9
20
|
end
|
10
21
|
|
11
|
-
def cleanup_convergence(action_handler,
|
22
|
+
def cleanup_convergence(action_handler, machine_spec)
|
12
23
|
raise "cleanup_convergence not overridden on #{self.class}"
|
13
24
|
end
|
14
25
|
end
|
@@ -7,20 +7,32 @@ require 'thread'
|
|
7
7
|
module ChefMetal
|
8
8
|
class ConvergenceStrategy
|
9
9
|
class InstallCached < PrecreateChefObjects
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
# convergence_options is a hash of setup convergence_options, including:
|
11
|
+
# - :chef_server
|
12
|
+
# - :allow_overwrite_keys
|
13
|
+
# - :source_key, :source_key_path, :source_key_pass_phrase
|
14
|
+
# - :private_key_options
|
15
|
+
# - :ohai_hints
|
16
|
+
# - :public_key_path, :public_key_format
|
17
|
+
# - :admin, :validator
|
18
|
+
# - :chef_client_timeout
|
19
|
+
# - :client_rb_path, :client_pem_path
|
20
|
+
# - :chef_version, :prerelease, :package_cache_path
|
21
|
+
def initialize(convergence_options, config)
|
22
|
+
super
|
23
|
+
@convergence_options[:client_rb_path] ||= '/etc/chef/client.rb'
|
24
|
+
@convergence_options[:client_pem_path] ||= '/etc/chef/client.pem'
|
25
|
+
@chef_version ||= convergence_options[:chef_version]
|
26
|
+
@prerelease ||= convergence_options[:prerelease]
|
27
|
+
@package_cache_path ||= convergence_options[:package_cache_path] || "#{ENV['HOME']}/.chef/package_cache"
|
16
28
|
@package_cache = {}
|
17
29
|
@tmp_dir = '/tmp'
|
18
|
-
@chef_client_timeout =
|
30
|
+
@chef_client_timeout = convergence_options.has_key?(:chef_client_timeout) ? convergence_options[:chef_client_timeout] : 120*60 # Default: 2 hours
|
19
31
|
FileUtils.mkdir_p(@package_cache_path)
|
20
32
|
@package_cache_lock = Mutex.new
|
21
33
|
end
|
22
34
|
|
23
|
-
def setup_convergence(action_handler, machine
|
35
|
+
def setup_convergence(action_handler, machine)
|
24
36
|
super
|
25
37
|
|
26
38
|
# Install chef-client. TODO check and update version if not latest / not desired
|
@@ -33,12 +45,14 @@ module ChefMetal
|
|
33
45
|
end
|
34
46
|
end
|
35
47
|
|
36
|
-
def converge(action_handler, machine
|
48
|
+
def converge(action_handler, machine)
|
37
49
|
super
|
38
50
|
|
39
51
|
action_handler.open_stream(machine.node['name']) do |stdout|
|
40
52
|
action_handler.open_stream(machine.node['name']) do |stderr|
|
41
|
-
|
53
|
+
command_line = "chef-client"
|
54
|
+
command_line << "-l #{config[:log_level].to_s}" if config[:log_level]
|
55
|
+
machine.execute(action_handler, "chef-client",
|
42
56
|
:stream_stdout => stdout,
|
43
57
|
:stream_stderr => stderr,
|
44
58
|
:timeout => @chef_client_timeout)
|
@@ -6,19 +6,19 @@ module ChefMetal
|
|
6
6
|
class InstallMsi < PrecreateChefObjects
|
7
7
|
@@install_msi_cache = {}
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
@install_msi_url =
|
11
|
-
@install_msi_path =
|
12
|
-
@chef_client_timeout =
|
9
|
+
def initialize(convergence_options, config)
|
10
|
+
@install_msi_url = convergence_options[:install_msi_url] || 'http://www.opscode.com/chef/install.msi'
|
11
|
+
@install_msi_path = convergence_options[:install_msi_path] || "%TEMP%\\#{File.basename(@install_msi_url)}"
|
12
|
+
@chef_client_timeout = convergence_options.has_key?(:chef_client_timeout) ? convergence_options[:chef_client_timeout] : 120*60 # Default: 2 hours
|
13
13
|
end
|
14
14
|
|
15
15
|
attr_reader :install_msi_url
|
16
16
|
attr_reader :install_msi_path
|
17
17
|
|
18
|
-
def setup_convergence(action_handler, machine
|
18
|
+
def setup_convergence(action_handler, machine)
|
19
19
|
system_drive = machine.execute_always('$env:SystemDrive').stdout.strip
|
20
|
-
|
21
|
-
|
20
|
+
convergence_options[:client_rb_path] ||= "#{system_drive}\\chef\\client.rb"
|
21
|
+
convergence_options[:client_pem_path] ||= "#{system_drive}\\chef\\client.pem"
|
22
22
|
|
23
23
|
super
|
24
24
|
|
@@ -33,11 +33,18 @@ module ChefMetal
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
def converge(action_handler, machine
|
36
|
+
def converge(action_handler, machine)
|
37
37
|
super
|
38
|
-
|
38
|
+
|
39
39
|
# TODO For some reason I get a 500 back if I don't do -l debug
|
40
|
-
machine.
|
40
|
+
action_handler.open_stream(machine.node['name']) do |stdout|
|
41
|
+
action_handler.open_stream(machine.node['name']) do |stderr|
|
42
|
+
machine.execute(action_handler, "chef-client -l debug",
|
43
|
+
:stream_stdout => stdout,
|
44
|
+
:stream_stderr => stderr,
|
45
|
+
:timeout => @chef_client_timeout)
|
46
|
+
end
|
47
|
+
end
|
41
48
|
end
|
42
49
|
end
|
43
50
|
end
|
@@ -6,18 +6,19 @@ module ChefMetal
|
|
6
6
|
class InstallSh < PrecreateChefObjects
|
7
7
|
@@install_sh_cache = {}
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
|
11
|
-
@
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
9
|
+
def initialize(convergence_options, config)
|
10
|
+
super
|
11
|
+
@install_sh_url = convergence_options[:install_sh_url] || 'http://www.opscode.com/chef/install.sh'
|
12
|
+
@install_sh_path = convergence_options[:install_sh_path] || '/tmp/chef-install.sh'
|
13
|
+
@convergence_options[:client_rb_path] ||= '/etc/chef/client.rb'
|
14
|
+
@convergence_options[:client_pem_path] ||= '/etc/chef/client.pem'
|
15
|
+
@chef_client_timeout = convergence_options.has_key?(:chef_client_timeout) ? convergence_options[:chef_client_timeout] : 120*60 # Default: 2 hours
|
15
16
|
end
|
16
17
|
|
17
18
|
attr_reader :install_sh_url
|
18
19
|
attr_reader :install_sh_path
|
19
20
|
|
20
|
-
def setup_convergence(action_handler, machine
|
21
|
+
def setup_convergence(action_handler, machine)
|
21
22
|
super
|
22
23
|
|
23
24
|
# Install chef-client. TODO check and update version if not latest / not desired
|
@@ -29,10 +30,19 @@ module ChefMetal
|
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
32
|
-
def converge(action_handler, machine
|
33
|
+
def converge(action_handler, machine)
|
33
34
|
super
|
34
|
-
|
35
|
-
|
35
|
+
|
36
|
+
action_handler.open_stream(machine.node['name']) do |stdout|
|
37
|
+
action_handler.open_stream(machine.node['name']) do |stderr|
|
38
|
+
command_line = "chef-client"
|
39
|
+
command_line << "-l #{config[:log_level].to_s}" if config[:log_level]
|
40
|
+
machine.execute(action_handler, command_line,
|
41
|
+
:stream_stdout => stdout,
|
42
|
+
:stream_stderr => stderr,
|
43
|
+
:timeout => @chef_client_timeout)
|
44
|
+
end
|
45
|
+
end
|
36
46
|
end
|
37
47
|
end
|
38
48
|
end
|
@@ -5,23 +5,30 @@ require 'cheffish'
|
|
5
5
|
module ChefMetal
|
6
6
|
class ConvergenceStrategy
|
7
7
|
class NoConverge < ConvergenceStrategy
|
8
|
-
|
9
|
-
|
8
|
+
def initialize(convergence_options, config)
|
9
|
+
super
|
10
|
+
end
|
10
11
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
def chef_server
|
13
|
+
@chef_server ||= convergence_options[:chef_server] || Cheffish.default_chef_server(config)
|
14
|
+
end
|
15
|
+
|
16
|
+
def setup_convergence(action_handler, machine)
|
17
|
+
machine_spec.save(action_handler)
|
18
|
+
end
|
19
|
+
|
20
|
+
def converge(action_handler, machine)
|
20
21
|
end
|
21
22
|
|
22
|
-
def cleanup_convergence(action_handler,
|
23
|
+
def cleanup_convergence(action_handler, machine_spec)
|
24
|
+
_self = self
|
23
25
|
ChefMetal.inline_resource(action_handler) do
|
24
|
-
chef_node
|
26
|
+
chef_node machine_spec.name do
|
27
|
+
chef_server _self.chef_server
|
28
|
+
action :delete
|
29
|
+
end
|
30
|
+
chef_client machine_spec.name do
|
31
|
+
chef_server _self.chef_server
|
25
32
|
action :delete
|
26
33
|
end
|
27
34
|
end
|
@@ -5,44 +5,46 @@ require 'cheffish'
|
|
5
5
|
module ChefMetal
|
6
6
|
class ConvergenceStrategy
|
7
7
|
class PrecreateChefObjects < ConvergenceStrategy
|
8
|
-
def initialize(
|
8
|
+
def initialize(convergence_options, config)
|
9
9
|
super
|
10
|
-
@client_rb_path = options[:client_rb_path]
|
11
|
-
@client_pem_path = options[:client_pem_path]
|
12
10
|
end
|
13
11
|
|
14
|
-
|
15
|
-
|
12
|
+
def chef_server
|
13
|
+
@chef_server ||= convergence_options[:chef_server] || Cheffish.default_chef_server(config)
|
14
|
+
end
|
16
15
|
|
17
|
-
def setup_convergence(action_handler, machine
|
16
|
+
def setup_convergence(action_handler, machine)
|
18
17
|
# Create keys on machine
|
19
|
-
public_key = create_keys(action_handler, machine
|
18
|
+
public_key = create_keys(action_handler, machine)
|
20
19
|
# Create node and client on chef server
|
21
|
-
create_chef_objects(action_handler, machine,
|
20
|
+
create_chef_objects(action_handler, machine, public_key)
|
22
21
|
|
23
22
|
# If the chef server lives on localhost, tunnel the port through to the guest
|
24
23
|
# (we need to know what got tunneled!)
|
25
|
-
chef_server_url =
|
24
|
+
chef_server_url = chef_server[:chef_server_url]
|
26
25
|
chef_server_url = machine.make_url_available_to_remote(chef_server_url)
|
27
26
|
|
28
|
-
#Support for multiple ohai hints, required on some platforms
|
29
|
-
create_ohai_files(action_handler, machine
|
27
|
+
# Support for multiple ohai hints, required on some platforms
|
28
|
+
create_ohai_files(action_handler, machine)
|
30
29
|
|
31
30
|
# Create client.rb and client.pem on machine
|
32
31
|
content = client_rb_content(chef_server_url, machine.node['name'])
|
33
|
-
machine.write_file(action_handler, client_rb_path, content, :ensure_dir => true)
|
32
|
+
machine.write_file(action_handler, convergence_options[:client_rb_path], content, :ensure_dir => true)
|
34
33
|
end
|
35
34
|
|
36
|
-
def converge(action_handler, machine
|
35
|
+
def converge(action_handler, machine)
|
37
36
|
machine.make_url_available_to_remote(chef_server[:chef_server_url])
|
38
37
|
end
|
39
38
|
|
40
|
-
def cleanup_convergence(action_handler,
|
39
|
+
def cleanup_convergence(action_handler, machine_spec)
|
40
|
+
_self = self
|
41
41
|
ChefMetal.inline_resource(action_handler) do
|
42
|
-
chef_node
|
42
|
+
chef_node machine_spec.name do
|
43
|
+
chef_server _self.chef_server
|
43
44
|
action :delete
|
44
45
|
end
|
45
|
-
chef_client
|
46
|
+
chef_client machine_spec.name do
|
47
|
+
chef_server _self.chef_server
|
46
48
|
action :delete
|
47
49
|
end
|
48
50
|
end
|
@@ -50,8 +52,8 @@ module ChefMetal
|
|
50
52
|
|
51
53
|
protected
|
52
54
|
|
53
|
-
def create_keys(action_handler, machine
|
54
|
-
server_private_key = machine.read_file(client_pem_path)
|
55
|
+
def create_keys(action_handler, machine)
|
56
|
+
server_private_key = machine.read_file(convergence_options[:client_pem_path])
|
55
57
|
if server_private_key
|
56
58
|
begin
|
57
59
|
server_private_key, format = Cheffish::KeyFormatter.decode(server_private_key)
|
@@ -61,25 +63,25 @@ module ChefMetal
|
|
61
63
|
end
|
62
64
|
|
63
65
|
if server_private_key
|
64
|
-
source_key = source_key_for(machine_resource)
|
65
66
|
if source_key && server_private_key.to_pem != source_key.to_pem
|
66
67
|
# If the server private key does not match our source key, overwrite it
|
67
68
|
server_private_key = source_key
|
68
|
-
if
|
69
|
-
machine.write_file(action_handler, client_pem_path, server_private_key.to_pem, :ensure_dir => true)
|
69
|
+
if convergence_options[:allow_overwrite_keys]
|
70
|
+
machine.write_file(action_handler, convergence_options[:client_pem_path], server_private_key.to_pem, :ensure_dir => true)
|
70
71
|
else
|
71
|
-
raise "Private key on machine #{
|
72
|
+
raise "Private key on machine #{machine.name} does not match desired input key."
|
72
73
|
end
|
73
74
|
end
|
74
75
|
|
75
76
|
else
|
76
77
|
|
77
78
|
# If the server does not already have keys, create them and upload
|
79
|
+
_convergence_options = convergence_options
|
78
80
|
ChefMetal.inline_resource(action_handler) do
|
79
81
|
private_key 'in_memory' do
|
80
82
|
path :none
|
81
|
-
if
|
82
|
-
|
83
|
+
if _convergence_options[:private_key_options]
|
84
|
+
_convergence_options[:private_key_options].each_pair do |key,value|
|
83
85
|
send(key, value)
|
84
86
|
end
|
85
87
|
end
|
@@ -87,7 +89,7 @@ module ChefMetal
|
|
87
89
|
end
|
88
90
|
end
|
89
91
|
|
90
|
-
machine.write_file(action_handler, client_pem_path, server_private_key.to_pem, :ensure_dir => true)
|
92
|
+
machine.write_file(action_handler, convergence_options[:client_pem_path], server_private_key.to_pem, :ensure_dir => true)
|
91
93
|
end
|
92
94
|
|
93
95
|
server_private_key.public_key
|
@@ -97,14 +99,14 @@ module ChefMetal
|
|
97
99
|
host == '127.0.0.1' || host == 'localhost' || host == '[::1]'
|
98
100
|
end
|
99
101
|
|
100
|
-
def
|
101
|
-
if
|
102
|
-
key, format = Cheffish::KeyFormatter.decode(
|
102
|
+
def source_key
|
103
|
+
if convergence_options[:source_key].is_a?(String)
|
104
|
+
key, format = Cheffish::KeyFormatter.decode(convergence_options[:source_key], convergence_options[:source_key_pass_phrase])
|
103
105
|
key
|
104
|
-
elsif
|
105
|
-
|
106
|
-
elsif
|
107
|
-
key, format = Cheffish::KeyFormatter.decode(IO.read(
|
106
|
+
elsif convergence_options[:source_key]
|
107
|
+
convergence_options[:source_key]
|
108
|
+
elsif convergence_options[:source_key_path]
|
109
|
+
key, format = Cheffish::KeyFormatter.decode(IO.read(convergence_options[:source_key_path]), convergence_options[:source_key_pass_phrase], convergence_options[:source_key_path])
|
108
110
|
key
|
109
111
|
else
|
110
112
|
nil
|
@@ -112,9 +114,9 @@ module ChefMetal
|
|
112
114
|
end
|
113
115
|
|
114
116
|
# Create the ohai file(s)
|
115
|
-
def create_ohai_files(action_handler, machine
|
116
|
-
if
|
117
|
-
|
117
|
+
def create_ohai_files(action_handler, machine)
|
118
|
+
if convergence_options[:ohai_hints]
|
119
|
+
convergence_options[:ohai_hints].each_pair do |hint, data|
|
118
120
|
# The location of the ohai hint
|
119
121
|
ohai_hint = "/etc/chef/ohai/hints/#{hint}.json"
|
120
122
|
machine.write_file(action_handler, ohai_hint, data.to_json, :ensure_dir => true)
|
@@ -122,30 +124,32 @@ module ChefMetal
|
|
122
124
|
end
|
123
125
|
end
|
124
126
|
|
125
|
-
def create_chef_objects(action_handler, machine,
|
127
|
+
def create_chef_objects(action_handler, machine, public_key)
|
128
|
+
_convergence_options = convergence_options
|
129
|
+
_chef_server = chef_server
|
126
130
|
# Save the node and create the client keys and client.
|
127
131
|
ChefMetal.inline_resource(action_handler) do
|
128
132
|
# Create client
|
129
|
-
chef_client machine.
|
130
|
-
chef_server
|
133
|
+
chef_client machine.name do
|
134
|
+
chef_server _chef_server
|
131
135
|
source_key public_key
|
132
|
-
output_key_path
|
133
|
-
output_key_format
|
134
|
-
admin
|
135
|
-
validator
|
136
|
+
output_key_path _convergence_options[:public_key_path]
|
137
|
+
output_key_format _convergence_options[:public_key_format]
|
138
|
+
admin _convergence_options[:admin]
|
139
|
+
validator _convergence_options[:validator]
|
136
140
|
end
|
137
141
|
|
138
142
|
# Create node
|
139
143
|
# TODO strip automatic attributes first so we don't race with "current state"
|
140
|
-
chef_node machine.
|
141
|
-
chef_server
|
144
|
+
chef_node machine.name do
|
145
|
+
chef_server _chef_server
|
142
146
|
raw_json machine.node
|
143
147
|
end
|
144
148
|
end
|
145
149
|
|
146
150
|
# If using enterprise/hosted chef, fix acls
|
147
|
-
if
|
148
|
-
grant_client_node_permissions(
|
151
|
+
if chef_server[:chef_server_url] =~ /\/+organizations\/.+/
|
152
|
+
grant_client_node_permissions(chef_server, machine.name, ["read", "update"])
|
149
153
|
end
|
150
154
|
end
|
151
155
|
|
@@ -164,7 +168,7 @@ module ChefMetal
|
|
164
168
|
<<EOM
|
165
169
|
chef_server_url #{chef_server_url.inspect}
|
166
170
|
node_name #{node_name.inspect}
|
167
|
-
client_key #{client_pem_path.inspect}
|
171
|
+
client_key #{convergence_options[:client_pem_path].inspect}
|
168
172
|
EOM
|
169
173
|
end
|
170
174
|
end
|