Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save long25vn/9f6331e1da33fa9e30861514f06987f9 to your computer and use it in GitHub Desktop.
Save long25vn/9f6331e1da33fa9e30861514f06987f9 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

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