---
- name: Install Elasticsearch
  apt:
    name: elasticsearch
    state: present

- name: Setup Elasticsearch
  template:
    src: elasticsearch.yml
    dest: /etc/elasticsearch/elasticsearch.yml

- name: Restart Elasticsearch Daemon
  systemd:
    name: elasticsearch
    daemon_reload: true
    enabled: yes
    state: restarted

- name: Setup Elasticsearch Authentication
  become: yes
  become_user: jingrow
  command: "htpasswd -Bbc /home/jingrow/agent/nginx/kibana.htpasswd jingrow {{ kibana_password }}"

- name: Setup NGINX for Elasticsearch
  become: yes
  become_user: jingrow
  command: /home/jingrow/agent/env/bin/agent setup log
  args:
    chdir: /home/jingrow/agent
