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

- name: "Clone ElastAlert"
  git:
    accept_hostkey: yes
    repo: 'https://github.com/Yelp/elastalert.git'
    dest: '/opt/elastalert'
    force: yes
    version: 'master'
  notify:
    - "ElastAlert installation"
    - "Add ElastAlert to Boot-List"
    - "Restart ElastAlert"

- name: "Install PIP Components"
  pip:
    name='{{ item }}'
    state='latest'
  with_items:
    - 'pip'
    - 'setuptools'
    - 'six'
  notify:
    - "Restart ElastAlert"

- name: "Install PIP Requirements"
  pip:
    requirements='/opt/elastalert/requirements.txt'
    state='latest'
  notify:
    - "Restart ElastAlert"

- name: "Ensure Rules Directory"
  file:
    path='/opt/elastalert/my_rules'
    state='directory'
    owner='root'
    group='root'
    mode='755'

- name: "Configuration"
  template:
    src='config.yaml'
    dest='/opt/elastalert/config.yaml'
    owner='root'
    group='root'
    mode='644'
  notify:
    - "Restart ElastAlert"
