|
| 1 | +# |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | +# contributor license agreements. See the NOTICE file distributed with |
| 4 | +# this work for additional information regarding copyright ownership. |
| 5 | +# The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | +# (the "License"); you may not use this file except in compliance with |
| 7 | +# the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | +--- |
| 18 | +# This role will run a ElasticSearch server on the db group |
| 19 | + |
| 20 | +- name: set the vm.max_map_count to 262144 |
| 21 | + sysctl: |
| 22 | + name: vm.max_map_count |
| 23 | + value: '262144' |
| 24 | + become: true |
| 25 | + |
| 26 | +- name: set elasticsearch container name, volume and port |
| 27 | + set_fact: |
| 28 | + elasticsearch_name: "{{ name_prefix ~ host_group.index(inventory_hostname) }}" |
| 29 | + volume_name: "{{ db.elasticsearch.base_volume ~ host_group.index(inventory_hostname) }}" |
| 30 | + http_port: "{{ (db.elasticsearch.port|int) + host_group.index(inventory_hostname) }}" |
| 31 | + transport_port: "{{ (db.elasticsearch.base_transport_port|int) + host_group.index(inventory_hostname) }}" |
| 32 | + |
| 33 | +- name: ensure elasticserach config directory is created with permissions |
| 34 | + file: |
| 35 | + path: "{{ db.elasticsearch.confdir }}/{{ elasticsearch_name }}" |
| 36 | + state: directory |
| 37 | + mode: 0755 |
| 38 | + become: "{{ db.elasticsearch.dir.become }}" |
| 39 | + |
| 40 | +# create volume direcotry if it's a directory path(not a named volume) |
| 41 | +- name: ensure elasticserach volume directory is created with permissions |
| 42 | + file: |
| 43 | + path: "{{ volume_name }}" |
| 44 | + state: directory |
| 45 | + mode: 0700 |
| 46 | + owner: "{{ db.elasticsearch.uid }}" |
| 47 | + become: true |
| 48 | + when: volume_name is search("/") |
| 49 | + |
| 50 | +- name: copy elasticsearch config file |
| 51 | + template: |
| 52 | + src: "elasticsearch.yml.j2" |
| 53 | + dest: "{{ db.elasticsearch.confdir }}/{{ elasticsearch_name }}/elasticsearch.yml" |
| 54 | + mode: 0644 |
| 55 | + become: "{{ db.elasticsearch.dir.become }}" |
| 56 | + |
| 57 | +- name: copy elasticsearch log config file |
| 58 | + template: |
| 59 | + src: "log4j2.properties.j2" |
| 60 | + dest: "{{ db.elasticsearch.confdir }}/{{ elasticsearch_name }}/log4j2.properties" |
| 61 | + mode: 0644 |
| 62 | + become: "{{ db.elasticsearch.dir.become }}" |
| 63 | + |
| 64 | +- name: "(re)start ElasticSearch from '{{ elasticsearch_image }} ' " |
| 65 | + vars: |
| 66 | + elasticsearch_image: "{{ elasticsearch.docker_image | default('docker.elastic.co/elasticsearch/elasticsearch:' ~ elasticsearch.version ) }}" |
| 67 | + docker_container: |
| 68 | + name: "{{ elasticsearch_name }}" |
| 69 | + image: "{{ elasticsearch_image }}" |
| 70 | + state: started |
| 71 | + recreate: true |
| 72 | + restart_policy: "{{ docker.restart.policy }}" |
| 73 | + ports: |
| 74 | + - "{{ http_port }}:9200" |
| 75 | + - "{{ transport_port }}:{{ transport_port }}" |
| 76 | + volumes: |
| 77 | + - "{{ db.elasticsearch.confdir }}/{{ elasticsearch_name }}/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml" |
| 78 | + - "{{ db.elasticsearch.confdir }}/{{ elasticsearch_name }}/log4j2.properties:/usr/share/elasticsearch/config/log4j2.properties" |
| 79 | + - "{{ volume_name }}:/usr/share/elasticsearch/data" |
| 80 | + pull: "{{ docker.pull_elasticsearch | default(true) }}" |
| 81 | + ulimits: |
| 82 | + - "nofile:262144:262144" |
| 83 | + - "memlock:-1:-1" |
| 84 | + env: |
| 85 | + TZ: "{{ docker.timezone }}" |
| 86 | + ES_JAVA_OPTS: "{{ db.elasticsearch.java_opts }}" |
| 87 | + |
| 88 | +- name: wait until ElasticSearch in this host is up and running |
| 89 | + uri: |
| 90 | + url: "{{ db.elasticsearch.protocol }}://{{ ansible_host }}:{{ http_port }}" |
| 91 | + register: result |
| 92 | + until: result.status == 200 |
| 93 | + retries: 12 |
| 94 | + delay: 5 |
0 commit comments