How to connect to ec2 instance using .pem file in ansible

Hi ,
I am trying to connect to ec2 instance using .pem file in ansible.
I am getting below error.

fatal: [hdi_master1]: UNREACHABLE! => {
“changed”: false,
“msg”: “Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).”,
“unreachable”: true
}

my inventory:

Hi ,
I am trying to connect to ec2 instance using .pem file in ansible.
I am getting below error.

fatal: [hdi_master1]: UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).",
"unreachable": true
}

my inventory:

# inventory of servers

#ungrouped servers
hdi_master1 ansible_host=13.234.186.61 ansible_connection=ssh ansible_user=centos --private-key=/home/centos/openshift.pem

even though i am passing i am getting above error .can anyone help me please.

Your syntax in the inventory file is bogus, please try

ansible_ssh_private_key_file=/home/centos/openshift.pem

Regards
         Racke

Hi Thank you for your reply,
Now i am getting below error.

“msg”: “Failed to connect to the host via ssh: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r\n@ WARNING: UNPROTECTED PRIVATE KEY FILE! @\r\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r\nPermissions 0644 for ‘/home/centos/openshift.pem’ are too open.\r\nIt is required that your private key files are NOT accessible by others.\r\nThis private key will be ignored.\r\nLoad key "/home/centos/openshift.pem": bad permissions\r\nPermission denied (publickey,gssapi-keyex,gssapi-with-mic).”,
“unreachable”: true

My Inventory :=

Hi Thank you for your reply,
Now i am getting below error.

"msg": "Failed to connect to the host via ssh: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\\r\\n@     

WARNING: UNPROTECTED PRIVATE KEY FILE!
@\r\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r\nPermissions 0644 for '/home/centos/openshift.pem'
are too open.\r\nIt is required that your private key files are NOT accessible by others.\r\nThis private key will be
ignored.\r\nLoad key \"/home/centos/openshift.pem\": bad permissions\r\nPermission denied
(publickey,gssapi-keyex,gssapi-with-mic).",
"unreachable": true

My Inventory :=

hdi_master1 ansible_host=13.234.186.61 ansible_connection=ssh ansible_user=centos
ansible_ssh_private_key_file=/home/centos/openshift.pem

Well, I suppose you can read that error message and fix the permissions !?

Regards
         Racke

Hi,
Thank you so much , i am able to connect now to remote node after changing permissions and using correct syntax in inventory file.

Thank you once again.