i have searched the whole internet and cannot find anwser to this question. "how can i terminate an ec2 instance using dynamic inventory with tags?" so if i can terminate an instance or group of ec2 instances with specific tag(s)
the ec2 module requires one to pass the instance-id but there is nothing automated in doing that. SO looking for a way to target specific tags using dynamic inventory with ansible
- name: terminate single instance
hosts: all
tasks:
- action: ec2_facts
- name: terminating single instance
local_action:
module: ec2
state: 'absent'
region: us-east-1
instance_ids: "{{ ansible_ec2_instance_id }}"
I have tried the above with the following comamnd
ansible-playbook terminate.yml --tags "tag_Name_web_server"
which means i want too delete ec2 instances with Name' tag 'web-server
Right now when i run that, it looks through several ec2 instances but it to only target those with the specified tags. Short story, does not work.
Any help will be greatly appreciated