I have an ec2 instance on which i am running ansible.I want to create a user with a playbook, but without a password and the user must be using existing pem file for authentication and must be able to login to instance that file.Tricky part here is how to write play that creates a user and associates it with existing pem file.I am completely out of ideas.
Asked
Active
Viewed 857 times
1 Answers
1
You will just need to add the public key contained in the pem file in the authorized_keys file for the user.
The public key can be extract like this:
openssl rsa -in charlie.pem -pubout > charlie.pub
The public key can than be stored in the Ansible code under files
.
Than you can use the user module to create the user and the authorized_key module to add the public key like this:
- user: name=charlie state=present
- authorized_key: user=charlie key="{{ lookup('file', 'charlie.pub') }}"

Henrik Pingel
- 9,380
- 2
- 28
- 39