terminate.yml 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. - name: "populate oo_hosts_to_terminate host group if needed"
  2. hosts: localhost
  3. gather_facts: no
  4. tasks:
  5. - debug: var=oo_host_group_exp
  6. - name: Evaluate oo_host_group_exp if it's set
  7. add_host: "name={{ item }} groups=oo_hosts_to_terminate"
  8. with_items: "{{ oo_host_group_exp | default('') }}"
  9. when: oo_host_group_exp is defined
  10. - debug: msg="{{ groups['oo_hosts_to_terminate'] }}"
  11. - name: Terminate instances
  12. hosts: localhost
  13. connection: local
  14. tasks:
  15. - name: Terminate minion instances
  16. gce:
  17. service_account_email: "{{ gce_service_account_email }}"
  18. pem_file: "{{ gce_pem_file }}"
  19. project_id: "{{ gce_project_id }}"
  20. state: 'absent'
  21. instance_names: "{{ groups['oo_hosts_to_terminate'] }}"
  22. disks: "{{ groups['oo_hosts_to_terminate'] }}"
  23. register: gce
  24. - debug: var=gce
  25. - name: Remove disks of instances
  26. gce_pd:
  27. service_account_email: "{{ gce_service_account_email }}"
  28. pem_file: "{{ gce_pem_file }}"
  29. project_id: "{{ gce_project_id }}"
  30. name: "{{ item }}"
  31. zone: "{{ gce.zone }}"
  32. state: absent
  33. with_items: gce.instance_names