Skip to content

Commit

Permalink
Chef JSON can be set directly with json = instead of the old `merge…
Browse files Browse the repository at this point in the history
…!` trick. [closes hashicorpGH-314]
  • Loading branch information
mitchellh committed Jul 6, 2011
1 parent c2bccdc commit 9287324
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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)

Expand Down
20 changes: 10 additions & 10 deletions lib/vagrant/provisioners/chef.rb
Expand Up @@ -59,7 +59,7 @@ def setup_json

# 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

Expand Down Expand Up @@ -90,11 +90,12 @@ class Config < Vagrant::Config::Base
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
Expand All @@ -104,16 +105,15 @@ def initialize
@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
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant/provisioners/chef_client.rb
Expand Up @@ -34,7 +34,7 @@ def validate(errors)

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

Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant/provisioners/chef_solo.rb
Expand Up @@ -24,7 +24,7 @@ def validate(errors)
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

Expand Down

0 comments on commit 9287324

Please sign in to comment.