---
# tasks file for elasticsearch
# include the distro-specific stuff
- include: debian.yml
  when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'
#
- include: rhel.yml
  when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux'

- name: Start Elasticsearch Service
  service: name=elasticsearch state=running enabled=yes

- name: Format the extra file storage
  filesystem:
    fstype: ext4
    dev: /dev/xvdl

- name: Mount the extra storage
  mount:
    name: /var/lib/elasticsearch
    src: /dev/xvdl1
    fstype: ext4
    state: present

- name: Copy the elasticsearch config into place
  template: src=elasticsearch.yml dest=/etc/elasticsearch/elasticsearch.yml
  notify: restart_elasticsearch

- name: Register with Consul
  consul:
      service_name: elasticsearch
      service_port: 9200
  when: consul_enabled and consul_enabled == True

- name: Enable the relevant plugins
  command: "/usr/share/elasticsearch/bin/elasticsearch-plugin install --batch {{ item }}"
  with_items:
    - x-pack
  ignore_errors: true

- name: Enable traffic for all inbound connections
  firewalld:
    port: 9200-9305/tcp
    permanent: true
    state: enabled
    immediate: true

---
# tasks file for elasticsearch
# include the distro-specific stuff
- include: debian.yml
  when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'
#
- include: rhel.yml
  when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux'

- name: Start Elasticsearch Service
  service: name=elasticsearch state=running enabled=yes

- name: Format the extra file storage
  filesystem:
    fstype: ext4
    dev: /dev/xvdl

- name: Mount the extra storage
  mount:
    name: /var/lib/elasticsearch
    src: /dev/xvdl1
    fstype: ext4
    state: present

- name: Copy the elasticsearch config into place
  template: src=elasticsearch.yml dest=/etc/elasticsearch/elasticsearch.yml
  notify: restart_elasticsearch

- name: Register with Consul
  consul:
      service_name: elasticsearch
      service_port: 9200
  when: consul_enabled and consul_enabled == True

- name: Enable the relevant plugins
  command: "/usr/share/elasticsearch/bin/elasticsearch-plugin install --batch {{ item }}"
  with_items:
    - x-pack
  ignore_errors: true

- name: Copy the generic system key for x-pack - CHANGE THIS FOR PRODUCTION!
  copy:
    src: system_key
    dest: /etc/elasticsearch/x-pack/system_key
    owner: elasticsearch
    group: elasticsearch
    mode: 0640
  notify: restart_elasticsearch

- name: Enable traffic for all inbound connections
  firewalld:
    port: 9200-9305/tcp
    permanent: true
    state: enabled
    immediate: true

Add the default, generic system key for Elasticsearch
Add the default, generic system key for Elasticsearch
