I don't know how to use the ec2_key module in Ansible. Can somebody please give me an example of how to create a new Key-Pair?
working example:
- name: Create an EC2 key
ec2_key:
name: "mykey"
region: "eu-west-1"
register: ec2_key
- name: save private key
copy:
content: "{{ ec2_key.key.private_key }}"
dest: "./aws-private.pem"
mode: 0600
when: ec2_key.changed
The examples in the Ansible documentation appear to show exactly how to do this:
# Creates a new ec2 key pair named `example` if not present, returns generated
# private key
- name: example ec2 key
local_action:
module: ec2_key
name: example
# Creates a new ec2 key pair named `example` if not present using provided key
# material
- name: example2 ec2 key
local_action:
module: ec2_key
name: example2
key_material: 'ssh-rsa AAAAxyz...== [email protected]'
state: present
# Creates a new ec2 key pair named `example` if not present using provided key
# material
- name: example3 ec2 key
local_action:
module: ec2_key
name: example3
key_material: "{{ item }}"
with_file: /path/to/public_key.id_rsa.pub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With