amazon ec2 key pair

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


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.

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

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.

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?

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