How to use a public keypair .pem file for ansible playbooks?


I want to use a public aws keypair .pem file for running ansible playbooks. I want to do this without changing my ~/.ssh/ and I can’t create a new keypair from my current ~/.ssh/ and apply it to the ec2 instances I am trying to change.

Here is my hosts file (note that my actual ip is replaced with This is probably the issue since I need a way to set a public key variable and use that:

Here is my playbook:

This is the command I am using to run it:

It results in the following error:

There is no problem with my keypair:

What am I doing wrong?


Ok little mistakes I guess you can’t have spaces in host file variables and need to define the group you are applying the vars to. This hosts file works with it all:

Leave a Reply