diff --git a/CHANGELOG.md b/CHANGELOG.md index 212c3527e..f532dcaf9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ ## 1.2.4 (unreleased) +FEATURES: + + - Chef solo and client provisioning now support a `custom_config_path` + setting that accepts a path to a Ruby file to load as part of Chef + configuration, allowing you to override any setting available. [GH-876] + BUG FIXES: - core/nfs: Exporting sub-directories of other exported folders now diff --git a/plugins/provisioners/chef/config/base.rb b/plugins/provisioners/chef/config/base.rb index 9334b6dd5..463755692 100644 --- a/plugins/provisioners/chef/config/base.rb +++ b/plugins/provisioners/chef/config/base.rb @@ -6,6 +6,7 @@ module VagrantPlugins attr_accessor :attempts attr_accessor :binary_path attr_accessor :binary_env + attr_accessor :custom_config_path attr_accessor :http_proxy attr_accessor :http_proxy_user attr_accessor :http_proxy_pass @@ -26,6 +27,7 @@ module VagrantPlugins @attempts = UNSET_VALUE @binary_path = UNSET_VALUE @binary_env = UNSET_VALUE + @custom_config_path = UNSET_VALUE @http_proxy = UNSET_VALUE @http_proxy_user = UNSET_VALUE @http_proxy_pass = UNSET_VALUE @@ -46,6 +48,7 @@ module VagrantPlugins @attempts = 1 if @attempts == UNSET_VALUE @binary_path = nil if @binary_path == UNSET_VALUE @binary_env = nil if @binary_env == UNSET_VALUE + @custom_config_path = nil if @custom_config_path == 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 @@ -68,6 +71,22 @@ module VagrantPlugins end end + # Just like the normal configuration "validate" method except that + # it returns an array of errors that should be merged into some + # other error accumulator. + def validate_base(machine) + errors = [] + + if @custom_config_path + expanded = File.expand_path(@custom_config_path, machine.env.root_path) + if !File.file?(expanded) + errors << I18n.t("vagrant.config.chef.custom_config_path_missing") + end + end + + errors + end + # Adds a recipe to the run list def add_recipe(name) name = "recipe[#{name}]" unless name =~ /^recipe\[(.+?)\]$/ diff --git a/plugins/provisioners/chef/config/chef_client.rb b/plugins/provisioners/chef/config/chef_client.rb index ad536067d..899927213 100644 --- a/plugins/provisioners/chef/config/chef_client.rb +++ b/plugins/provisioners/chef/config/chef_client.rb @@ -44,6 +44,7 @@ module VagrantPlugins def validate(machine) errors = _detected_errors + errors.concat(validate_base(machine)) errors << I18n.t("vagrant.config.chef.server_url_empty") if \ !chef_server_url || chef_server_url.strip == "" errors << I18n.t("vagrant.config.chef.validation_key_path") if \ diff --git a/plugins/provisioners/chef/config/chef_solo.rb b/plugins/provisioners/chef/config/chef_solo.rb index 2268dccb5..f3054627d 100644 --- a/plugins/provisioners/chef/config/chef_solo.rb +++ b/plugins/provisioners/chef/config/chef_solo.rb @@ -59,6 +59,7 @@ module VagrantPlugins def validate(machine) errors = _detected_errors + errors.concat(validate_base(machine)) errors << I18n.t("vagrant.config.chef.cookbooks_path_empty") if \ !cookbooks_path || [cookbooks_path].flatten.empty? diff --git a/plugins/provisioners/chef/provisioner/base.rb b/plugins/provisioners/chef/provisioner/base.rb index f201234c2..180ce6e1b 100644 --- a/plugins/provisioners/chef/provisioner/base.rb +++ b/plugins/provisioners/chef/provisioner/base.rb @@ -47,14 +47,26 @@ module VagrantPlugins end def setup_config(template, filename, template_vars) + # If we have custom configuration, upload it + remote_custom_config_path = nil + if @config.custom_config_path + expanded = File.expand_path( + @config.custom_config_path, @machine.env.root_path) + remote_custom_config_path = File.join( + config.provisioning_path, "custom-config.rb") + + @machine.communicate.upload(expanded, remote_custom_config_path) + end + config_file = Vagrant::Util::TemplateRenderer.render(template, { - :log_level => @config.log_level.to_sym, + :custom_configuration => remote_custom_config_path, :http_proxy => @config.http_proxy, :http_proxy_user => @config.http_proxy_user, :http_proxy_pass => @config.http_proxy_pass, :https_proxy => @config.https_proxy, :https_proxy_user => @config.https_proxy_user, :https_proxy_pass => @config.https_proxy_pass, + :log_level => @config.log_level.to_sym, :no_proxy => @config.no_proxy }.merge(template_vars)) diff --git a/templates/locales/en.yml b/templates/locales/en.yml index d7d1fb39b..b0c252e7b 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -588,6 +588,8 @@ en: cookbooks_path_empty: "Must specify a cookbooks path for chef solo." cookbooks_path_missing: |- Cookbook path doesn't exist: %{path} + custom_config_path_missing: |- + Path specified for "custom_config_path" does not exist. server_url_empty: "Chef server URL must be populated." validation_key_path: "Validation key path must be valid path to your chef server validation key." loader: diff --git a/templates/provisioners/chef_client/client.erb b/templates/provisioners/chef_client/client.erb index 44c24fe26..23c3f68de 100644 --- a/templates/provisioners/chef_client/client.erb +++ b/templates/provisioners/chef_client/client.erb @@ -30,3 +30,7 @@ no_proxy <%= no_proxy.inspect %> pid_file "/var/run/chef/chef-client.pid" Mixlib::Log::Formatter.show_time = true + +<% if custom_configuration -%> +load "<%= custom_configuration %>" +<% end -%> diff --git a/templates/provisioners/chef_solo/solo.erb b/templates/provisioners/chef_solo/solo.erb index 10a108437..c969ba77e 100644 --- a/templates/provisioners/chef_solo/solo.erb +++ b/templates/provisioners/chef_solo/solo.erb @@ -25,3 +25,7 @@ https_proxy <%= https_proxy.inspect %> https_proxy_user <%= https_proxy_user.inspect %> https_proxy_pass <%= https_proxy_pass.inspect %> no_proxy <%= no_proxy.inspect %> + +<% if custom_configuration -%> +load "<%= custom_configuration %>" +<% end -%>