An Ansible playbook fails with "UNREACHABLE! ... Permission denied (publickey)". Fix it.

BeginnerHands-onLive debugging tasks
Answer
ansible web1 -i inventory.yml -m ping -vvvv        # shows the exact ssh command used
ssh -i ~/.ssh/prod.pem [email protected]            # reproduce manually
chmod 600 ~/.ssh/prod.pem

Check ansible_user (ubuntu vs ec2-user vs admin), ansible_ssh_private_key_file, and that the key is in the target user's authorized_keys.

Key trick → -vvvv prints the full SSH command Ansible runs, which you can paste into a terminal to reproduce. Wrong username is the cause most of the time.

All Real-World Interview questions Roadmap: Interview readiness

More on Live debugging tasks