terminate instance behind ELB

60 views
Skip to first unread message

Rahul Mehrotra

unread,
Apr 21, 2015, 6:04:22 PM4/21/15
to ansible...@googlegroups.com
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

Raghu Udiyar

unread,
Apr 22, 2015, 3:24:52 AM4/22/15
to ansible...@googlegroups.com
Disable gather_facts, so ansible won't try to contact the instance : 

---
- name: destroy ec2 instance
  hosts: "{{cli_hosts}}"
  gather_facts: false
  tasks:
   - name: remove instance by instance id
     ec2:
       state: absent
       region: "{{ec2_region}}"
       instance_ids: "{{ec2_id}}"
       wait: true
     delegate_to: localhost

-- Raghu
Reply all
Reply to author
Forward
0 new messages