Your task looks fine on first look. But why do you use the "connection" and "become" flags on termination? Just asking because you don't use them in the provisioning task.

EDIT2: Are your provisioning- and termination-tasks in the same play? If yes you can access the registered "ec2" variable like this:

- name: Terminate instances that were previously launched ec2: state: 'absent' instance_ids: '{{ item.instance_id }}' region: "{{ aws_region }}" wait: yes wait_timeout: 500 with_items: "{{ ec2.instances }}"

If your termination task is in another play of the same playbook run you have to use the set_fact task to make it accessible for other plays.

If your termination task will be executed in an entirely different playbook run you can find out your instance ids with ec2_instance_facts like this:

- name: get ec2 instance id by its name tag ec2_instance_facts: filters: "tag:ec2_instance_name": "{{ ecs_instance_name }}" instance-state-name: running register: instances

With this method you have to set the above mentioned tag via the provisioning task.