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.
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.
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.