main.yaml 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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:
  12. elasticsearch_name: "{{ 'logging-elasticsearch' ~ ( (openshift_logging_elasticsearch_ops_deployment | default(false) | bool) | ternary('-ops', '')) }}"
  13. es_component: "{{ 'es' ~ ( (openshift_logging_elasticsearch_ops_deployment | default(false) | bool) | ternary('-ops', '') ) }}"
  14. - include: determine_version.yaml
  15. # allow passing in a tempdir
  16. - name: Create temp directory for doing work in
  17. command: mktemp -d /tmp/openshift-logging-ansible-XXXXXX
  18. register: mktemp
  19. changed_when: False
  20. - set_fact:
  21. tempdir: "{{ mktemp.stdout }}"
  22. # This may not be necessary in this role
  23. - name: Create templates subdirectory
  24. file:
  25. state: directory
  26. path: "{{ tempdir }}/templates"
  27. mode: 0755
  28. changed_when: False
  29. # we want to make sure we have all the necessary components here
  30. # service account
  31. - name: Create ES service account
  32. oc_serviceaccount:
  33. state: present
  34. name: "aggregated-logging-elasticsearch"
  35. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  36. image_pull_secrets: "{{ openshift_logging_image_pull_secret }}"
  37. when: openshift_logging_image_pull_secret != ''
  38. - name: Create ES service account
  39. oc_serviceaccount:
  40. state: present
  41. name: "aggregated-logging-elasticsearch"
  42. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  43. when:
  44. - openshift_logging_image_pull_secret == ''
  45. # rolebinding reader
  46. - copy:
  47. src: rolebinding-reader.yml
  48. dest: "{{ tempdir }}/rolebinding-reader.yml"
  49. - name: Create rolebinding-reader role
  50. oc_obj:
  51. state: present
  52. name: "rolebinding-reader"
  53. kind: clusterrole
  54. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  55. files:
  56. - "{{ tempdir }}/rolebinding-reader.yml"
  57. delete_after: true
  58. # SA roles
  59. - name: Set rolebinding-reader permissions for ES
  60. oc_adm_policy_user:
  61. state: present
  62. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  63. resource_kind: cluster-role
  64. resource_name: rolebinding-reader
  65. user: "system:serviceaccount:{{ openshift_logging_elasticsearch_namespace }}:aggregated-logging-elasticsearch"
  66. # View role and binding
  67. - name: Generate logging-elasticsearch-view-role
  68. template:
  69. src: rolebinding.j2
  70. dest: "{{mktemp.stdout}}/logging-elasticsearch-view-role.yaml"
  71. vars:
  72. obj_name: logging-elasticsearch-view-role
  73. roleRef:
  74. name: view
  75. subjects:
  76. - kind: ServiceAccount
  77. name: aggregated-logging-elasticsearch
  78. changed_when: no
  79. - name: Set logging-elasticsearch-view-role role
  80. oc_obj:
  81. state: present
  82. name: "logging-elasticsearch-view-role"
  83. kind: rolebinding
  84. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  85. files:
  86. - "{{ tempdir }}/logging-elasticsearch-view-role.yaml"
  87. delete_after: true
  88. # configmap
  89. - template:
  90. src: elasticsearch-logging.yml.j2
  91. dest: "{{ tempdir }}/elasticsearch-logging.yml"
  92. when: es_logging_contents is undefined
  93. changed_when: no
  94. - template:
  95. src: elasticsearch.yml.j2
  96. dest: "{{ tempdir }}/elasticsearch.yml"
  97. vars:
  98. allow_cluster_reader: "{{ openshift_logging_elasticsearch_ops_allow_cluster_reader | lower | default('false') }}"
  99. when: es_config_contents is undefined
  100. changed_when: no
  101. - copy:
  102. content: "{{ es_logging_contents }}"
  103. dest: "{{ tempdir }}/elasticsearch-logging.yml"
  104. when: es_logging_contents is defined
  105. changed_when: no
  106. - copy:
  107. content: "{{ es_config_contents }}"
  108. dest: "{{ tempdir }}/elasticsearch.yml"
  109. when: es_config_contents is defined
  110. changed_when: no
  111. - name: Set ES configmap
  112. oc_configmap:
  113. state: present
  114. name: "{{ elasticsearch_name }}"
  115. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  116. from_file:
  117. elasticsearch.yml: "{{ tempdir }}/elasticsearch.yml"
  118. logging.yml: "{{ tempdir }}/elasticsearch-logging.yml"
  119. # when:
  120. # secret
  121. - name: Set ES secret
  122. oc_secret:
  123. state: present
  124. name: "logging-elasticsearch"
  125. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  126. files:
  127. - name: key
  128. path: "{{ generated_certs_dir }}/logging-es.jks"
  129. - name: truststore
  130. path: "{{ generated_certs_dir }}/truststore.jks"
  131. - name: searchguard.key
  132. path: "{{ generated_certs_dir }}/elasticsearch.jks"
  133. - name: searchguard.truststore
  134. path: "{{ generated_certs_dir }}/truststore.jks"
  135. - name: admin-key
  136. path: "{{ generated_certs_dir }}/system.admin.key"
  137. - name: admin-cert
  138. path: "{{ generated_certs_dir }}/system.admin.crt"
  139. - name: admin-ca
  140. path: "{{ generated_certs_dir }}/ca.crt"
  141. - name: admin.jks
  142. path: "{{ generated_certs_dir }}/system.admin.jks"
  143. # services
  144. - name: Set logging-{{ es_component }}-cluster service
  145. oc_service:
  146. state: present
  147. name: "logging-{{ es_component }}-cluster"
  148. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  149. selector:
  150. component: "{{ es_component }}"
  151. provider: openshift
  152. # labels:
  153. # - logging-infra: 'support'
  154. ports:
  155. - port: 9300
  156. - name: Set logging-{{ es_component }} service
  157. oc_service:
  158. state: present
  159. name: "logging-{{ es_component }}"
  160. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  161. selector:
  162. component: "{{ es_component }}"
  163. provider: openshift
  164. # labels:
  165. # - logging-infra: 'support'
  166. ports:
  167. - port: 9200
  168. targetPort: "restapi"
  169. - name: Creating ES storage template
  170. template:
  171. src: pvc.j2
  172. dest: "{{ tempdir }}/templates/logging-es-pvc.yml"
  173. vars:
  174. obj_name: "{{ openshift_logging_elasticsearch_pvc_name }}"
  175. size: "{{ openshift_logging_elasticsearch_pvc_size }}"
  176. access_modes: "{{ openshift_logging_elasticsearch_pvc_access_modes | list }}"
  177. pv_selector: "{{ openshift_logging_elasticsearch_pvc_pv_selector }}"
  178. when:
  179. - openshift_logging_elasticsearch_storage_type == "pvc"
  180. - not openshift_logging_elasticsearch_pvc_dynamic
  181. - name: Creating ES storage template
  182. template:
  183. src: pvc.j2
  184. dest: "{{ tempdir }}/templates/logging-es-pvc.yml"
  185. vars:
  186. obj_name: "{{ openshift_logging_elasticsearch_pvc_name }}"
  187. size: "{{ openshift_logging_elasticsearch_pvc_size }}"
  188. access_modes: "{{ openshift_logging_elasticsearch_pvc_access_modes | list }}"
  189. pv_selector: "{{ openshift_logging_elasticsearch_pvc_pv_selector }}"
  190. annotations:
  191. volume.alpha.kubernetes.io/storage-class: "dynamic"
  192. when:
  193. - openshift_logging_elasticsearch_storage_type == "pvc"
  194. - openshift_logging_elasticsearch_pvc_dynamic
  195. - name: Set ES storage
  196. oc_obj:
  197. state: present
  198. kind: pvc
  199. name: "{{ openshift_logging_elasticsearch_pvc_name }}"
  200. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  201. files:
  202. - "{{ tempdir }}/templates/logging-es-pvc.yml"
  203. delete_after: true
  204. when:
  205. - openshift_logging_elasticsearch_storage_type == "pvc"
  206. - set_fact:
  207. es_deploy_name: "logging-{{ es_component }}-{{ openshift_logging_elasticsearch_deployment_type }}-{{ 'abcdefghijklmnopqrstuvwxyz0123456789' | random_word(8) }}"
  208. when: openshift_logging_elasticsearch_deployment_name == ""
  209. - set_fact:
  210. es_deploy_name: "{{ openshift_logging_elasticsearch_deployment_name }}"
  211. when: openshift_logging_elasticsearch_deployment_name != ""
  212. # DC
  213. - name: Set ES dc templates
  214. template:
  215. src: es.j2
  216. dest: "{{ tempdir }}/templates/logging-es-dc.yml"
  217. vars:
  218. es_cluster_name: "{{ es_component }}"
  219. component: "{{ es_component }}"
  220. logging_component: elasticsearch
  221. deploy_name: "{{ es_deploy_name }}"
  222. image: "{{ openshift_logging_image_prefix }}logging-elasticsearch:{{ openshift_logging_image_version }}"
  223. es_cpu_limit: "{{ openshift_logging_elasticsearch_cpu_limit }}"
  224. es_memory_limit: "{{ openshift_logging_elasticsearch_memory_limit }}"
  225. es_node_selector: "{{ openshift_logging_elasticsearch_nodeselector | default({}) }}"
  226. deploy_type: "{{ openshift_logging_elasticsearch_deployment_type }}"
  227. - name: Set ES dc
  228. oc_obj:
  229. state: present
  230. name: "{{ es_deploy_name }}"
  231. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  232. kind: dc
  233. files:
  234. - "{{ tempdir }}/templates/logging-es-dc.yml"
  235. delete_after: true
  236. # scale up
  237. - name: Start Elasticsearch
  238. oc_scale:
  239. kind: dc
  240. name: "{{ es_deploy_name }}"
  241. namespace: "{{ openshift_logging_elasticsearch_namespace }}"
  242. replicas: 1
  243. ## Placeholder for migration when necessary ##
  244. - name: Delete temp directory
  245. file:
  246. name: "{{ tempdir }}"
  247. state: absent
  248. changed_when: False