restart_cluster.yml 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. ---
  2. # Disable external communication for {{ _cluster_component }}
  3. - name: Disable external communication for logging-{{ _cluster_component }}
  4. oc_service:
  5. state: present
  6. name: "logging-{{ _cluster_component }}"
  7. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  8. selector:
  9. component: "{{ _cluster_component }}"
  10. provider: openshift
  11. connection: blocked
  12. labels:
  13. logging-infra: 'support'
  14. ports:
  15. - port: 9200
  16. targetPort: "restapi"
  17. when:
  18. - full_restart_cluster | bool
  19. ## get all pods for the cluster
  20. - command: >
  21. oc get pod -l component={{ _cluster_component }},provider=openshift -n {{ openshift_logging_elasticsearch_namespace }} -o jsonpath={.items[?(@.status.phase==\"Running\")].metadata.name}
  22. register: _cluster_pods
  23. - name: "Disable shard balancing for logging-{{ _cluster_component }} cluster"
  24. command: >
  25. oc exec {{ _cluster_pods.stdout.split(' ')[0] }} -c elasticsearch -n {{ openshift_logging_elasticsearch_namespace }} -- {{ __es_local_curl }} -XPUT 'https://localhost:9200/_cluster/settings' -d '{ "transient": { "cluster.routing.allocation.enable" : "none" } }'
  26. register: _disable_output
  27. changed_when: "'\"acknowledged\":true' in _disable_output.stdout"
  28. when: _cluster_pods.stdout_lines | count > 0
  29. # Flush ES
  30. - name: "Flushing for logging-{{ _cluster_component }} cluster"
  31. command: >
  32. oc exec {{ _cluster_pods.stdout.split(' ')[0] }} -c elasticsearch -n {{ openshift_logging_elasticsearch_namespace }} -- {{ __es_local_curl }} -XPUT 'https://localhost:9200/_flush/synced'
  33. register: _flush_output
  34. changed_when: "'\"acknowledged\":true' in _flush_output.stdout"
  35. when:
  36. - _cluster_pods.stdout_lines | count > 0
  37. - full_restart_cluster | bool
  38. - command: >
  39. oc get dc -l component={{ _cluster_component }},provider=openshift -n {{ openshift_logging_elasticsearch_namespace }} -o jsonpath={.items[*].metadata.name}
  40. register: _cluster_dcs
  41. ## restart all dcs for full restart
  42. - name: "Restart ES node {{ _es_node }}"
  43. include_tasks: restart_es_node.yml
  44. with_items: "{{ _cluster_dcs }}"
  45. loop_control:
  46. loop_var: _es_node
  47. when:
  48. - full_restart_cluster | bool
  49. ## restart the node if it's dc is in the list of nodes to restart?
  50. - name: "Restart ES node {{ _es_node }}"
  51. include_tasks: restart_es_node.yml
  52. with_items: "{{ _restart_logging_nodes }}"
  53. loop_control:
  54. loop_var: _es_node
  55. when:
  56. - not full_restart_cluster | bool
  57. - _es_node in _cluster_dcs.stdout
  58. ## we may need a new first pod to run against -- fetch them all again
  59. - command: >
  60. oc get pod -l component={{ _cluster_component }},provider=openshift -n {{ openshift_logging_elasticsearch_namespace }} -o jsonpath={.items[?(@.status.phase==\"Running\")].metadata.name}
  61. register: _cluster_pods
  62. - name: "Enable shard balancing for logging-{{ _cluster_component }} cluster"
  63. command: >
  64. oc exec {{ _cluster_pods.stdout.split(' ')[0] }} -c elasticsearch -n {{ openshift_logging_elasticsearch_namespace }} -- {{ __es_local_curl }} -XPUT 'https://localhost:9200/_cluster/settings' -d '{ "transient": { "cluster.routing.allocation.enable" : "all" } }'
  65. register: _enable_output
  66. changed_when: "'\"acknowledged\":true' in _enable_output.stdout"
  67. # Reenable external communication for {{ _cluster_component }}
  68. - name: Reenable external communication for logging-{{ _cluster_component }}
  69. oc_service:
  70. state: present
  71. name: "logging-{{ _cluster_component }}"
  72. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  73. selector:
  74. component: "{{ _cluster_component }}"
  75. provider: openshift
  76. labels:
  77. logging-infra: 'support'
  78. ports:
  79. - port: 9200
  80. targetPort: "restapi"
  81. when:
  82. - full_restart_cluster | bool