deprovision.yml 852 B

12345678910111213141516171819202122232425262728293031323334
  1. ---
  2. - hosts: localhost
  3. connection: local
  4. gather_facts: false
  5. tasks:
  6. - include_vars: "{{ item }}"
  7. with_first_found:
  8. - vars.yml
  9. - vars.yaml
  10. - name: Gather ec2 facts
  11. ec2_instance_facts:
  12. region: "{{ aws_region }}"
  13. filters:
  14. tag-key: "kubernetes.io/cluster/{{ aws_cluster_id }}"
  15. register: ec2
  16. - name: Stop VMs
  17. ec2:
  18. instance_ids: "{{ item.instance_id }}"
  19. region: "{{ aws_region }}"
  20. state: stopped
  21. wait: no
  22. with_items: "{{ ec2.instances }}"
  23. ignore_errors: true
  24. - name: Rename VMs
  25. ec2_tag:
  26. resource: "{{ item.instance_id }}"
  27. region: "{{ aws_region }}"
  28. tags:
  29. Name: "{{ item.tags.Name }}-terminate"
  30. when: "'-terminate' not in item.tags.Name"
  31. with_items: "{{ ec2.instances }}"