You can find the ec2_key module in Ansible. This is used to create a key pair on the AWS cloud. I have attached the below playbook for your reference.
- hosts: localhost
- name: create a new ec2 key pair, returns generated private key