Hi@akhtar,
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
  tasks:
  - name: create a new ec2 key pair, returns generated private key
    ec2_key:
      name: my_keypair
      region: ap-south-1
      aws_access_key: 
      aws_secret_key: