I am working with Ansible and just accidentally terminated 4 ec2 instances out of 20+ in AWS and I’m trying to figure out the why as to what was deleted. I have already determined that the code I originally used was wrong, but wish to understand what happened. The quasi code in question was/is:
- name: Create EC2
ec2:
key_name: key
instance_type: t2.medium
image: actual_amiID
wait: yes
region: us-east-1
vpc_subnet_id: actual_subnetID
instance_tags: { “Name”:“vpc03VM01” }
group_id: actual_securitygroupID
count_tag: (or count_tag: 1)
exact_count: 1
I’m not 100% sure that count_tag was empty it may have been 1. 4 instances were destroyed, it tried to destroy a 5th, but it had protection. All of them had some tags, only one of them had the Name tag in question, but two of the other ones were named similarly ( vpc01VM01 / vpc02VM01 ), the other three (including the one that wasn’t destroyed because of protections) were named differently. I want to understand why these instances were terminated and the one that I was trying to create wasn’t created. I was trying to use the count_tag and exact_count to be similar in functionality to “state: present.”