chef 15.10.12 → 15.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +10 -10
- data/README.md +3 -3
- data/Rakefile +1 -1
- data/chef-universal-mingw32.gemspec +2 -2
- data/chef.gemspec +3 -3
- data/lib/chef/api_client/registration.rb +2 -2
- data/lib/chef/application/apply.rb +2 -2
- data/lib/chef/application/exit_code.rb +2 -2
- data/lib/chef/chef_fs/chef_fs_data_store.rb +3 -3
- data/lib/chef/chef_fs/file_system/chef_server/policies_dir.rb +1 -1
- data/lib/chef/chef_fs/file_system/chef_server/rest_list_dir.rb +1 -1
- data/lib/chef/chef_fs/file_system/multiplexed_dir.rb +1 -1
- data/lib/chef/chef_fs/file_system/repository/base_file.rb +1 -0
- data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb +2 -2
- data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb +1 -1
- data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb +2 -2
- data/lib/chef/chef_fs/file_system/repository/directory.rb +1 -1
- data/lib/chef/chef_fs/file_system/repository/file_system_entry.rb +1 -1
- data/lib/chef/chef_fs/path_utils.rb +3 -3
- data/lib/chef/cookbook/file_system_file_vendor.rb +1 -1
- data/lib/chef/cookbook_version.rb +4 -4
- data/lib/chef/data_bag.rb +2 -2
- data/lib/chef/data_collector/error_handlers.rb +1 -1
- data/lib/chef/deprecated.rb +13 -1
- data/lib/chef/dsl/declare_resource.rb +1 -1
- data/lib/chef/dsl/platform_introspection.rb +3 -1
- data/lib/chef/environment.rb +2 -2
- data/lib/chef/exceptions.rb +3 -0
- data/lib/chef/formatters/error_inspectors/node_load_error_inspector.rb +2 -2
- data/lib/chef/formatters/error_inspectors/registration_error_inspector.rb +7 -7
- data/lib/chef/http.rb +2 -1
- data/lib/chef/knife.rb +26 -20
- data/lib/chef/knife/bootstrap.rb +30 -31
- data/lib/chef/knife/bootstrap/chef_vault_handler.rb +12 -8
- data/lib/chef/knife/bootstrap/client_builder.rb +23 -19
- data/lib/chef/knife/bootstrap/templates/chef-full.erb +9 -9
- data/lib/chef/knife/bootstrap/templates/windows-chef-client-msi.erb +3 -1
- data/lib/chef/knife/bootstrap/train_connector.rb +1 -0
- data/lib/chef/knife/cookbook_download.rb +1 -1
- data/lib/chef/knife/cookbook_metadata.rb +1 -1
- data/lib/chef/knife/cookbook_site_search.rb +1 -1
- data/lib/chef/knife/cookbook_site_show.rb +1 -1
- data/lib/chef/knife/cookbook_site_unshare.rb +1 -1
- data/lib/chef/knife/core/gem_glob_loader.rb +1 -1
- data/lib/chef/knife/core/hashed_command_loader.rb +3 -2
- data/lib/chef/knife/core/subcommand_loader.rb +1 -1
- data/lib/chef/knife/core/windows_bootstrap_context.rb +18 -3
- data/lib/chef/knife/exec.rb +2 -2
- data/lib/chef/knife/ssh.rb +21 -2
- data/lib/chef/log.rb +1 -1
- data/lib/chef/mixin/create_path.rb +8 -8
- data/lib/chef/mixin/openssl_helper.rb +26 -3
- data/lib/chef/mixin/template.rb +1 -0
- data/lib/chef/node/mixin/deep_merge_cache.rb +7 -7
- data/lib/chef/node_map.rb +5 -2
- data/lib/chef/provider/mount/solaris.rb +0 -1
- data/lib/chef/provider/package/cab.rb +1 -1
- data/lib/chef/provider/package/chocolatey.rb +4 -3
- data/lib/chef/provider/package/msu.rb +1 -0
- data/lib/chef/provider/package/powershell.rb +5 -1
- data/lib/chef/provider/package/snap.rb +96 -27
- data/lib/chef/provider/package/zypper.rb +0 -1
- data/lib/chef/provider/service/arch.rb +2 -2
- data/lib/chef/provider/service/debian.rb +1 -1
- data/lib/chef/provider/service/gentoo.rb +2 -2
- data/lib/chef/provider/service/macosx.rb +2 -2
- data/lib/chef/provider/service/openbsd.rb +1 -1
- data/lib/chef/provider/service/redhat.rb +2 -2
- data/lib/chef/provider/service/simple.rb +3 -3
- data/lib/chef/provider/service/upstart.rb +1 -1
- data/lib/chef/provider/windows_task.rb +1 -1
- data/lib/chef/provider/yum_repository.rb +1 -1
- data/lib/chef/provider/zypper_repository.rb +31 -11
- data/lib/chef/resource.rb +2 -0
- data/lib/chef/resource/archive_file.rb +28 -8
- data/lib/chef/resource/build_essential.rb +1 -1
- data/lib/chef/resource/cron_access.rb +13 -5
- data/lib/chef/resource/cron_d.rb +1 -1
- data/lib/chef/resource/hostname.rb +19 -18
- data/lib/chef/resource/launchd.rb +4 -4
- data/lib/chef/resource/lwrp_base.rb +7 -0
- data/lib/chef/resource/macos_userdefaults.rb +3 -3
- data/lib/chef/resource/msu_package.rb +5 -0
- data/lib/chef/resource/ssh_known_hosts_entry.rb +1 -1
- data/lib/chef/resource/sudo.rb +2 -2
- data/lib/chef/resource/windows_feature_powershell.rb +6 -2
- data/lib/chef/resource/windows_firewall_rule.rb +8 -4
- data/lib/chef/resource/windows_font.rb +2 -1
- data/lib/chef/resource/windows_share.rb +4 -4
- data/lib/chef/resource/windows_task.rb +13 -13
- data/lib/chef/resource_inspector.rb +4 -3
- data/lib/chef/role.rb +2 -2
- data/lib/chef/shell.rb +1 -1
- data/lib/chef/shell/shell_session.rb +2 -0
- data/lib/chef/util/diff.rb +1 -1
- data/lib/chef/util/dsc/lcm_output_parser.rb +3 -3
- data/lib/chef/util/powershell/cmdlet.rb +1 -1
- data/lib/chef/version.rb +2 -2
- data/lib/chef/win32/api/command_line_helper.rb +89 -0
- data/lib/chef/win32/api/file.rb +18 -18
- data/lib/chef/win32/file.rb +3 -3
- data/lib/chef/win32/process.rb +2 -2
- data/spec/functional/knife/ssh_spec.rb +4 -4
- data/spec/functional/resource/aix_service_spec.rb +0 -1
- data/spec/functional/resource/aixinit_service_spec.rb +7 -8
- data/spec/functional/resource/apt_package_spec.rb +0 -1
- data/spec/functional/resource/bff_spec.rb +2 -2
- data/spec/functional/resource/chocolatey_package_spec.rb +29 -0
- data/spec/functional/resource/cookbook_file_spec.rb +1 -1
- data/spec/functional/resource/cron_spec.rb +0 -1
- data/spec/functional/resource/dsc_resource_spec.rb +1 -1
- data/spec/functional/resource/insserv_spec.rb +4 -5
- data/spec/functional/resource/link_spec.rb +17 -17
- data/spec/functional/resource/msu_package_spec.rb +5 -2
- data/spec/functional/resource/rpm_spec.rb +2 -2
- data/spec/functional/resource/user/dscl_spec.rb +2 -2
- data/spec/functional/resource/user/mac_user_spec.rb +2 -2
- data/spec/functional/resource/windows_certificate_spec.rb +3 -3
- data/spec/functional/resource/windows_font_spec.rb +49 -0
- data/spec/functional/resource/windows_task_spec.rb +8 -8
- data/spec/functional/run_lock_spec.rb +2 -1
- data/spec/functional/util/powershell/cmdlet_spec.rb +1 -1
- data/spec/functional/version_spec.rb +1 -1
- data/spec/functional/win32/service_manager_spec.rb +1 -1
- data/spec/integration/recipes/accumulator_spec.rb +1 -1
- data/spec/integration/recipes/lwrp_inline_resources_spec.rb +2 -2
- data/spec/integration/recipes/lwrp_spec.rb +1 -1
- data/spec/integration/recipes/notifies_spec.rb +1 -1
- data/spec/integration/recipes/notifying_block_spec.rb +1 -1
- data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
- data/spec/integration/recipes/resource_converge_if_changed_spec.rb +2 -0
- data/spec/integration/recipes/resource_load_spec.rb +1 -0
- data/spec/integration/recipes/unified_mode_spec.rb +1 -1
- data/spec/scripts/ssl-serve.rb +1 -1
- data/spec/spec_helper.rb +26 -19
- data/spec/support/chef_helpers.rb +1 -1
- data/spec/support/platform_helpers.rb +12 -42
- data/spec/support/platforms/win32/spec_service.rb +1 -1
- data/spec/support/shared/functional/directory_resource.rb +1 -1
- data/spec/support/shared/functional/execute_resource.rb +1 -1
- data/spec/support/shared/functional/file_resource.rb +3 -3
- data/spec/support/shared/functional/win32_service.rb +1 -1
- data/spec/support/shared/functional/windows_script.rb +3 -3
- data/spec/support/shared/integration/knife_support.rb +2 -5
- data/spec/unit/application_spec.rb +7 -0
- data/spec/unit/chef_fs/file_system/operation_failed_error_spec.rb +2 -4
- data/spec/unit/cookbook/gem_installer_spec.rb +2 -1
- data/spec/unit/data_bag_spec.rb +1 -1
- data/spec/unit/data_collector_spec.rb +1 -1
- data/spec/unit/dsl/platform_introspection_spec.rb +1 -0
- data/spec/unit/environment_spec.rb +7 -7
- data/spec/unit/event_dispatch/dispatcher_spec.rb +3 -0
- data/spec/unit/file_access_control_spec.rb +1 -1
- data/spec/unit/json_compat_spec.rb +1 -1
- data/spec/unit/knife/bootstrap_spec.rb +26 -29
- data/spec/unit/knife/cookbook_download_spec.rb +4 -4
- data/spec/unit/knife/cookbook_metadata_from_file_spec.rb +1 -1
- data/spec/unit/knife/cookbook_upload_spec.rb +5 -6
- data/spec/unit/knife/core/hashed_command_loader_spec.rb +3 -3
- data/spec/unit/knife/core/windows_bootstrap_context_spec.rb +6 -0
- data/spec/unit/knife/role_env_run_list_add_spec.rb +6 -6
- data/spec/unit/knife/role_env_run_list_clear_spec.rb +4 -4
- data/spec/unit/knife/role_env_run_list_remove_spec.rb +4 -4
- data/spec/unit/knife/role_env_run_list_replace_spec.rb +4 -4
- data/spec/unit/knife/role_env_run_list_set_spec.rb +4 -4
- data/spec/unit/knife/role_run_list_add_spec.rb +6 -6
- data/spec/unit/knife/role_run_list_clear_spec.rb +4 -4
- data/spec/unit/knife/role_run_list_remove_spec.rb +4 -4
- data/spec/unit/knife/role_run_list_replace_spec.rb +4 -4
- data/spec/unit/knife/role_run_list_set_spec.rb +4 -4
- data/spec/unit/knife/ssh_spec.rb +2 -2
- data/spec/unit/knife/supermarket_share_spec.rb +1 -1
- data/spec/unit/lwrp_spec.rb +4 -4
- data/spec/unit/mixin/securable_spec.rb +0 -1
- data/spec/unit/mixin/user_context_spec.rb +1 -9
- data/spec/unit/property_spec.rb +6 -6
- data/spec/unit/provider/apt_repository_spec.rb +2 -2
- data/spec/unit/provider/git_spec.rb +3 -3
- data/spec/unit/provider/osx_profile_spec.rb +2 -2
- data/spec/unit/provider/package/chocolatey_spec.rb +1 -1
- data/spec/unit/provider/package/dnf/python_helper_spec.rb +1 -1
- data/spec/unit/provider/package/msu_spec.rb +3 -3
- data/spec/unit/provider/package/powershell_spec.rb +95 -86
- data/spec/unit/provider/package/rubygems_spec.rb +5 -10
- data/spec/unit/provider/package/snap_spec.rb +1 -1
- data/spec/unit/provider/package/windows_spec.rb +30 -53
- data/spec/unit/provider/service/arch_service_spec.rb +3 -2
- data/spec/unit/provider/service/debian_service_spec.rb +1 -1
- data/spec/unit/provider/service/gentoo_service_spec.rb +8 -8
- data/spec/unit/provider/service/macosx_spec.rb +3 -3
- data/spec/unit/provider/service/redhat_spec.rb +2 -2
- data/spec/unit/provider/service/upstart_service_spec.rb +3 -3
- data/spec/unit/provider/service/windows_spec.rb +2 -6
- data/spec/unit/provider/systemd_unit_spec.rb +28 -24
- data/spec/unit/provider/zypper_repository_spec.rb +75 -25
- data/spec/unit/provider_resolver_spec.rb +9 -9
- data/spec/unit/provider_spec.rb +1 -0
- data/spec/unit/resource/archive_file_spec.rb +11 -2
- data/spec/unit/resource/msu_package_spec.rb +4 -0
- data/spec/unit/resource/windows_dns_record_spec.rb +3 -3
- data/spec/unit/resource/windows_dns_zone_spec.rb +2 -2
- data/spec/unit/resource/windows_feature_powershell_spec.rb +30 -4
- data/spec/unit/resource/windows_package_spec.rb +1 -0
- data/spec/unit/resource/windows_task_spec.rb +1 -1
- data/spec/unit/resource/windows_uac_spec.rb +2 -2
- data/spec/unit/resource/yum_repository_spec.rb +21 -21
- data/spec/unit/resource_reporter_spec.rb +1 -1
- data/spec/unit/resource_spec.rb +1 -1
- data/spec/unit/role_spec.rb +11 -11
- data/spec/unit/run_context/cookbook_compiler_spec.rb +1 -1
- data/spec/unit/run_context_spec.rb +1 -1
- data/spec/unit/run_lock_spec.rb +1 -1
- data/spec/unit/scan_access_control_spec.rb +1 -1
- data/spec/unit/util/threaded_job_queue_spec.rb +9 -0
- data/spec/unit/win32/security_spec.rb +4 -3
- data/tasks/rspec.rb +5 -13
- metadata +24 -16
data/lib/chef/exceptions.rb
CHANGED
@@ -198,6 +198,7 @@ class Chef
|
|
198
198
|
class MetadataNotFound < StandardError
|
199
199
|
attr_reader :install_path
|
200
200
|
attr_reader :cookbook_name
|
201
|
+
|
201
202
|
def initialize(install_path, cookbook_name)
|
202
203
|
@install_path = install_path
|
203
204
|
@cookbook_name = cookbook_name
|
@@ -448,6 +449,7 @@ class Chef
|
|
448
449
|
# to correctly populate the backtrace with the wrapped backtraces.
|
449
450
|
class RunFailedWrappingError < RuntimeError
|
450
451
|
attr_reader :wrapped_errors
|
452
|
+
|
451
453
|
def initialize(*errors)
|
452
454
|
errors = errors.select { |e| !e.nil? }
|
453
455
|
output = "Found #{errors.size} errors, they are stored in the backtrace"
|
@@ -488,6 +490,7 @@ class Chef
|
|
488
490
|
|
489
491
|
class MultipleDscResourcesFound < RuntimeError
|
490
492
|
attr_reader :resources_found
|
493
|
+
|
491
494
|
def initialize(resources_found)
|
492
495
|
@resources_found = resources_found
|
493
496
|
matches_info = @resources_found.each do |r|
|
@@ -46,7 +46,7 @@ class Chef
|
|
46
46
|
when Chef::Exceptions::PrivateKeyMissing
|
47
47
|
error_description.section("Private Key Not Found:", <<~E)
|
48
48
|
Your private key could not be loaded. If the key file exists, ensure that it is
|
49
|
-
readable by #{Chef::Dist::
|
49
|
+
readable by #{Chef::Dist::PRODUCT}.
|
50
50
|
E
|
51
51
|
error_description.section("Relevant Config Settings:", <<~E)
|
52
52
|
client_key "#{api_key}"
|
@@ -99,7 +99,7 @@ class Chef
|
|
99
99
|
# redirect.
|
100
100
|
def describe_404_error(error_description)
|
101
101
|
error_description.section("Resource Not Found:", <<~E)
|
102
|
-
The
|
102
|
+
The #{Chef::Dist::SERVER_PRODUCT} returned a HTTP 404. This usually indicates that your chef_server_url is incorrect.
|
103
103
|
E
|
104
104
|
error_description.section("Relevant Config Settings:", <<~E)
|
105
105
|
chef_server_url "#{server_url}"
|
@@ -28,7 +28,7 @@ class Chef
|
|
28
28
|
humanize_http_exception(error_description)
|
29
29
|
when Errno::ECONNREFUSED, Timeout::Error, Errno::ETIMEDOUT, SocketError
|
30
30
|
error_description.section("Network Error:", <<~E)
|
31
|
-
There was a network error connecting to the Chef
|
31
|
+
There was a network error connecting to the #{Chef::Dist::SERVER_PRODUCT}:
|
32
32
|
#{exception.message}
|
33
33
|
E
|
34
34
|
error_description.section("Relevant Config Settings:", <<~E)
|
@@ -39,14 +39,14 @@ class Chef
|
|
39
39
|
when Chef::Exceptions::PrivateKeyMissing
|
40
40
|
error_description.section("Private Key Not Found:", <<~E)
|
41
41
|
Your private key could not be loaded. If the key file exists, ensure that it is
|
42
|
-
readable by #{Chef::Dist::
|
42
|
+
readable by #{Chef::Dist::PRODUCT}.
|
43
43
|
E
|
44
44
|
error_description.section("Relevant Config Settings:", <<~E)
|
45
45
|
validation_key "#{api_key}"
|
46
46
|
E
|
47
47
|
when Chef::Exceptions::InvalidRedirect
|
48
48
|
error_description.section("Invalid Redirect:", <<~E)
|
49
|
-
Change your
|
49
|
+
Change your #{Chef::Dist::SERVER_PRODUCT} location in client.rb to the #{Chef::Dist::SERVER_PRODUCT}'s FQDN to avoid unwanted redirections.
|
50
50
|
E
|
51
51
|
when EOFError
|
52
52
|
describe_eof_error(error_description)
|
@@ -61,13 +61,13 @@ class Chef
|
|
61
61
|
when Net::HTTPUnauthorized
|
62
62
|
if clock_skew?
|
63
63
|
error_description.section("Authentication Error:", <<~E)
|
64
|
-
Failed to authenticate to the
|
64
|
+
Failed to authenticate to the #{Chef::Dist::SERVER_PRODUCT} (http 401).
|
65
65
|
The request failed because your clock has drifted by more than 15 minutes.
|
66
66
|
Syncing your clock to an NTP Time source should resolve the issue.
|
67
67
|
E
|
68
68
|
else
|
69
69
|
error_description.section("Authentication Error:", <<~E)
|
70
|
-
Failed to authenticate to the
|
70
|
+
Failed to authenticate to the #{Chef::Dist::SERVER_PRODUCT} (http 401).
|
71
71
|
E
|
72
72
|
|
73
73
|
error_description.section("Server Response:", format_rest_error)
|
@@ -81,7 +81,7 @@ class Chef
|
|
81
81
|
end
|
82
82
|
when Net::HTTPForbidden
|
83
83
|
error_description.section("Authorization Error:", <<~E)
|
84
|
-
Your validation client is not authorized to create the client for this node (HTTP 403).
|
84
|
+
Your validation client is not authorized to create the client for this node on the #{Chef::Dist::SERVER_PRODUCT} (HTTP 403).
|
85
85
|
E
|
86
86
|
error_description.section("Possible Causes:", <<~E)
|
87
87
|
* There may already be a client named "#{config[:node_name]}"
|
@@ -94,7 +94,7 @@ class Chef
|
|
94
94
|
error_description.section("Server Response:", format_rest_error)
|
95
95
|
when Net::HTTPNotFound
|
96
96
|
error_description.section("Resource Not Found:", <<~E)
|
97
|
-
The
|
97
|
+
The #{Chef::Dist::SERVER_PRODUCT} returned a HTTP 404. This usually indicates that your chef_server_url configuration is incorrect.
|
98
98
|
E
|
99
99
|
error_description.section("Relevant Config Settings:", <<~E)
|
100
100
|
chef_server_url "#{server_url}"
|
data/lib/chef/http.rb
CHANGED
@@ -22,7 +22,8 @@
|
|
22
22
|
#
|
23
23
|
|
24
24
|
require "tempfile" unless defined?(Tempfile)
|
25
|
-
require "
|
25
|
+
require "openssl" unless defined?(OpenSSL)
|
26
|
+
require "net/http" unless defined?(Net::HTTP)
|
26
27
|
require "uri" unless defined?(URI)
|
27
28
|
require_relative "http/basic_client"
|
28
29
|
require_relative "monkey_patches/net_http"
|
data/lib/chef/knife.rb
CHANGED
@@ -345,31 +345,35 @@ class Chef
|
|
345
345
|
exit(1)
|
346
346
|
end
|
347
347
|
|
348
|
-
#
|
349
|
-
|
350
|
-
|
348
|
+
# This is all set and default mixlib-config values. We only need the default
|
349
|
+
# values here (the set values are explicitly mixed in again later), but there is
|
350
|
+
# no mixlib-config API to get a Hash back with only the default values.
|
351
|
+
#
|
352
|
+
# Assumption: since config_file_defaults is the lowest precedence it doesn't matter
|
353
|
+
# that we include the set values here, but this is a hack and makes the name of the
|
354
|
+
# method a lie. FIXME: make the name not a lie by adding an API to mixlib-config.
|
355
|
+
#
|
356
|
+
# @api private
|
357
|
+
#
|
358
|
+
def config_file_defaults
|
359
|
+
Chef::Config[:knife].save(true) # this is like "dup" to a (real) Hash, and includes default values (and user set values)
|
351
360
|
end
|
352
361
|
|
353
|
-
#
|
354
|
-
#
|
362
|
+
# This is only the user-set mixlib-config values. We do not include the defaults
|
363
|
+
# here so that the config defaults do not override the cli defaults.
|
364
|
+
#
|
365
|
+
# @api private
|
355
366
|
#
|
356
|
-
# NOTE: due to weirdness in mixlib-config #has_key? is only true if the value has
|
357
|
-
# been set by the user -- the Chef::Config defaults return #has_key?() of false and
|
358
|
-
# this code DEPENDS on that functionality since applying the default values in
|
359
|
-
# Chef::Config[:knife] would break the defaults in the cli that we would otherwise
|
360
|
-
# overwrite.
|
361
367
|
def config_file_settings
|
362
|
-
|
363
|
-
if Chef::Config[:knife].key?(key)
|
364
|
-
memo[key] = Chef::Config[:knife][key]
|
365
|
-
end
|
366
|
-
end
|
368
|
+
Chef::Config[:knife].save(false) # this is like "dup" to a (real) Hash, and does not include default values (just user set values)
|
367
369
|
end
|
368
370
|
|
369
371
|
# config is merged in this order (inverse of precedence)
|
370
|
-
#
|
371
|
-
#
|
372
|
-
#
|
372
|
+
# config_file_defaults - Chef::Config[:knife] defaults from chef-config (XXX: this also includes the settings, but they get overwritten)
|
373
|
+
# default_config - mixlib-cli defaults (accessor from mixlib-cli)
|
374
|
+
# config_file_settings - Chef::Config[:knife] user settings from the client.rb file
|
375
|
+
# config - mixlib-cli settings (accessor from mixlib-cli)
|
376
|
+
#
|
373
377
|
def merge_configs
|
374
378
|
# Update our original_config - if someone has created a knife command
|
375
379
|
# instance directly, they are likely ot have set cmd.config values directly
|
@@ -377,7 +381,7 @@ class Chef
|
|
377
381
|
@original_config = config.dup
|
378
382
|
# other code may have a handle to the config object, so use Hash#replace to deliberately
|
379
383
|
# update-in-place.
|
380
|
-
config.replace(default_config.merge(config_file_settings).merge(config))
|
384
|
+
config.replace(config_file_defaults.merge(default_config).merge(config_file_settings).merge(config))
|
381
385
|
end
|
382
386
|
|
383
387
|
#
|
@@ -387,8 +391,9 @@ class Chef
|
|
387
391
|
# @return [Symbol,NilClass] return the source of the config key,
|
388
392
|
# one of:
|
389
393
|
# - :cli - this was explicitly provided on the CLI
|
390
|
-
# - :config - this came from Chef::Config[:knife]
|
394
|
+
# - :config - this came from Chef::Config[:knife] explicitly being set
|
391
395
|
# - :cli_default - came from a declared CLI `option`'s `default` value.
|
396
|
+
# - :config_default - this came from Chef::Config[:knife]'s defaults
|
392
397
|
# - nil - if the key could not be found in any source.
|
393
398
|
# This can happen when it is invalid, or has been
|
394
399
|
# set directly into #config without then calling #merge_config
|
@@ -396,6 +401,7 @@ class Chef
|
|
396
401
|
return :cli if @original_config.include? key
|
397
402
|
return :config if config_file_settings.key? key
|
398
403
|
return :cli_default if default_config.include? key
|
404
|
+
return :config_default if config_file_defaults.key? key # must come after :config check
|
399
405
|
|
400
406
|
nil
|
401
407
|
end
|
data/lib/chef/knife/bootstrap.rb
CHANGED
@@ -94,13 +94,13 @@ class Chef
|
|
94
94
|
description: "For WinRM basic authentication when using the 'ssl' auth method.",
|
95
95
|
boolean: true
|
96
96
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
97
|
+
# This option was provided in knife bootstrap windows winrm,
|
98
|
+
# but it is ignored in knife-windows/WinrmSession, and so remains unimplemeneted here.
|
99
|
+
# option :kerberos_keytab_file,
|
100
|
+
# :short => "-T KEYTAB_FILE",
|
101
|
+
# :long => "--keytab-file KEYTAB_FILE",
|
102
|
+
# :description => "The Kerberos keytab file used for authentication",
|
103
|
+
# :proc => Proc.new { |keytab| Chef::Config[:knife][:kerberos_keytab_file] = keytab }
|
104
104
|
|
105
105
|
option :kerberos_realm,
|
106
106
|
short: "-R KERBEROS_REALM",
|
@@ -497,7 +497,7 @@ class Chef
|
|
497
497
|
template = bootstrap_template
|
498
498
|
|
499
499
|
# Use the template directly if it's a path to an actual file
|
500
|
-
if File.
|
500
|
+
if File.exist?(template)
|
501
501
|
Chef::Log.trace("Using the specified bootstrap template: #{File.dirname(template)}")
|
502
502
|
return template
|
503
503
|
end
|
@@ -512,7 +512,7 @@ class Chef
|
|
512
512
|
|
513
513
|
template_file = Array(bootstrap_files).find do |bootstrap_template|
|
514
514
|
Chef::Log.trace("Looking for bootstrap template in #{File.dirname(bootstrap_template)}")
|
515
|
-
File.
|
515
|
+
File.exist?(bootstrap_template)
|
516
516
|
end
|
517
517
|
|
518
518
|
unless template_file
|
@@ -555,7 +555,7 @@ class Chef
|
|
555
555
|
end
|
556
556
|
|
557
557
|
def run
|
558
|
-
check_license
|
558
|
+
check_license if ChefConfig::Dist::ENFORCE_LICENSE
|
559
559
|
|
560
560
|
plugin_setup!
|
561
561
|
validate_name_args!
|
@@ -597,11 +597,8 @@ class Chef
|
|
597
597
|
|
598
598
|
bootstrap_context.client_pem = client_builder.client_path
|
599
599
|
else
|
600
|
-
ui.
|
601
|
-
|
602
|
-
Delete your validation key in order to use your user credentials for client registration instead.
|
603
|
-
EOM
|
604
|
-
|
600
|
+
ui.warn "Performing legacy client registration with the validation key at #{Chef::Config[:validation_key]}..."
|
601
|
+
ui.warn "Remove the key file or remove the 'validation_key' configuration option from your config.rb (knife.rb) to use more secure user credentials for client registration."
|
605
602
|
end
|
606
603
|
end
|
607
604
|
|
@@ -619,7 +616,7 @@ class Chef
|
|
619
616
|
end
|
620
617
|
|
621
618
|
def connect!
|
622
|
-
ui.info("Connecting to #{ui.color(server_name, :bold)}")
|
619
|
+
ui.info("Connecting to #{ui.color(server_name, :bold)} using #{connection_protocol}")
|
623
620
|
opts ||= connection_opts.dup
|
624
621
|
do_connect(opts)
|
625
622
|
rescue Train::Error => e
|
@@ -1061,24 +1058,25 @@ class Chef
|
|
1061
1058
|
}
|
1062
1059
|
end
|
1063
1060
|
|
1064
|
-
#
|
1065
|
-
#
|
1066
|
-
#
|
1067
|
-
#
|
1061
|
+
# Knife plugins should just use the config hash and not call this method. In the
|
1062
|
+
# future there will be a way to deprecate Chef::Config options in addition to the
|
1063
|
+
# CLI options, which will eliminate this methods primary purpose.
|
1064
|
+
#
|
1065
|
+
# In Chef-16 the single-argument verison of this function will be deprecated and
|
1066
|
+
# config_value(:whatver) should be converted to config[:whatever]. That never had
|
1067
|
+
# any purpose and never should have been used this way.
|
1068
1068
|
#
|
1069
|
-
#
|
1070
|
-
# key is different from the CLI flag lookup key.
|
1069
|
+
# @api deprecated
|
1071
1070
|
#
|
1072
|
-
def config_value(key,
|
1073
|
-
if config.key?
|
1071
|
+
def config_value(key, fallback_key = nil, default = nil)
|
1072
|
+
if config.key?(key)
|
1073
|
+
# the first key is the primary key so we check the merged hash first
|
1074
1074
|
config[key]
|
1075
|
+
elsif config.key?(fallback_key)
|
1076
|
+
# we get the old config option here (the deprecated cli option shouldn't exist)
|
1077
|
+
config[fallback_key]
|
1075
1078
|
else
|
1076
|
-
|
1077
|
-
if Chef::Config[:knife].key?(lookup_key) || config.key?(lookup_key)
|
1078
|
-
Chef::Config[:knife][lookup_key] || config[lookup_key]
|
1079
|
-
else
|
1080
|
-
default
|
1081
|
-
end
|
1079
|
+
default
|
1082
1080
|
end
|
1083
1081
|
end
|
1084
1082
|
|
@@ -1107,7 +1105,8 @@ class Chef
|
|
1107
1105
|
# These keys are available in Chef::Config, and are prefixed with the protocol name.
|
1108
1106
|
# For example, :user CLI option will map to :winrm_user and :ssh_user Chef::Config keys,
|
1109
1107
|
# based on the connection protocol in use.
|
1110
|
-
def knife_key_for_protocol(
|
1108
|
+
def knife_key_for_protocol(new_option, option = nil)
|
1109
|
+
option = new_option if option.nil? # hacky compat with both old Chef-15 style and new Chef-16 style API signature
|
1111
1110
|
"#{connection_protocol}_#{option}".to_sym
|
1112
1111
|
end
|
1113
1112
|
|
@@ -21,7 +21,7 @@ class Chef
|
|
21
21
|
class ChefVaultHandler
|
22
22
|
|
23
23
|
# @return [Hash] knife merged config, typically @config
|
24
|
-
attr_accessor :
|
24
|
+
attr_accessor :config
|
25
25
|
|
26
26
|
# @return [Chef::Knife::UI] ui object for output
|
27
27
|
attr_accessor :ui
|
@@ -29,11 +29,15 @@ class Chef
|
|
29
29
|
# @return [Chef::ApiClient] vault client
|
30
30
|
attr_reader :client
|
31
31
|
|
32
|
-
# @param
|
32
|
+
# @param config [Hash] knife merged config, typically @config
|
33
33
|
# @param ui [Chef::Knife::UI] ui object for output
|
34
|
-
def initialize(
|
35
|
-
@
|
36
|
-
|
34
|
+
def initialize(config: {}, knife_config: nil, ui: nil)
|
35
|
+
@config = config
|
36
|
+
unless knife_config.nil?
|
37
|
+
# the knife_config argument becomes deprecated in Chef-16, don't use it
|
38
|
+
@config = knife_config
|
39
|
+
end
|
40
|
+
@ui = ui
|
37
41
|
end
|
38
42
|
|
39
43
|
# Updates the chef vault items for the newly created client.
|
@@ -85,17 +89,17 @@ class Chef
|
|
85
89
|
|
86
90
|
# @return [String] string with serialized JSON representing the chef vault items
|
87
91
|
def bootstrap_vault_json
|
88
|
-
|
92
|
+
config[:bootstrap_vault_json]
|
89
93
|
end
|
90
94
|
|
91
95
|
# @return [String] JSON text in a file representing the chef vault items
|
92
96
|
def bootstrap_vault_file
|
93
|
-
|
97
|
+
config[:bootstrap_vault_file]
|
94
98
|
end
|
95
99
|
|
96
100
|
# @return [Hash] Ruby object representing the chef vault items to create
|
97
101
|
def bootstrap_vault_item
|
98
|
-
|
102
|
+
config[:bootstrap_vault_item]
|
99
103
|
end
|
100
104
|
|
101
105
|
# Helper to return a ruby object represeting all the data bags and items
|
@@ -28,7 +28,7 @@ class Chef
|
|
28
28
|
class ClientBuilder
|
29
29
|
|
30
30
|
# @return [Hash] knife merged config, typically @config
|
31
|
-
attr_accessor :
|
31
|
+
attr_accessor :config
|
32
32
|
# @return [Hash] chef config object
|
33
33
|
attr_accessor :chef_config
|
34
34
|
# @return [Chef::Knife::UI] ui object for output
|
@@ -36,13 +36,17 @@ class Chef
|
|
36
36
|
# @return [Chef::ApiClient] client saved on run
|
37
37
|
attr_reader :client
|
38
38
|
|
39
|
-
# @param
|
39
|
+
# @param config [Hash] Hash of knife config settings
|
40
40
|
# @param chef_config [Hash] Hash of chef config settings
|
41
41
|
# @param ui [Chef::Knife::UI] UI object for output
|
42
|
-
def initialize(
|
43
|
-
@
|
44
|
-
|
45
|
-
|
42
|
+
def initialize(config: {}, knife_config: nil, chef_config: {}, ui: nil)
|
43
|
+
@config = config
|
44
|
+
unless knife_config.nil?
|
45
|
+
# the knife_config argument becomes deprecated in Chef-16, don't use it
|
46
|
+
@config = knife_config
|
47
|
+
end
|
48
|
+
@chef_config = chef_config
|
49
|
+
@ui = ui
|
46
50
|
end
|
47
51
|
|
48
52
|
# Main entry. Prompt the user to clean up any old client or node objects. Then create
|
@@ -77,34 +81,34 @@ class Chef
|
|
77
81
|
|
78
82
|
private
|
79
83
|
|
80
|
-
# @return [String] node name from the
|
84
|
+
# @return [String] node name from the config
|
81
85
|
def node_name
|
82
|
-
|
86
|
+
config[:chef_node_name]
|
83
87
|
end
|
84
88
|
|
85
|
-
# @return [String] enviroment from the
|
89
|
+
# @return [String] enviroment from the config
|
86
90
|
def environment
|
87
|
-
|
91
|
+
config[:environment]
|
88
92
|
end
|
89
93
|
|
90
|
-
# @return [String] run_list from the
|
94
|
+
# @return [String] run_list from the config
|
91
95
|
def run_list
|
92
|
-
|
96
|
+
config[:run_list]
|
93
97
|
end
|
94
98
|
|
95
|
-
# @return [String] policy_name from the
|
99
|
+
# @return [String] policy_name from the config
|
96
100
|
def policy_name
|
97
|
-
|
101
|
+
config[:policy_name]
|
98
102
|
end
|
99
103
|
|
100
|
-
# @return [String] policy_group from the
|
104
|
+
# @return [String] policy_group from the config
|
101
105
|
def policy_group
|
102
|
-
|
106
|
+
config[:policy_group]
|
103
107
|
end
|
104
108
|
|
105
|
-
# @return [Hash,Array] Object representation of json first-boot attributes from the
|
109
|
+
# @return [Hash,Array] Object representation of json first-boot attributes from the config
|
106
110
|
def first_boot_attributes
|
107
|
-
|
111
|
+
config[:first_boot_attributes]
|
108
112
|
end
|
109
113
|
|
110
114
|
# @return [String] chef server url from the Chef::Config
|
@@ -154,7 +158,7 @@ class Chef
|
|
154
158
|
node.environment(environment) if environment
|
155
159
|
node.policy_name = policy_name if policy_name
|
156
160
|
node.policy_group = policy_group if policy_group
|
157
|
-
(
|
161
|
+
(config[:tags] || []).each do |tag|
|
158
162
|
node.tags << tag
|
159
163
|
end
|
160
164
|
node
|
@@ -185,50 +185,50 @@ if test "x$tmp_dir" != "x"; then
|
|
185
185
|
rm -r "$tmp_dir"
|
186
186
|
fi
|
187
187
|
|
188
|
-
mkdir -p
|
188
|
+
mkdir -p /etc/chef
|
189
189
|
|
190
190
|
<% if client_pem -%>
|
191
|
-
(umask 077 && (cat >
|
191
|
+
(umask 077 && (cat > /etc/chef/client.pem <<'EOP'
|
192
192
|
<%= ::File.read(::File.expand_path(client_pem)) %>
|
193
193
|
EOP
|
194
194
|
)) || exit 1
|
195
195
|
<% end -%>
|
196
196
|
|
197
197
|
<% if validation_key -%>
|
198
|
-
(umask 077 && (cat >
|
198
|
+
(umask 077 && (cat > /etc/chef/validation.pem <<'EOP'
|
199
199
|
<%= validation_key %>
|
200
200
|
EOP
|
201
201
|
)) || exit 1
|
202
202
|
<% end -%>
|
203
203
|
|
204
204
|
<% if encrypted_data_bag_secret -%>
|
205
|
-
(umask 077 && (cat >
|
205
|
+
(umask 077 && (cat > /etc/chef/encrypted_data_bag_secret <<'EOP'
|
206
206
|
<%= encrypted_data_bag_secret %>
|
207
207
|
EOP
|
208
208
|
)) || exit 1
|
209
209
|
<% end -%>
|
210
210
|
|
211
211
|
<% unless trusted_certs.empty? -%>
|
212
|
-
mkdir -p
|
212
|
+
mkdir -p /etc/chef/trusted_certs
|
213
213
|
<%= trusted_certs %>
|
214
214
|
<% end -%>
|
215
215
|
|
216
216
|
<%# Generate Ohai Hints -%>
|
217
217
|
<% unless @chef_config[:knife][:hints].nil? || @chef_config[:knife][:hints].empty? -%>
|
218
|
-
mkdir -p
|
218
|
+
mkdir -p /etc/chef/ohai/hints
|
219
219
|
|
220
220
|
<% @chef_config[:knife][:hints].each do |name, hash| -%>
|
221
|
-
cat >
|
221
|
+
cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP'
|
222
222
|
<%= Chef::JSONCompat.to_json(hash) %>
|
223
223
|
EOP
|
224
224
|
<% end -%>
|
225
225
|
<% end -%>
|
226
226
|
|
227
|
-
cat >
|
227
|
+
cat > /etc/chef/client.rb <<'EOP'
|
228
228
|
<%= config_content %>
|
229
229
|
EOP
|
230
230
|
|
231
|
-
cat >
|
231
|
+
cat > /etc/chef/first-boot.json <<'EOP'
|
232
232
|
<%= Chef::JSONCompat.to_json(first_boot) %>
|
233
233
|
EOP
|
234
234
|
|