creating ec2 key and save the result to a file

I’m trying to use ec2_key module, creating a new key and save it to a file for future use.
The first succeed, but I have problem saving to a .pem file:
Look like ec2_key.private_key is not returned, but ec2_key.fingerprint is.

Any idea why?

Thanks
Tzach

Tzach,

change ec2_key.private_key into ec2_key.key.private_key, here is a working example of this one for your reference. By the way, I am using Ansible 2.0.1.0

`

  • 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
    `

Hope this will help you.

Thanks!