terminate.yml 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. ---
  2. - name: Terminate instance(s)
  3. hosts: localhost
  4. connection: local
  5. gather_facts: no
  6. vars_files:
  7. - vars.yml
  8. tasks:
  9. - set_fact: scratch_group=tag_env-{{ cluster_id }}
  10. - add_host:
  11. name: "{{ item }}"
  12. groups: oo_hosts_to_terminate
  13. ansible_ssh_user: "{{ deployment_vars[deployment_type].ssh_user | default(ansible_ssh_user, true) }}"
  14. ansible_sudo: "{{ deployment_vars[deployment_type].sudo }}"
  15. with_items: groups[scratch_group] | default([], true) | difference(['localhost']) | difference(groups.status_terminated | default([], true))
  16. - name: Unsubscribe VMs
  17. hosts: oo_hosts_to_terminate
  18. vars_files:
  19. - vars.yml
  20. roles:
  21. - role: rhel_unsubscribe
  22. when: deployment_type == "enterprise" and
  23. ansible_distribution == "RedHat" and
  24. lookup('oo_option', 'rhel_skip_subscription') | default(rhsub_skip, True) |
  25. default('no', True) | lower in ['no', 'false']
  26. - name: Terminate instances(s)
  27. hosts: localhost
  28. connection: local
  29. gather_facts: no
  30. vars_files:
  31. - vars.yml
  32. tasks:
  33. - name: Terminate instances that were previously launched
  34. local_action:
  35. module: gce
  36. state: 'absent'
  37. name: "{{ item }}"
  38. service_account_email: "{{ lookup('env', 'gce_service_account_email_address') }}"
  39. pem_file: "{{ lookup('env', 'gce_service_account_pem_file_path') }}"
  40. project_id: "{{ lookup('env', 'gce_project_id') }}"
  41. zone: "{{ lookup('env', 'zone') }}"
  42. with_items: groups['oo_hosts_to_terminate'] | default([], true)
  43. when: item is defined
  44. #- include: ../openshift-node/terminate.yml
  45. # vars:
  46. # gce_service_account_email: "{{ lookup('env', 'gce_service_account_email_address') }}"
  47. # gce_pem_file: "{{ lookup('env', 'gce_service_account_pem_file_path') }}"
  48. # gce_project_id: "{{ lookup('env', 'gce_project_id') }}"
  49. #
  50. #- include: ../openshift-master/terminate.yml
  51. # vars:
  52. # gce_service_account_email: "{{ lookup('env', 'gce_service_account_email_address') }}"
  53. # gce_pem_file: "{{ lookup('env', 'gce_service_account_pem_file_path') }}"
  54. # gce_project_id: "{{ lookup('env', 'gce_project_id') }}"