remove_bootstrap.yml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. ---
  2. - name: Get bootstrap instance group
  3. gcp_compute_instance_group_manager_facts:
  4. auth_kind: serviceaccount
  5. scopes:
  6. - https://www.googleapis.com/auth/compute
  7. service_account_file: "{{ openshift_gcp_iam_service_account_keyfile }}"
  8. project: "{{ openshift_gcp_project }}"
  9. zone: "{{ openshift_gcp_zone }}"
  10. filters:
  11. - name = "{{ openshift_gcp_prefix }}ig-b"
  12. register: bootstrap_instance_group
  13. - name: Get bootstrap instance template
  14. gcp_compute_instance_template_facts:
  15. auth_kind: serviceaccount
  16. scopes:
  17. - https://www.googleapis.com/auth/compute
  18. service_account_file: "{{ openshift_gcp_iam_service_account_keyfile }}"
  19. project: "{{ openshift_gcp_project }}"
  20. filters:
  21. - "name : {{ openshift_gcp_prefix }}instance-template-bootstrap"
  22. register: bootstrap_instance_template
  23. - name: Collect a list of instances
  24. gcp_compute_instance_facts:
  25. auth_kind: serviceaccount
  26. scopes:
  27. - https://www.googleapis.com/auth/compute
  28. service_account_file: "{{ openshift_gcp_iam_service_account_keyfile }}"
  29. project: "{{ openshift_gcp_project }}"
  30. zone: "{{ openshift_gcp_zone }}"
  31. register: all_instances
  32. - name: Filter instances to fetch masters
  33. set_fact:
  34. master_instances: "{{ master_instances | default([]) }} + [ {{ item }} ]"
  35. with_items:
  36. - "{{ all_instances['items'] }}"
  37. when:
  38. - "'tags' in item"
  39. - "'items' in item['tags']"
  40. - "cluster_tag in item['tags']['items']"
  41. - "'ocp-master' in item['tags']['items']"
  42. vars:
  43. cluster_tag: "{{ openshift_gcp_prefix }}ocp"
  44. - set_fact:
  45. master_external_ips: "{{ master_external_ips | default([]) }} + [ '{{ master_ip }}' ]"
  46. with_indexed_items: "{{ master_instances }}"
  47. vars:
  48. master_ip: "{{ item.1.networkInterfaces[0].accessConfigs[0].natIP }}"
  49. - name: Get a managed zone
  50. gcp_dns_managed_zone:
  51. auth_kind: serviceaccount
  52. scopes:
  53. - https://www.googleapis.com/auth/ndev.clouddns.readwrite
  54. service_account_file: "{{ openshift_gcp_iam_service_account_keyfile }}"
  55. project: "{{ openshift_gcp_project }}"
  56. name: "{{ dns_managed_zone | default(openshift_gcp_prefix + 'managed-zone') }}"
  57. state: present
  58. register: managed_zone
  59. - name: Update public API hostname
  60. gcp_dns_resource_record_set:
  61. auth_kind: serviceaccount
  62. scopes:
  63. - https://www.googleapis.com/auth/ndev.clouddns.readwrite
  64. service_account_file: "{{ openshift_gcp_iam_service_account_keyfile }}"
  65. project: "{{ openshift_gcp_project }}"
  66. name: "{{ openshift_master_cluster_public_hostname }}."
  67. managed_zone: "{{ managed_zone }}"
  68. type: A
  69. ttl: 600
  70. target: "{{ master_external_ips }}"
  71. state: present
  72. - name: Delete bootstrap instance group
  73. gcp_compute_instance_group_manager:
  74. auth_kind: serviceaccount
  75. scopes:
  76. - https://www.googleapis.com/auth/compute
  77. service_account_file: "{{ openshift_gcp_iam_service_account_keyfile }}"
  78. project: "{{ openshift_gcp_project }}"
  79. zone: "{{ openshift_gcp_zone }}"
  80. name: "{{ bootstrap_instance_group['items'][0]['name'] }}"
  81. base_instance_name: "{{ bootstrap_instance_group['items'][0]['baseInstanceName'] }}"
  82. instance_template: "{{ bootstrap_instance_template['items'][0] }}"
  83. state: absent
  84. when:
  85. - bootstrap_instance_group['items'] | length > 0
  86. - bootstrap_instance_template['items'] | length > 0