Interview Prep/Ansible/Connection and SSH Failures

`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.

All Ansible questions Roadmap: Ansible

More on Connection and SSH Failures