---
# tasks file for ansible-elasticsearch

- name: Add apt repo key
  apt_key:
    url: https://packages.elastic.co/GPG-KEY-elasticsearch
    state: present

- name: Add apt repo
  apt_repository:
    repo: deb http://packages.elastic.co/elasticsearch/2.x/debian stable main
    state: present
    update_cache: yes

- name: apt install
  with_items:
  - openjdk-7-jre-headless
  - elasticsearch
  apt:
    name: '{{ item }}'
    state: present
    update_cache: yes
    cache_valid_time: 3600

- name: Set Java options
  lineinfile:
    dest: /etc/default/elasticsearch
    line: "ES_JAVA_OPTS='-Djava.net.preferIPv4Stack=true'"
    regexp: '^ES_JAVA_OPTS='
    state: present
  notify:
  - Restart Elasticsearch

- name: Copy configutation template
  template:
    src: elasticsearch.yml.j2
    dest: /etc/elasticsearch/elasticsearch.yml
    owner: root
    group: root
    mode: '0644'
  notify:
  - Restart Elasticsearch

- name: Enable, start Elasticsearch service
  service:
    name: elasticsearch
    state: started
    enabled: yes
