main.yaml 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. ---
  2. - name: Validate Elasticsearch cluster size
  3. fail: msg="The openshift_logging_es_cluster_size may only be scaled down manually. Please see official documentation on how to do this."
  4. when: openshift_logging_facts.elasticsearch.deploymentconfigs | length > openshift_logging_es_cluster_size|int
  5. - name: Validate Elasticsearch Ops cluster size
  6. fail: msg="The openshift_logging_es_ops_cluster_size may only be scaled down manually. Please see official documentation on how to do this."
  7. when: openshift_logging_facts.elasticsearch_ops.deploymentconfigs | length > openshift_logging_es_ops_cluster_size|int
  8. - fail:
  9. msg: Invalid deployment type, one of ['data-master', 'data-client', 'master', 'client'] allowed
  10. when: not openshift_logging_elasticsearch_deployment_type in __allowed_es_types
  11. - set_fact: elasticsearch_name="{{ 'logging-elasticsearch' ~ ( (openshift_logging_elasticsearch_ops_deployment | default(false) | bool) | ternary('-ops', '')) }}"
  12. - include: determine_version.yaml
  13. # allow passing in a tempdir
  14. - name: Create temp directory for doing work in
  15. command: mktemp -d /tmp/openshift-logging-ansible-XXXXXX
  16. register: mktemp
  17. changed_when: False
  18. - set_fact:
  19. tempdir: "{{ mktemp.stdout }}"
  20. # This may not be necessary in this role
  21. - name: Create templates subdirectory
  22. file:
  23. state: directory
  24. path: "{{ tempdir }}/templates"
  25. mode: 0755
  26. changed_when: False
  27. # we want to make sure we have all the necessary components here
  28. # service account
  29. - name: Create ES service account
  30. oc_serviceaccount:
  31. state: present
  32. name: "aggregated-logging-elasticsearch"
  33. namespace: "{{ openshift_logging_namespace }}"
  34. image_pull_secrets: "{{ openshift_logging_image_pull_secret }}"
  35. when: openshift_logging_image_pull_secret != ''
  36. - name: Create ES service account
  37. oc_serviceaccount:
  38. state: present
  39. name: "aggregated-logging-elasticsearch"
  40. namespace: "{{ openshift_logging_namespace }}"
  41. when:
  42. - openshift_logging_image_pull_secret == ''
  43. # rolebinding reader
  44. - copy:
  45. src: rolebinding-reader.yml
  46. dest: "{{ tempdir }}/rolebinding-reader.yml"
  47. - name: Create rolebinding-reader role
  48. oc_obj:
  49. state: present
  50. name: "rolebinding-reader"
  51. kind: clusterrole
  52. namespace: "{{ openshift_logging_namespace }}"
  53. files:
  54. - "{{ tempdir }}/rolebinding-reader.yml"
  55. delete_after: true
  56. # SA roles
  57. - name: Set rolebinding-reader permissions for ES
  58. oc_adm_policy_user:
  59. state: present
  60. namespace: "{{ openshift_logging_namespace }}"
  61. resource_kind: cluster-role
  62. resource_name: rolebinding-reader
  63. user: "system:serviceaccount:{{ openshift_logging_namespace }}:aggregated-logging-elasticsearch"
  64. # configmap
  65. - template:
  66. src: elasticsearch-logging.yml.j2
  67. dest: "{{ tempdir }}/elasticsearch-logging.yml"
  68. when: es_logging_contents is undefined
  69. changed_when: no
  70. - template:
  71. src: elasticsearch.yml.j2
  72. dest: "{{ tempdir }}/elasticsearch.yml"
  73. vars:
  74. allow_cluster_reader: "{{ openshift_logging_elasticsearch_ops_allow_cluster_reader | lower | default('false') }}"
  75. deploy_type: "{{ openshift_logging_elasticsearch_deployment_type }}"
  76. when: es_config_contents is undefined
  77. changed_when: no
  78. - copy:
  79. content: "{{ es_logging_contents }}"
  80. dest: "{{ tempdir }}/elasticsearch-logging.yml"
  81. when: es_logging_contents is defined
  82. changed_when: no
  83. - copy:
  84. content: "{{ es_config_contents }}"
  85. dest: "{{ tempdir }}/elasticsearch.yml"
  86. when: es_config_contents is defined
  87. changed_when: no
  88. - name: Set ES configmap
  89. oc_configmap:
  90. state: present
  91. name: "{{ elasticsearch_name }}-{{ openshift_logging_elasticsearch_deployment_type }}"
  92. namespace: "{{ openshift_logging_namespace }}"
  93. from_file:
  94. elasticsearch.yml: "{{ tempdir }}/elasticsearch.yml"
  95. logging.yml: "{{ tempdir }}/elasticsearch-logging.yml"
  96. # when:
  97. # secret
  98. - name: Set ES secret
  99. oc_secret:
  100. state: present
  101. name: "logging-elasticsearch"
  102. namespace: "{{ openshift_logging_namespace }}"
  103. files:
  104. - name: key
  105. path: "{{ generated_certs_dir }}/logging-es.jks"
  106. - name: truststore
  107. path: "{{ generated_certs_dir }}/truststore.jks"
  108. - name: searchguard.key
  109. path: "{{ generated_certs_dir }}/elasticsearch.jks"
  110. - name: searchguard.truststore
  111. path: "{{ generated_certs_dir }}/truststore.jks"
  112. - name: admin-key
  113. path: "{{ generated_certs_dir }}/system.admin.key"
  114. - name: admin-cert
  115. path: "{{ generated_certs_dir }}/system.admin.crt"
  116. - name: admin-ca
  117. path: "{{ generated_certs_dir }}/ca.crt"
  118. - name: admin.jks
  119. path: "{{ generated_certs_dir }}/system.admin.jks"
  120. - name: Creating ES storage template
  121. template:
  122. src: pvc.j2
  123. dest: "{{ tempdir }}/templates/logging-es-pvc.yml"
  124. vars:
  125. obj_name: "{{ openshift_logging_elasticsearch_pvc_name }}"
  126. size: "{{ openshift_logging_elasticsearch_pvc_size }}"
  127. access_modes: "{{ openshift_logging_elasticsearch_pvc_access_modes | list }}"
  128. pv_selector: "{{ openshift_logging_elasticsearch_pvc_pv_selector }}"
  129. when:
  130. - openshift_logging_elasticsearch_storage_type == "pvc"
  131. - not openshift_logging_elasticsearch_pvc_dynamic
  132. - name: Creating ES storage template
  133. template:
  134. src: pvc.j2
  135. dest: "{{ tempdir }}/templates/logging-es-pvc.yml"
  136. vars:
  137. obj_name: "{{ openshift_logging_elasticsearch_pvc_name }}"
  138. size: "{{ openshift_logging_elasticsearch_pvc_size }}"
  139. access_modes: "{{ openshift_logging_elasticsearch_pvc_access_modes | list }}"
  140. pv_selector: "{{ openshift_logging_elasticsearch_pvc_pv_selector }}"
  141. annotations:
  142. volume.alpha.kubernetes.io/storage-class: "dynamic"
  143. when:
  144. - openshift_logging_elasticsearch_storage_type == "pvc"
  145. - openshift_logging_elasticsearch_pvc_dynamic
  146. - name: Set ES storage
  147. oc_obj:
  148. state: present
  149. kind: pvc
  150. name: "{{ openshift_logging_elasticsearch_pvc_name }}"
  151. namespace: "{{ openshift_logging_namespace }}"
  152. files:
  153. - "{{ tempdir }}/templates/logging-es-pvc.yml"
  154. delete_after: true
  155. when:
  156. - openshift_logging_elasticsearch_storage_type == "pvc"
  157. - set_fact:
  158. es_component: "{{ 'es' ~ ( (openshift_logging_elasticsearch_ops_deployment | default(false) | bool) | ternary('-ops', '') ) }}"
  159. - set_fact:
  160. es_deploy_name: "logging-{{ es_component }}-{{ openshift_logging_elasticsearch_deployment_type }}-{{ 'abcdefghijklmnopqrstuvwxyz0123456789' | random_word(8) }}"
  161. when: openshift_logging_elasticsearch_deployment_name == ""
  162. - set_fact:
  163. es_deploy_name: "{{ openshift_logging_elasticsearch_deployment_name }}"
  164. when: openshift_logging_elasticsearch_deployment_name != ""
  165. # DC
  166. - name: Set ES dc templates
  167. template:
  168. src: es.j2
  169. dest: "{{ tempdir }}/templates/logging-es-dc.yml"
  170. vars:
  171. es_configmap: "{{ elasticsearch_name }}-{{ openshift_logging_elasticsearch_deployment_type }}"
  172. es_cluster_name: "{{ es_component }}"
  173. logging_component: "{{ es_component }}"
  174. deploy_name: "{{ es_deploy_name }}"
  175. image: "{{ openshift_logging_image_prefix }}logging-elasticsearch:{{ openshift_logging_image_version }}"
  176. es_cpu_limit: "{{ openshift_logging_elasticsearch_cpu_limit }}"
  177. es_memory_limit: "{{ openshift_logging_elasticsearch_memory_limit }}"
  178. es_node_selector: "{{ openshift_logging_elasticsearch_nodeselector | default({}) }}"
  179. - name: Set ES dc
  180. oc_obj:
  181. state: present
  182. name: "{{ es_deploy_name }}"
  183. namespace: "{{ openshift_logging_namespace }}"
  184. kind: dc
  185. files:
  186. - "{{ tempdir }}/templates/logging-es-dc.yml"
  187. delete_after: true
  188. # scale up
  189. - name: Start Elasticsearch
  190. oc_scale:
  191. kind: dc
  192. name: "{{ es_deploy_name }}"
  193. namespace: "{{ openshift_logging_namespace }}"
  194. replicas: 1
  195. ## Placeholder for migration when necessary ##
  196. - name: Delete temp directory
  197. file:
  198. name: "{{ tempdir }}"
  199. state: absent
  200. changed_when: False