# amazon ec2 key pair

**URL:** <https://forum.ansible.com/t/amazon-ec2-key-pair/13362>\
**Category:** Ansible Project\
**Created:** [August 26, 2013, 3:32pm UTC](https://forum.ansible.com/t/amazon-ec2-key-pair/13362 "2013-08-26T15:32:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![carl](https://avatars.discourse-cdn.com/v4/letter/c/ee7513/32.png) [@carl](https://forum.ansible.com/u/carl)\
**Post date:** [August 26, 2013, 3:32pm UTC](https://forum.ansible.com/t/amazon-ec2-key-pair/13362/1 "2013-08-26T15:32:30Z")

</div>

In the ansible works documentation, it says that you can reference an amazon ec2 key pair like this:

```auto

ec2 keypair={{mykeypair}}

However, I cannot seem to find what format {mykeypair} should take. I want to use .yml variables (and not set environment variables) in my plays since I have many amazon accounts with different key pairs.

```

---

<div class="post-metadata">

**Author:** ![James\_Cammarata1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@James\_Cammarata1](https://forum.ansible.com/u/James_Cammarata1)\
**Post date:** [August 26, 2013, 3:46pm UTC](https://forum.ansible.com/t/amazon-ec2-key-pair/13362/2 "2013-08-26T15:46:24Z")

</div>

The keypair= is a path to a file that you downloaded from Amazon. Typically this is saved as filename.pem.

---

<div class="post-metadata">

**Author:** ![James\_Cammarata1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@James\_Cammarata1](https://forum.ansible.com/u/James_Cammarata1)\
**Post date:** [August 26, 2013, 3:47pm UTC](https://forum.ansible.com/t/amazon-ec2-key-pair/13362/3 "2013-08-26T15:47:53Z")

</div>

Actually, let correct myself. The keypair= is the name of the keypair associated with your user, which will be assigned as the keypair to the system. You then use the AWS GUI to download the key.pem file, and use that as the private SSH key.

---

<div class="post-metadata">

**Author:** ![carl](https://avatars.discourse-cdn.com/v4/letter/c/ee7513/32.png) [@carl](https://forum.ansible.com/u/carl)\
**Post date:** [August 26, 2013, 6:26pm UTC](https://forum.ansible.com/t/amazon-ec2-key-pair/13362/4 "2013-08-26T18:26:47Z")

</div>

Thanks for this.

When I try to run:

ansible localhost -m ec2 -a “image=ami-03559b6a instance\_type=m1.medium keypair=.pem group= wait=yes count=1”

I get this error:

localhost | FAILED =\> FAILED: Authentication failed.

How do I get past localhost authentication?

---

<div class="post-metadata">

**Author:** ![Bruce\_Pennypacker](https://avatars.discourse-cdn.com/v4/letter/b/0ea827/32.png) [@Bruce\_Pennypacker](https://forum.ansible.com/u/Bruce_Pennypacker)\
**Post date:** [August 26, 2013, 6:38pm UTC](https://forum.ansible.com/t/amazon-ec2-key-pair/13362/5 "2013-08-26T18:38:06Z")

</div>

The keypair in this case is the name of an existing AWS keypair. If you log into the AWS management console and navigate to EC2 → Key Pairs, then it’s the name of one of the keypairs that’s already defined there.

The “Authentication failed” message you’re getting here has nothing to do with the keypair. You need to specify both an AWS API key and private key, either via the aws\_access\_key and aws\_secret\_key parameters in the ec2 module, or via the AWS\_ACCESS\_KEY and AWS\_SECRET\_KEY environment variables. And those AWS keys must have permission to launch ec2 instances. If those parameters aren’t properly set or the specified AWS keys don’t have the authority to launch instances then you’ll likely get the authentication failed error.

-Bruce
