`fatal: [localhost]: UNREACHABLE! Failed to connect to the host via ssh: Permission denied` when targeting localhost
BeginnerTroubleshootingConnection and SSH Failures
Answer
Likely causes → A host named localhost in your own inventory overrides the implicit local connection and Ansible tries SSH.
Diagnose → ansible-inventory --host localhost and look for ansible_connection.
Fix →
localhost ansible_connection=local
or use connection: local in the play.
Prevent → Always set connection: local for control-node plays.
More on Connection and SSH Failures
`UNREACHABLE! => {"msg": "Failed to connect to the host via ssh: Permission denied (publickey,password)."}`Beginner`UNREACHABLE! => {"msg": "Failed to connect to the host via ssh: ssh: connect to host 10.0.1.15 port 22: Connection timed out"}`Beginner`UNREACHABLE! => {"msg": "Failed to connect to the host via ssh: ssh: connect to host web01 port 22: Connection refused"}`Beginner`Host key verification failed.` after rebuilding a serverBeginnerThe playbook hangs for ever at "Gathering Facts" on one hostIntermediate`Failed to connect to the host via ssh: Too many authentication failures`Intermediate