Skip to content

Instantly share code, notes, and snippets.

@bmurithi
Last active January 10, 2024 14:26
Show Gist options
  • Save bmurithi/46b93b0b6dc83eb6d3497190fd3b6804 to your computer and use it in GitHub Desktop.
Save bmurithi/46b93b0b6dc83eb6d3497190fd3b6804 to your computer and use it in GitHub Desktop.
Ansible SSH too many authentication failures

This exception appears to affect ansible when a playbook is executed from a host with several identities configured in the SSH agent (Tested on a development machine with 12 private keys).

I've noted this exception to be particulary common with AWS targets

Inventory configuration

Most tasks will run fine when we configure our inventory to use a specific private key.

We also need to set the IdentitiesOnly flag so that ssh does not attempt other authentication strategies.

# inventory
example.com ansible_ssh_private_key_file=/a/b/key.pem ansible_ssh_extra_args="-o IdentitiesOnly=yes"

Fixing synchronize module tasks

synchronize tasks will require an additional flag:

use_ssh_args needs to be set to include ssh arguments from the inventory when running rsync

    - name: copy code
      synchronize:
        src: "<source>"
        dest: "<destination>"
        use_ssh_args: yes
      tags:
        - code

See synchronize module options

@anandshivam44
Copy link

Thanks it was helpful

@khalangy
Copy link

Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment