Install apache on awa ec2 from locally installed ansible server on my laptop I would like to install apache2 remotely on aws ec2 instance from my locally installed ansible server on my laptop. I have also the. pem key of the instance. Now what Ip need to put in /etc/ansible/hosts file inorder to connect ec2 instance from my laptop?
You need to put public ip address or hostname assigned by aws ec2 service, if your aws ec2 instance is public.

If your aws ec2 instance is located in vpc, you won't be able to connect it directly. Either you need to setup routing through internet gateway or you have to setup ansible server in vpc.