terminate instance behind ELB

Hi,
I am trying to figure out if there is a way to terminate instance which are in private subnet behind ELB using dynamic inventory.

I have my ansible script as follows

`

  • hosts: localhost
    serial: 1

tasks:

  • name: Terminate {{ec2_id}} instance in {{aws_region}}
    local_action:
    module: ec2
    state: ‘absent’
    region: ‘{{region}}’
    instance_ids: ‘{{ec2_id}}’

`

Now the issue is that ; the instance do not have a public IP, if I am modifying ec2.ini to get private IP and set hosts to like tag_Name_webservers
then ansible tries to SSH inside the instance and fails.

If I set it to localhost it is not able to get the instance_id and exits with ec2_id not found

Can anyone direct me with a correct method to do this ?

Thank you

Disable gather_facts, so ansible won’t try to contact the instance :

`