diff --git a/plugins/provisioners/ansible/config.rb b/plugins/provisioners/ansible/config.rb index 649f1d66b..b29433f6e 100644 --- a/plugins/provisioners/ansible/config.rb +++ b/plugins/provisioners/ansible/config.rb @@ -47,7 +47,7 @@ module VagrantPlugins @extra_vars = nil if @extra_vars == UNSET_VALUE @inventory_path = nil if @inventory_path == UNSET_VALUE @ask_sudo_pass = false unless @ask_sudo_pass == true - @ask_vault_pass = false unless @ask_sudo_pass == true + @ask_vault_pass = false unless @ask_vault_pass == true @vault_password_file = nil if @vault_password_file == UNSET_VALUE @limit = nil if @limit == UNSET_VALUE @sudo = false unless @sudo == true @@ -112,6 +112,15 @@ module VagrantPlugins end end + # Validate the existence of the vault_password_file, if specified + if vault_password_file + expanded_path = Pathname.new(vault_password_file).expand_path(machine.env.root_path) + if !expanded_path.exist? + errors << I18n.t("vagrant.provisioners.ansible.vault_password_file_invalid", + :path => expanded_path) + end + end + { "ansible provisioner" => errors } end end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index b2628a38b..5b668300a 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -1700,6 +1700,7 @@ en: no_playbook: "`playbook` must be set for the Ansible provisioner." playbook_path_invalid: "`playbook` for the Ansible provisioner does not exist on the host system: %{path}" inventory_path_invalid: "`inventory_path` for the Ansible provisioner does not exist on the host system: %{path}" + vault_password_file_invalid: "`vault_password_file` for the Ansible provisioner does not exist on the host system: %{path}" extra_vars_invalid: "`extra_vars` for the Ansible provisioner must be a hash or a path to an existing file. Received: %{value} (as %{type})" docker: diff --git a/test/unit/plugins/provisioners/ansible/config_test.rb b/test/unit/plugins/provisioners/ansible/config_test.rb index 6e0ec3301..d3cdc8208 100644 --- a/test/unit/plugins/provisioners/ansible/config_test.rb +++ b/test/unit/plugins/provisioners/ansible/config_test.rb @@ -16,6 +16,7 @@ describe VagrantPlugins::Ansible::Config do config_options = subject.public_methods(false).find_all { |i| i.to_s.end_with?('=') } config_options.map! { |i| i.to_s.sub('=', '') } supported_options = %w( ask_sudo_pass + ask_vault_pass extra_vars groups host_key_checking @@ -29,6 +30,7 @@ describe VagrantPlugins::Ansible::Config do sudo sudo_user tags + vault_password_file verbose ) expect(config_options.sort).to eql(supported_options) @@ -40,6 +42,8 @@ describe VagrantPlugins::Ansible::Config do expect(subject.playbook).to be_nil expect(subject.extra_vars).to be_nil expect(subject.ask_sudo_pass).to be_false + expect(subject.ask_vault_pass).to be_false + expect(subject.vault_password_file).to be_nil expect(subject.limit).to be_nil expect(subject.sudo).to be_false expect(subject.sudo_user).to be_nil @@ -59,6 +63,9 @@ describe VagrantPlugins::Ansible::Config do describe "ask_sudo_pass option" do it_behaves_like "any VagrantConfigProvisioner strict boolean attribute", :ask_sudo_pass, false end + describe "ask_vault_pass option" do + it_behaves_like "any VagrantConfigProvisioner strict boolean attribute", :ask_sudo_pass, false + end describe "sudo option" do it_behaves_like "any VagrantConfigProvisioner strict boolean attribute", :sudo, false end @@ -155,6 +162,17 @@ describe VagrantPlugins::Ansible::Config do ]) end + it "returns an error if vault_password_file is specified, but does not exist" do + subject.vault_password_file = non_existing_file + subject.finalize! + + result = subject.validate(machine) + expect(result["ansible provisioner"]).to eql([ + I18n.t("vagrant.provisioners.ansible.vault_password_file_invalid", + :path => non_existing_file) + ]) + end + it "it collects and returns all detected errors" do subject.playbook = non_existing_file subject.inventory_path = non_existing_file