From 9287324472c7bc222aaf33f36da1afbd2325ae4f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 6 Jul 2011 00:44:21 -0700 Subject: [PATCH] Chef JSON can be set directly with `json =` instead of the old `merge!` trick. [closes GH-314] --- CHANGELOG.md | 2 ++ lib/vagrant/provisioners/chef.rb | 20 ++++++++++---------- lib/vagrant/provisioners/chef_client.rb | 2 +- lib/vagrant/provisioners/chef_solo.rb | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index faf433cff..9ff8b9b71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ behavior. [GH-323] - Forward agent and forward X11 settings properly appear in `ssh_config` output. [GH-105] + - Chef JSON can now be set with `chef.json =` instead of the old + `merge` technique. [GH-314] ## 0.7.6 (July 2, 2011) diff --git a/lib/vagrant/provisioners/chef.rb b/lib/vagrant/provisioners/chef.rb index 246c83891..bf61d5685 100644 --- a/lib/vagrant/provisioners/chef.rb +++ b/lib/vagrant/provisioners/chef.rb @@ -59,7 +59,7 @@ module Vagrant # Merge with the "extra data" which isn't put under the # vagrant namespace by default - data.merge!(config.json) + data.merge!(config.merged_json) json = data.to_json @@ -90,11 +90,12 @@ module Vagrant attr_accessor :no_proxy attr_accessor :binary_path attr_accessor :binary_env + attr_accessor :run_list def initialize @provisioning_path = "/tmp/vagrant-chef" @log_level = :info - @json = { :instance_role => "vagrant" } + @json = {} @http_proxy = nil @http_proxy_user = nil @http_proxy_pass = nil @@ -104,16 +105,15 @@ module Vagrant @no_proxy = nil @binary_path = nil @binary_env = nil + @run_list = [] end - # Returns the run list for the provisioning - def run_list - json[:run_list] ||= [] - end - - # Sets the run list to the specified value - def run_list=(value) - json[:run_list] = value + # This returns the json that is merged with the defaults and the + # user set data. + def merged_json + { :instance_role => "vagrant", + :run_list => run_list + }.merge(json || {}) end # Adds a recipe to the run list diff --git a/lib/vagrant/provisioners/chef_client.rb b/lib/vagrant/provisioners/chef_client.rb index deb2cccf2..84f968543 100644 --- a/lib/vagrant/provisioners/chef_client.rb +++ b/lib/vagrant/provisioners/chef_client.rb @@ -34,7 +34,7 @@ module Vagrant errors.add(I18n.t("vagrant.config.chef.server_url_empty")) if !chef_server_url || chef_server_url.strip == "" errors.add(I18n.t("vagrant.config.chef.validation_key_path")) if !validation_key_path - errors.add(I18n.t("vagrant.config.chef.run_list_empty")) if json[:run_list] && run_list.empty? + errors.add(I18n.t("vagrant.config.chef.run_list_empty")) if run_list && run_list.empty? end end diff --git a/lib/vagrant/provisioners/chef_solo.rb b/lib/vagrant/provisioners/chef_solo.rb index 60f383ae7..74a3be9aa 100644 --- a/lib/vagrant/provisioners/chef_solo.rb +++ b/lib/vagrant/provisioners/chef_solo.rb @@ -24,7 +24,7 @@ module Vagrant super errors.add(I18n.t("vagrant.config.chef.cookbooks_path_empty")) if !cookbooks_path || [cookbooks_path].flatten.empty? - errors.add(I18n.t("vagrant.config.chef.run_list_empty")) if !json[:run_list] || run_list.empty? + errors.add(I18n.t("vagrant.config.chef.run_list_empty")) if !run_list || run_list.empty? end end