Before we complete this chapter, we need to look at terminating the resources; the only additions we need to make are to remove the autoscaling group and AMIs. To do this, we are going to add four tasks to roles/remove/tasks/main.yml; starting at the top of the file, add the following two tasks:
- name: remove the auto-scaling group ec2_asg: region: "{{ ec2_region }}" name: "{{ environment_name }}-asg" state: absent wait_for_instances: "yes" wait_timeout: "900"
- name: wait for 2 minutes before continuing pause: minutes: 2
The first task removes the autoscaling group. This, in turn, will terminate any instances that have been launched by it. We have also built in a pause to ensure that everything has been removed ...