diff --git a/plugins/provisioners/ansible/provisioner/host.rb b/plugins/provisioners/ansible/provisioner/host.rb index e0fc70f0b..b86157208 100644 --- a/plugins/provisioners/ansible/provisioner/host.rb +++ b/plugins/provisioners/ansible/provisioner/host.rb @@ -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 diff --git a/test/unit/plugins/provisioners/ansible/provisioner_test.rb b/test/unit/plugins/provisioners/ansible/provisioner_test.rb index 2c8c27fb4..308307aab 100644 --- a/test/unit/plugins/provisioners/ansible/provisioner_test.rb +++ b/test/unit/plugins/provisioners/ansible/provisioner_test.rb @@ -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