diff --git a/plugins/provisioners/cfengine/config.rb b/plugins/provisioners/cfengine/config.rb index fb6364494..7d00b1c8c 100644 --- a/plugins/provisioners/cfengine/config.rb +++ b/plugins/provisioners/cfengine/config.rb @@ -3,6 +3,7 @@ require "vagrant" module VagrantPlugins module CFEngine class Config < Vagrant.plugin("2", :config) + attr_accessor :classes attr_accessor :deb_repo_file attr_accessor :deb_repo_line attr_accessor :force_bootstrap @@ -16,6 +17,7 @@ module VagrantPlugins attr_accessor :yum_repo_url def initialize + @classes = UNSET_VALUE @deb_repo_file = UNSET_VALUE @deb_repo_line = UNSET_VALUE @force_bootstrap = UNSET_VALUE @@ -30,6 +32,8 @@ module VagrantPlugins end def finalize! + @classes = nil if @classes == UNSET_VALUE + if @deb_repo_file == UNSET_VALUE @deb_repo_file = "/etc/apt/sources.list.d/cfengine-community.list" end @@ -75,6 +79,10 @@ module VagrantPlugins errors << I18n.t("vagrant.cfengine_config.policy_server_address") if !@policy_server_address end + if @classes && !@classes.is_a?(Array) + errors << I18n.t("vagrant.cfengine_config.classes_array") + end + { "CFEngine" => errors } end end diff --git a/plugins/provisioners/cfengine/provisioner.rb b/plugins/provisioners/cfengine/provisioner.rb index 74f2b8f6e..95ea19a3a 100644 --- a/plugins/provisioners/cfengine/provisioner.rb +++ b/plugins/provisioners/cfengine/provisioner.rb @@ -21,7 +21,7 @@ module VagrantPlugins @machine.ui.info(I18n.t("vagrant.cfengine_single_run_execute")) path = Pathname.new(@config.run_file).expand_path(@machine.env.root_path) machine.communicate.upload(path.to_s, @config.upload_path) - cfagent("-KI -f #{@config.upload_path}") + cfagent("-KI -f #{@config.upload_path}#{cfagent_classes_args}") end end @@ -44,6 +44,15 @@ module VagrantPlugins end end + # Returns the arguments for the classes configuration if they are + # set. + def cfagent_classes_args + return "" if !@config.classes + + args = @config.classes.map { |c| "-D#{c}" }.join(" ") + return " #{args}" + end + # This handles checking if the CFEngine installation needs to # be bootstrapped, and bootstraps if it does. def handle_cfengine_bootstrap diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 533cc36b2..bb03cb9dd 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -16,6 +16,8 @@ en: Executing run file for CFEngine... cfengine_config: + classes_array: |- + The 'classes' configuration must be an array. invalid_mode: |- The mode must be 'bootstrap' or 'single_run' policy_server_address: |-