---
# file: roles/elastalert/tasks/install.yml

- name: Install Alerta Pip Package
  pip:
    name: elastalert
    state: present

- name: Ensure elastalert user
  user:
    name: elastalert
    groups: adm,root
    append: yes

- name: Ensure ElastAlert Directories
  file:
    dest: /opt/elastalert/{{ item }}
    state: directory
  with_items:
    - config
    - rules

- name: Copy config files
  template:
    src: '{{ item }}'
    dest: /opt/elastalert/config/{{ item }}
    owner: root
    group: root
    mode: 0644
  with_items:
    - config.json
    - elastalert.yaml
    - elastalert-test.yaml
  tags:
    - Config

- name: Copy startup script
  template:
    src: elastalert
    dest: /etc/init.d/elastalert
    owner: root
    group: root
    mode: 0755
  notify:
    - Add elastalert to autostart

- name: Configure Logrotate
  template:
    src: logrotate
    dest: /etc/logrotate.d/elastalert
    owner: root
    group: root
    mode: 0644
