fix `config.ssh.keys_only = false` for ansible

Also see #5017.
This commit is contained in:
Martin Nowak 2017-04-11 13:40:14 +02:00
parent aaa41d5af3
commit 1ca247f516
2 changed files with 18 additions and 5 deletions

View File

@ -249,11 +249,8 @@ module VagrantPlugins
# Don't access user's known_hosts file, except when host_key_checking is enabled.
ssh_options << "-o UserKnownHostsFile=/dev/null" unless config.host_key_checking
# Set IdentitiesOnly=yes to avoid authentication errors when the host has more than 5 ssh keys.
# Notes:
# - Solaris/OpenSolaris/Illumos uses SunSSH which doesn't support the IdentitiesOnly option.
# - this could be improved by sharing logic with lib/vagrant/util/ssh.rb
ssh_options << "-o IdentitiesOnly=yes" unless Vagrant::Util::Platform.solaris?
# Compare to lib/vagrant/util/ssh.rb
ssh_options << "-o IdentitiesOnly=yes" if !Vagrant::Util::Platform.solaris? && @ssh_info[:keys_only]
# Multiple Private Keys
unless !config.inventory_path && @ssh_info[:private_key_path].size == 1

View File

@ -40,6 +40,7 @@ VF
let(:config) { VagrantPlugins::Ansible::Config::Host.new }
let(:ssh_info) {{
private_key_path: ['/path/to/my/key'],
keys_only: true,
username: 'testuser',
host: '127.0.0.1',
port: 2223
@ -988,5 +989,20 @@ VF
end
end
describe 'with config.ssh.keys_only = false' do
it 'does not set IdentitiesOnly=yes in ANSIBLE_SSH_ARGS' do
ssh_info[:keys_only] = false
expect(Vagrant::Util::Subprocess).to receive(:execute).with { |*args|
cmd_opts = args.last
expect(cmd_opts[:env]['ANSIBLE_SSH_ARGS']).to_not include("-o IdentitiesOnly=yes")
# Ending this block with a negative expectation (to_not / not_to)
# would lead to a failure of the above expectation.
true
}
end
end
end
end