---
- name: Install JRE
  yum: pkg=jre state=installed

- name: Add Elasticsearch GPG key.
  rpm_key:
    key: http://packages.elasticsearch.org/GPG-KEY-elasticsearch
    state: present

- name: Add Elasticsearch repository.
  copy:
    src: elasticsearch.repo
    dest: /etc/yum.repos.d/elasticsearch.repo
    mode: 0644

- name: Install Elasticsearch.
  yum: pkg=elasticsearch state=installed

- name: Removing Plugins if they exist
  action: >
    shell bin/plugin remove {{ item.shortname }}
    chdir={{ elasticsearch_home_dir }}
  with_items: elasticsearch_plugins
  ignore_errors: yes

- name: Installing Plugins
  action: >
    shell bin/plugin install {{ item.name }}
    chdir={{ elasticsearch_home_dir }}
  with_items: elasticsearch_plugins
  ignore_errors: yes

- name: Configure Elasticsearch.
  lineinfile: >
    dest=/etc/elasticsearch/elasticsearch.yml
    regexp="{{ item.regexp }}"
    line="{{ item.line }}"
    state=present
  with_items:
    - { regexp: 'network\.host', line: 'network.host: 0.0.0.0' }
    - { regexp: 'node\.name', line: 'node.name: node-1' }
  notify: restart elasticsearch

- name: Start Elasticsearch.
  service: name=elasticsearch state=started enabled=yes

---
- name: Install JRE
  yum: pkg=jre state=installed

- name: Add Elasticsearch GPG key.
  rpm_key:
    key: http://packages.elasticsearch.org/GPG-KEY-elasticsearch
    state: present

- name: Add Elasticsearch repository.
  copy:
    src: elasticsearch.repo
    dest: /etc/yum.repos.d/elasticsearch.repo
    mode: 0644

- name: Install Elasticsearch.
  yum: pkg=elasticsearch state=installed

- name: Removing Plugins if they exist
  action: >
    shell bin/plugin remove {{ item.shortname }}
    chdir={{ elasticsearch_home_dir }}
  with_items: "{{ elasticsearch_plugins }}"
  ignore_errors: yes

- name: Installing Plugins
  action: >
    shell bin/plugin install {{ item.name }}
    chdir={{ elasticsearch_home_dir }}
  with_items: "{{ elasticsearch_plugins }}"
  ignore_errors: yes

- name: Configure Elasticsearch.
  lineinfile: >
    dest=/etc/elasticsearch/elasticsearch.yml
    regexp="{{ item.regexp }}"
    line="{{ item.line }}"
    state=present
  with_items:
    - { regexp: 'network\.host', line: 'network.host: 0.0.0.0' }
    - { regexp: 'node\.name', line: 'node.name: node-1' }
  notify: restart elasticsearch

- name: Start Elasticsearch.
  service: name=elasticsearch state=started enabled=yes

Fix with_items variable syntax in ES role for ansible 2.2.x compatibility.
Fix with_items variable syntax in ES role for ansible 2.2.x compatibility.
