diff --git a/plugins/provisioners/chef/config/base.rb b/plugins/provisioners/chef/config/base.rb index f097d03b2..494da6164 100644 --- a/plugins/provisioners/chef/config/base.rb +++ b/plugins/provisioners/chef/config/base.rb @@ -2,42 +2,62 @@ module VagrantPlugins module Chef module Config class Base < Vagrant.plugin("2", :config) - # Shared config - attr_accessor :node_name - attr_accessor :provisioning_path - attr_accessor :log_level - attr_accessor :json + attr_accessor :arguments + attr_accessor :attempts + attr_accessor :binary_path + attr_accessor :binary_env attr_accessor :http_proxy attr_accessor :http_proxy_user attr_accessor :http_proxy_pass attr_accessor :https_proxy attr_accessor :https_proxy_user attr_accessor :https_proxy_pass + attr_accessor :json + attr_accessor :log_level attr_accessor :no_proxy - attr_accessor :binary_path - attr_accessor :binary_env - attr_accessor :attempts - attr_accessor :arguments - attr_writer :run_list + attr_accessor :node_name + attr_accessor :provisioning_path + attr_accessor :run_list - # Provide defaults in such a way that they won't override the instance - # variable. This is so merging continues to work properly. - def attempts; @attempts || 1; end - def json; @json ||= {}; end - def log_level; @log_level || :info; end + def initialize + super - # This returns the json that is merged with the defaults and the - # user set data. - def merged_json - original = { :instance_role => "vagrant" } - original[:run_list] = @run_list if @run_list - original.merge(json || {}) + @arguments = UNSET_VALUE + @attempts = UNSET_VALUE + @binary_path = UNSET_VALUE + @binary_env = UNSET_VALUE + @http_proxy = UNSET_VALUE + @http_proxy_user = UNSET_VALUE + @http_proxy_pass = UNSET_VALUE + @https_proxy = UNSET_VALUE + @https_proxy_user = UNSET_VALUE + @https_proxy_pass = UNSET_VALUE + @log_level = UNSET_VALUE + @no_proxy = UNSET_VALUE + @node_name = UNSET_VALUE + @provisioning_path = UNSET_VALUE + + @json = {} + @run_list = [] end - # Returns the run list, but also sets it up to be empty if it - # hasn't been defined already. - def run_list - @run_list ||= [] + def finalize! + @arguments = nil if @arguments == UNSET_VALUE + @attempts = 1 if @attempts == UNSET_VALUE + @binary_path = nil if @binary_path == UNSET_VALUE + @binary_env = nil if @binary_env == UNSET_VALUE + @http_proxy = nil if @http_proxy == UNSET_VALUE + @http_proxy_user = nil if @http_proxy_user == UNSET_VALUE + @http_proxy_pass = nil if @http_proxy_pass == UNSET_VALUE + @https_proxy = nil if @https_proxy == UNSET_VALUE + @https_proxy_user = nil if @https_proxy_user == UNSET_VALUE + @https_proxy_pass = nil if @https_proxy_pass == UNSET_VALUE + @log_level = :info if @log_level == UNSET_VALUE + @no_proxy = nil if @no_proxy == UNSET_VALUE + @provisioning_path = nil if @provisioning_path == UNSET_VALUIE + + # Make sure the log level is a symbol + @log_level = @log_level.to_sym end # Adds a recipe to the run list @@ -51,14 +71,6 @@ module VagrantPlugins name = "role[#{name}]" unless name =~ /^role\[(.+?)\]$/ run_list << name end - - def instance_variables_hash - # Overridden so that the 'json' key could be removed, since its just - # merged into the config anyways - result = super - result.delete("json") - result - end end end end diff --git a/plugins/provisioners/chef/config/chef_client.rb b/plugins/provisioners/chef/config/chef_client.rb index 360fd4c7a..d94589180 100644 --- a/plugins/provisioners/chef/config/chef_client.rb +++ b/plugins/provisioners/chef/config/chef_client.rb @@ -5,22 +5,41 @@ module VagrantPlugins module Config class ChefClient < Base attr_accessor :chef_server_url - attr_accessor :validation_key_path - attr_accessor :validation_client_name attr_accessor :client_key_path - attr_accessor :file_cache_path - attr_accessor :file_backup_path - attr_accessor :environment attr_accessor :encrypted_data_bag_secret_key_path attr_accessor :encrypted_data_bag_secret + attr_accessor :environment + attr_accessor :file_cache_path + attr_accessor :file_backup_path + attr_accessor :validation_key_path + attr_accessor :validation_client_name - # Provide defaults in such a way that they won't override the instance - # variable. This is so merging continues to work properly. - def validation_client_name; @validation_client_name || "chef-validator"; end - def client_key_path; @client_key_path || "/etc/chef/client.pem"; end - def file_cache_path; @file_cache_path || "/srv/chef/file_store"; end - def file_backup_path; @file_backup_path || "/srv/chef/cache"; end - def encrypted_data_bag_secret; @encrypted_data_bag_secret || "/tmp/encrypted_data_bag_secret"; end + def initialize + super + + @chef_server_url = UNSET_VALUE + @client_key_path = UNSET_VALUE + @encrypted_data_bag_secret_key_path = UNSET_VALUE + @encrypted_data_bag_secret = UNSET_VALUE + @environment = UNSET_VALUE + @file_cache_path = UNSET_VALUE + @file_backup_path = UNSET_VALUE + @validation_key_path = UNSET_VALUE + @validation_client_name = UNSET_VALUE + end + + def finalize! + super + + @client_key_path = "/etc/chef/client.pem" if @client_key_path == UNSET_VALUE + @file_backup_path = "/srv/chef/cache" if @file_backup_path == UNSET_VALUE + @file_cache_path = "/srv/chef/file_store" if @file_cache_path == UNSET_VALUE + @validation_client_name = "chef-validator" if @validation_client_name == UNSET_VALUE + + if @encrypted_data_bag_secret == UNSET_VALUE + @encrypted_data_bag_secret = "/tmp/encrypted_data_bag_secret" + end + end def validate(machine) errors = _detected_errors diff --git a/plugins/provisioners/chef/config/chef_solo.rb b/plugins/provisioners/chef/config/chef_solo.rb index d19cf07d9..3d832738d 100644 --- a/plugins/provisioners/chef/config/chef_solo.rb +++ b/plugins/provisioners/chef/config/chef_solo.rb @@ -31,6 +31,8 @@ module VagrantPlugins #------------------------------------------------------------ def finalize! + super + @recipe_url = nil if @recipe_url == UNSET_VALUE if @cookbooks_path == UNSET_VALUE diff --git a/plugins/provisioners/chef/provisioner/base.rb b/plugins/provisioners/chef/provisioner/base.rb index acc4417c1..f6589c18a 100644 --- a/plugins/provisioners/chef/provisioner/base.rb +++ b/plugins/provisioners/chef/provisioner/base.rb @@ -75,7 +75,7 @@ module VagrantPlugins @machine.env.ui.info I18n.t("vagrant.provisioners.chef.json") # Get the JSON that we're going to expose to Chef - json = JSON.pretty_generate(@config.merged_json) + json = JSON.pretty_generate(@config.json) # Create a temporary file to store the data so we # can upload it