Unable to connect to ec2-host (errors with permission denied errors) in AWS

Unable to connect to ec2-host (errors with permission denied errors) in AWS.

   1. Have the following entry in inventory file
   2. Following command was executed ansible -vvv test_ansible --user
   ansible --private-key=/home/ansible/.ssh/id_rsa -m ping
   --become-user=ansible

It is trying to connect as ec2-user@ec2_remotehost |FAILED> SSH Error:
Permission denied (publickey).
while connecting to ec2_remotehost:22

If this is already fixed, let me know the bug number and I can close this
as duplicate.

This does not seem as much as a bug as a lack of permissions or some
configuration discrepancy.

Do you have ansible_ssh_user/ssh_host set for the host?
from the command line switches, you would expect ansible@test_ansible
, but you report the error as ec2-user@ec2_remotehost

test_ansible is a group. In that ec2_remotehost is the server defined in the inventory file as follows

[test]

ec2_remotehost ansible_ssh_user=ansible

userid exists.

Never mind. It was typo in my /etc/ansible/hosts file.