terminate.yml 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 node instances
  12. hosts: localhost
  13. connection: local
  14. gather_facts: no
  15. tasks:
  16. - name: Terminate node instances
  17. gce:
  18. service_account_email: "{{ gce_service_account_email }}"
  19. pem_file: "{{ gce_pem_file }}"
  20. project_id: "{{ gce_project_id }}"
  21. state: 'absent'
  22. instance_names: "{{ groups['oo_hosts_to_terminate'] }}"
  23. disks: "{{ groups['oo_hosts_to_terminate'] }}"
  24. register: gce
  25. - debug: var=gce
  26. - name: Remove disks of instances
  27. gce_pd:
  28. service_account_email: "{{ gce_service_account_email }}"
  29. pem_file: "{{ gce_pem_file }}"
  30. project_id: "{{ gce_project_id }}"
  31. name: "{{ item }}"
  32. zone: "{{ gce.zone }}"
  33. state: absent
  34. with_items: gce.instance_names