- hosts: monitor
  remote_user: ubuntu
  become: true
  gather_facts: no


  vars_files:
    - variables.yml


  tasks:


    # Heartbeat
    - name: Install Heartbeat
      apt: deb={{ elastic_download }}/downloads/beats/heartbeat/heartbeat-{{ elastic_version }}-amd64.deb

    - name: Change the Heartbeat configuration
      template: src=templates/heartbeat.yml dest=/etc/heartbeat/heartbeat.yml

    - name: Restart Heartbeat and make sure it autostarts, but stop it for now
      service: name=heartbeat state=stopped enabled=yes

    - name: Add Heartbeat dashboard
      command: /usr/share/heartbeat/scripts/import_dashboards -es {{ elasticsearch_host }} -user {{ elasticsearch_user }} -pass {{ elasticsearch_password }}


    # Httpbeat
    - name: Install Httpbeat
      apt: deb=https://github.com/christiangalsterer/httpbeat/releases/download/4.0.0/httpbeat-4.0.0-amd64.deb

    - name: Change the Httpbeat configuration
      template: src=templates/httpbeat.yml dest=/etc/httpbeat/httpbeat.yml

    - name: Restart Httpbeat and make sure it autostarts, but stop it for now
      service: name=httpbeat state=stopped enabled=yes

- hosts: monitor
  remote_user: ubuntu
  become: true
  gather_facts: no


  vars_files:
    - variables.yml


  tasks:


    # Heartbeat
    - name: Purge Heartbeat since it might collide with the Linux package
      apt: name=heartbeat purge=yes

    - name: Install Heartbeat
      apt: deb={{ elastic_download }}/downloads/beats/heartbeat/heartbeat-{{ elastic_version }}-amd64.deb

    - name: Change the Heartbeat configuration
      template: src=templates/heartbeat.yml dest=/etc/heartbeat/heartbeat.yml

    - name: Restart Heartbeat and make sure it autostarts, but stop it for now
      service: name=heartbeat state=stopped enabled=yes

    - name: Add Heartbeat dashboard
      command: /usr/share/heartbeat/scripts/import_dashboards -es {{ elasticsearch_host }} -user {{ elasticsearch_user }} -pass {{ elasticsearch_password }}


    # Httpbeat
    - name: Install Httpbeat
      apt: deb=https://github.com/christiangalsterer/httpbeat/releases/download/4.0.0/httpbeat-4.0.0-amd64.deb

    - name: Change the Httpbeat configuration
      template: src=templates/httpbeat.yml dest=/etc/httpbeat/httpbeat.yml

    - name: Restart Httpbeat and make sure it autostarts, but stop it for now
      service: name=httpbeat state=stopped enabled=yes

FIX avoid name collision on the Heartbeat package name by purging
FIX avoid name collision on the Heartbeat package name by purging
