Created
August 22, 2016 14:50
-
-
Save josnidhin/c57e2cc585d99e25cb3b234b703aad11 to your computer and use it in GitHub Desktop.
The ansible script to find ec2 instances with certain tags and terminate them. Does not uses ec2 dynamic inventory script.
As with latest version of ansible this is working for me searching by the Name tag but could be any key.
ec2_instance_facts:
region: "{{ region }}"
filters:
"tag:Name": "{{ ec2_tag_name }}"
register: ec2_list
They have renamed facts to info.
- name: collect list of node instances
amazon.aws.ec2_instance_info:
region: "{{ region }}"
filters:
"tag:Role": "node"
"tag:Vpc": "{{ vpc_name }}"
register: ec2_list
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script was written a long time back. But its still working for me. Did you update the
vars
to reflect your environment?The
Filter EC2 instances
task not required anymore,ec2_remote_facts
now supports filtering.