From f87c25bac830a2dc1c96b2d71de138357b04ec11 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 19 Jan 2012 20:47:01 -0800 Subject: [PATCH] Provide defaults in a proper way for Chef config --- lib/vagrant/provisioners/chef.rb | 10 +++++----- lib/vagrant/provisioners/chef_client.rb | 16 +++++++--------- lib/vagrant/provisioners/chef_solo.rb | 11 +++++++---- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/lib/vagrant/provisioners/chef.rb b/lib/vagrant/provisioners/chef.rb index 2df2d4f09..6824a4faa 100644 --- a/lib/vagrant/provisioners/chef.rb +++ b/lib/vagrant/provisioners/chef.rb @@ -115,11 +115,11 @@ module Vagrant attr_accessor :attempts attr_writer :run_list - def initialize - @attempts = 1 - @json = {} - @log_level = :info - end + # 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 # This returns the json that is merged with the defaults and the # user set data. diff --git a/lib/vagrant/provisioners/chef_client.rb b/lib/vagrant/provisioners/chef_client.rb index 5b8792752..85d49a208 100644 --- a/lib/vagrant/provisioners/chef_client.rb +++ b/lib/vagrant/provisioners/chef_client.rb @@ -18,15 +18,13 @@ module Vagrant attr_accessor :encrypted_data_bag_secret_key_path attr_accessor :encrypted_data_bag_secret - def initialize - super - - @validation_client_name = "chef-validator" - @client_key_path = "/etc/chef/client.pem" - @file_cache_path = "/srv/chef/file_store" - @file_backup_path = "/srv/chef/cache" - @encrypted_data_bag_secret = "/tmp/encrypted_data_bag_secret" - end + # 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 validate(env, errors) super diff --git a/lib/vagrant/provisioners/chef_solo.rb b/lib/vagrant/provisioners/chef_solo.rb index e1b5389f6..ec8be6edf 100644 --- a/lib/vagrant/provisioners/chef_solo.rb +++ b/lib/vagrant/provisioners/chef_solo.rb @@ -16,11 +16,14 @@ module Vagrant attr_accessor :recipe_url attr_accessor :nfs - def initialize - super + # Provide defaults in such a way that they won't override the instance + # variable. This is so merging continues to work properly. + def cookbooks_path + @cookbooks_path || ["cookbooks", [:vm, "cookbooks"]] + end - @cookbooks_path = ["cookbooks", [:vm, "cookbooks"]] - @nfs = false + def nfs + @nfs || false end def validate(env, errors)