Hi@akhtar,
You can use the ec2_key module in your playbook. In this module, you have to set state value as absent. I have attached one playbook below for your reference.
- hosts: localhost
tasks:
- name: Remove key pair
ec2_key:
name: my_keypair
region: ap-south-1
state: absent
aws_access_key:
aws_secret_key: