diff --git a/plugins/kernel_v2/config/vm.rb b/plugins/kernel_v2/config/vm.rb index 8379f09d8..a0dc0c8b2 100644 --- a/plugins/kernel_v2/config/vm.rb +++ b/plugins/kernel_v2/config/vm.rb @@ -767,7 +767,8 @@ module VagrantPlugins next end - provisioner_errors = vm_provisioner.validate(machine) + provisioner_names = @provisioners.map { |i| i.name if i.name != vm_provisioner.name }.reject(&:blank?) + provisioner_errors = vm_provisioner.validate(machine, provisioner_names) if provisioner_errors errors = Vagrant::Config::V2::Util.merge_errors(errors, provisioner_errors) end diff --git a/plugins/kernel_v2/config/vm_provisioner.rb b/plugins/kernel_v2/config/vm_provisioner.rb index 545da783d..1dcdeedc1 100644 --- a/plugins/kernel_v2/config/vm_provisioner.rb +++ b/plugins/kernel_v2/config/vm_provisioner.rb @@ -105,23 +105,43 @@ module VagrantPlugins @config.finalize! end + # @param [Vagrant::Machine] machine - machine to validate against + # @param [Array] provisioner_names - Names of provisioners for a given machine # @return [Array] array of strings of error messages from config option validation - def validate(machine) + def validate(machine, provisioner_names) errors = _detected_errors if @before - if @before.is_a?(Symbol) && !VALID_BEFORE_AFTER_TYPES.include?(@before) - errors << I18n.t("vagrant.provisioners.base.invalid_alias_value", opt: "before", alias: VALID_BEFORE_AFTER_TYPES.join(", ")) - elsif !@before.is_a?(String) && !VALID_BEFORE_AFTER_TYPES.include?(@before) - errors << I18n.t("vagrant.provisioners.base.wrong_type", opt: "before") + if !VALID_BEFORE_AFTER_TYPES.include?(@before) + if @before.is_a?(Symbol) && !VALID_BEFORE_AFTER_TYPES.include?(@before) + errors << I18n.t("vagrant.provisioners.base.invalid_alias_value", opt: "before", alias: VALID_BEFORE_AFTER_TYPES.join(", ")) + elsif !@before.is_a?(String) && !VALID_BEFORE_AFTER_TYPES.include?(@before) + errors << I18n.t("vagrant.provisioners.base.wrong_type", opt: "before") + end + + if !provisioner_names.include?(@before.to_sym) + errors << I18n.t("vagrant.provisioners.base.missing_provisioner_name", + name: @before, + machine_name: machine.name, + action: "before") + end end end if @after - if @after.is_a?(Symbol) && !VALID_BEFORE_AFTER_TYPES.include?(@after) - errors << I18n.t("vagrant.provisioners.base.invalid_alias_value", opt: "after", alias: VALID_BEFORE_AFTER_TYPES.join(", ")) - elsif !@after.is_a?(String) && !VALID_BEFORE_AFTER_TYPES.include?(@after) - errors << I18n.t("vagrant.provisioners.base.wrong_type", opt: "after") + if !VALID_BEFORE_AFTER_TYPES.include?(@after) + if @after.is_a?(Symbol) + errors << I18n.t("vagrant.provisioners.base.invalid_alias_value", opt: "after", alias: VALID_BEFORE_AFTER_TYPES.join(", ")) + elsif !@after.is_a?(String) + errors << I18n.t("vagrant.provisioners.base.wrong_type", opt: "after") + end + + if !provisioner_names.include?(@after.to_sym) + errors << I18n.t("vagrant.provisioners.base.missing_provisioner_name", + name: @after, + machine_name: machine.name, + action: "after") + end end end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 766f36984..3590cdb9b 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -2489,6 +2489,8 @@ en: base: invalid_alias_value: |- Provisioner option `%{opt}` is not set as a valid type. Must be a string, or one of the alias shortcuts: %{alias} + missing_provisioner_name: |- + Could not find provisioner name `%{name}` defined for machine `%{machine_name}` to run provisioner `%{action}`. wrong_type: |- Provisioner option `%{opt}` is not set as a valid type. Must be a string. chef: