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

25 views
Skip to first unread message

anilkumar panditi

unread,
Feb 4, 2020, 7:11:30 AM2/4/20
to Ansible Project
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.

Stefan Hornburg (Racke)

unread,
Feb 4, 2020, 7:19:13 AM2/4/20
to ansible...@googlegroups.com
Your syntax in the inventory file is bogus, please try

ansible_ssh_private_key_file=/home/centos/openshift.pem

Regards
Racke

>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/fb8ec1ed-2346-417b-b056-171d65418f1e%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/fb8ec1ed-2346-417b-b056-171d65418f1e%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc

anilkumar panditi

unread,
Feb 4, 2020, 7:36:10 AM2/4/20
to Ansible Project
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




On Tuesday, 4 February 2020 17:49:13 UTC+5:30, Stefan Hornburg (Racke) wrote:
On 2/4/20 1:11 PM, anilkumar panditi wrote:
> 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

>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to

Stefan Hornburg (Racke)

unread,
Feb 4, 2020, 7:38:52 AM2/4/20
to ansible...@googlegroups.com
On 2/4/20 1:36 PM, anilkumar panditi wrote:
> 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

>
>
> On Tuesday, 4 February 2020 17:49:13 UTC+5:30, Stefan Hornburg (Racke) wrote:
>
> On 2/4/20 1:11 PM, anilkumar panditi wrote:
> > 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
>
> >
> > --
> > You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to
> > ansible...@googlegroups.com <javascript:> <mailto:ansible-proje...@googlegroups.com <javascript:>>.
> <https://groups.google.com/d/msgid/ansible-project/fb8ec1ed-2346-417b-b056-171d65418f1e%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/ansible-project/fb8ec1ed-2346-417b-b056-171d65418f1e%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
>
>
> --
> Ecommerce and Linux consulting + Perl and web application programming.
> Debian and Sympa administration. Provisioning with Ansible.
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/1ff8ed87-5558-47bb-902c-620c2072db73%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/1ff8ed87-5558-47bb-902c-620c2072db73%40googlegroups.com?utm_medium=email&utm_source=footer>.
signature.asc

anilkumar panditi

unread,
Feb 4, 2020, 8:29:15 AM2/4/20
to Ansible Project
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.
>     > ansible...@googlegroups.com <javascript:> <mailto:ansible-project+unsub...@googlegroups.com <javascript:>>.
>     > To view this discussion on the web visit
>     > https://groups.google.com/d/msgid/ansible-project/fb8ec1ed-2346-417b-b056-171d65418f1e%40googlegroups.com
>     <https://groups.google.com/d/msgid/ansible-project/fb8ec1ed-2346-417b-b056-171d65418f1e%40googlegroups.com>
>     >
>     <https://groups.google.com/d/msgid/ansible-project/fb8ec1ed-2346-417b-b056-171d65418f1e%40googlegroups.com?utm_medium=email&utm_source=footer
>     <https://groups.google.com/d/msgid/ansible-project/fb8ec1ed-2346-417b-b056-171d65418f1e%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
>
>
>     --
>     Ecommerce and Linux consulting + Perl and web application programming.
>     Debian and Sympa administration. Provisioning with Ansible.
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
Reply all
Reply to author
Forward
0 new messages