Merge pull request #9173 from hashicorp/gildegoma/fix-ansible-ask-sudo-pass-deprecation
Ansible Provisioner: Fix broken 'ask_sudo_pass' option
This commit is contained in:
commit
43bcf2aaf7
|
@ -16,7 +16,7 @@ module VagrantPlugins
|
||||||
#
|
#
|
||||||
alias :ask_sudo_pass :ask_become_pass
|
alias :ask_sudo_pass :ask_become_pass
|
||||||
def ask_sudo_pass=(value)
|
def ask_sudo_pass=(value)
|
||||||
show_deprecation_warning 'ask_sudo_pass', 'ask_become_pass'
|
show_deprecation_info 'ask_sudo_pass', 'ask_become_pass'
|
||||||
@ask_become_pass = value
|
@ask_become_pass = value
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -78,6 +78,7 @@ describe VagrantPlugins::Ansible::Config::Host, :skip_windows => true do
|
||||||
allow($stdout).to receive(:puts)
|
allow($stdout).to receive(:puts)
|
||||||
end
|
end
|
||||||
it_behaves_like "any VagrantConfigProvisioner strict boolean attribute", :ask_sudo_pass, false
|
it_behaves_like "any VagrantConfigProvisioner strict boolean attribute", :ask_sudo_pass, false
|
||||||
|
it_behaves_like "any deprecated option", :ask_sudo_pass, :ask_become_pass, true
|
||||||
end
|
end
|
||||||
describe "ask_vault_pass option" do
|
describe "ask_vault_pass option" do
|
||||||
it_behaves_like "any VagrantConfigProvisioner strict boolean attribute", :ask_vault_pass, false
|
it_behaves_like "any VagrantConfigProvisioner strict boolean attribute", :ask_vault_pass, false
|
||||||
|
|
|
@ -30,6 +30,17 @@ shared_examples_for 'options shared by both Ansible provisioners' do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
shared_examples_for 'any deprecated option' do |deprecated_option, new_option, option_value|
|
||||||
|
it "shows the deprecation message" do
|
||||||
|
expect($stdout).to receive(:puts).with("DEPRECATION: The '#{deprecated_option}' option for the Ansible provisioner is deprecated.").and_return(nil)
|
||||||
|
expect($stdout).to receive(:puts).with("Please use the '#{new_option}' option instead.").and_return(nil)
|
||||||
|
expect($stdout).to receive(:puts).with("The '#{deprecated_option}' option will be removed in a future release of Vagrant.\n\n").and_return(nil)
|
||||||
|
|
||||||
|
subject.send("#{deprecated_option}=", option_value)
|
||||||
|
subject.finalize!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
shared_examples_for 'an Ansible provisioner' do | path_prefix, ansible_setup |
|
shared_examples_for 'an Ansible provisioner' do | path_prefix, ansible_setup |
|
||||||
|
|
||||||
provisioner_label = "ansible #{ansible_setup} provisioner"
|
provisioner_label = "ansible #{ansible_setup} provisioner"
|
||||||
|
@ -158,6 +169,15 @@ shared_examples_for 'an Ansible provisioner' do | path_prefix, ansible_setup |
|
||||||
allow($stdout).to receive(:puts)
|
allow($stdout).to receive(:puts)
|
||||||
end
|
end
|
||||||
it_behaves_like "any VagrantConfigProvisioner strict boolean attribute", :sudo, false
|
it_behaves_like "any VagrantConfigProvisioner strict boolean attribute", :sudo, false
|
||||||
|
it_behaves_like "any deprecated option", :sudo, :become, true
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "sudo_user option" do
|
||||||
|
before do
|
||||||
|
# Filter the deprecation notice
|
||||||
|
allow($stdout).to receive(:puts)
|
||||||
|
end
|
||||||
|
it_behaves_like "any deprecated option", :sudo_user, :become_user, "foo"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -202,6 +202,14 @@ VF
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ensure_that_config_is_valid
|
||||||
|
# Abort the test when an invalid configuration is detected
|
||||||
|
config.validate(machine)
|
||||||
|
if config._detected_errors.length > 0
|
||||||
|
raise "Invalid Provisioner Configuration! Detected Errors:\n#{config._detected_errors.to_s}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#provision" do
|
describe "#provision" do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
@ -216,6 +224,8 @@ VF
|
||||||
|
|
||||||
after do
|
after do
|
||||||
unless RSpec.current_example.metadata[:skip_after]
|
unless RSpec.current_example.metadata[:skip_after]
|
||||||
|
ensure_that_config_is_valid
|
||||||
|
|
||||||
subject.provision
|
subject.provision
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -233,6 +243,7 @@ VF
|
||||||
|
|
||||||
config.playbook = STUBBED_INVALID_PATH
|
config.playbook = STUBBED_INVALID_PATH
|
||||||
config.finalize!
|
config.finalize!
|
||||||
|
ensure_that_config_is_valid
|
||||||
|
|
||||||
expect {subject.provision}.to raise_error(VagrantPlugins::Ansible::Errors::AnsibleError,
|
expect {subject.provision}.to raise_error(VagrantPlugins::Ansible::Errors::AnsibleError,
|
||||||
"`playbook` does not exist on the host: #{STUBBED_INVALID_PATH}")
|
"`playbook` does not exist on the host: #{STUBBED_INVALID_PATH}")
|
||||||
|
@ -245,11 +256,8 @@ VF
|
||||||
|
|
||||||
config.playbook = existing_file
|
config.playbook = existing_file
|
||||||
config.send(option_name + '=', STUBBED_INVALID_PATH)
|
config.send(option_name + '=', STUBBED_INVALID_PATH)
|
||||||
if option_name == 'extra_vars'
|
|
||||||
# little trick to auto-append the '@' prefix, which is a duty of the config validator...
|
|
||||||
config.validate(machine)
|
|
||||||
end
|
|
||||||
config.finalize!
|
config.finalize!
|
||||||
|
ensure_that_config_is_valid
|
||||||
|
|
||||||
expect {subject.provision}.to raise_error(VagrantPlugins::Ansible::Errors::AnsibleError,
|
expect {subject.provision}.to raise_error(VagrantPlugins::Ansible::Errors::AnsibleError,
|
||||||
"`#{option_name}` does not exist on the host: #{STUBBED_INVALID_PATH}")
|
"`#{option_name}` does not exist on the host: #{STUBBED_INVALID_PATH}")
|
||||||
|
@ -261,6 +269,7 @@ VF
|
||||||
describe 'when ansible-playbook fails' do
|
describe 'when ansible-playbook fails' do
|
||||||
it "raises an error", skip_before: true, skip_after: true do
|
it "raises an error", skip_before: true, skip_after: true do
|
||||||
config.finalize!
|
config.finalize!
|
||||||
|
ensure_that_config_is_valid
|
||||||
|
|
||||||
allow(subject).to receive(:check_path)
|
allow(subject).to receive(:check_path)
|
||||||
allow(Vagrant::Util::Subprocess).to receive(:execute)
|
allow(Vagrant::Util::Subprocess).to receive(:execute)
|
||||||
|
@ -398,6 +407,7 @@ VF
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises a compatibility conflict error", skip_before: false, skip_after: true do
|
it "raises a compatibility conflict error", skip_before: false, skip_after: true do
|
||||||
|
ensure_that_config_is_valid
|
||||||
expect {subject.provision}.to raise_error(VagrantPlugins::Ansible::Errors::AnsibleCompatibilityModeConflict)
|
expect {subject.provision}.to raise_error(VagrantPlugins::Ansible::Errors::AnsibleCompatibilityModeConflict)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -986,6 +996,7 @@ VF
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises an error about the ansible version mismatch", skip_before: false, skip_after: true do
|
it "raises an error about the ansible version mismatch", skip_before: false, skip_after: true do
|
||||||
|
ensure_that_config_is_valid
|
||||||
expect {subject.provision}.to raise_error(VagrantPlugins::Ansible::Errors::AnsibleVersionMismatch)
|
expect {subject.provision}.to raise_error(VagrantPlugins::Ansible::Errors::AnsibleVersionMismatch)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1020,6 +1031,7 @@ VF
|
||||||
|
|
||||||
it "raises an error when ansible-galaxy command fails", skip_before: true, skip_after: true do
|
it "raises an error when ansible-galaxy command fails", skip_before: true, skip_after: true do
|
||||||
config.finalize!
|
config.finalize!
|
||||||
|
ensure_that_config_is_valid
|
||||||
|
|
||||||
allow(subject).to receive(:check_path)
|
allow(subject).to receive(:check_path)
|
||||||
allow(Vagrant::Util::Subprocess).to receive(:execute)
|
allow(Vagrant::Util::Subprocess).to receive(:execute)
|
||||||
|
|
Loading…
Reference in New Issue