2

We have around 10 instances already running on AWS using my personal AWS keypair justin.pem.

I am setting up an Ansible box, and generated a new AWS keypair called ansible.pem. I copied ansible.pem to the Ansible instance into .ssh and have it ready to use.

The problem is how do I inject the ansible.pem public key into .ssh/authorized_keys on each of our existing AWS instances?

When we create new instances, I want to assign the justin.pem key pair, but this means that Ansible won't be able to ssh into newly created instances as well.

What is the solution to this? Seems like a chicken and egg problem.

1
  • Does the authorized_keys module work with pem keys? I had trouble with it.
    – esteban
    Sep 29, 2015 at 18:34

1 Answer 1

3

Create new instances with the ansible.pem public key, and then use Ansible's authorized_keys module to distribute any additional public keys you want to access your instance with, such as the corresponding public key for justin.pem.

- name: Install justin's ssh key
  authorized_key: user=ec2-user
                  key="{{lookup('file', '/home/justin/.ssh/justin.pub')}}"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .