Decommissioning resources on AWS using Ansible
In this recipe, we will outline how to decommission a complete network within AWS with all the associated network resources; that is, how we can easily build and tear down resources on the cloud with a simple playbook execution using Ansible. The starting point is the same, the intended data defined and used in the Ansible inventory, but this time using the collections to delete resources.
It’s important to notice the order. We have to undo it in the reverse order of creation, considering the AWS resource dependencies. Thus, the VPC deletion is the last one.
Here are the steps:
- Let’s create a new
pb_delete_vpc.ymlplaybook that implements all the tasks, starting with the VPC ID collection, which is needed in all the subsequent tasks:root@cookbook-lab:~/cookbook-lab/chapters/ch08# ansible-playbook pb_aws_net_delete.yml - name: Delete all VPC resources hosts...