---
# file: roles/netdata/tasks/main.yml

- name: NetData Role
  set_fact:
    role_netdata_started: yes
  tags:
    - always

- block:

    - name: Import prepare
      import_tasks: prepare.yml

    - name: Import install
      import_tasks: install.yml
      when: netdata_force_reset

    - name: Import configure
      import_tasks: configure.yml

    #- name: Import apache
    #  import_tasks: apache.yml
    #  when: groups['webserver'] is defined and inventory_hostname in groups['webserver']

    - name: Import elasticsearch
      import_tasks: elasticsearch.yml
      when: groups['logserver'] is defined and inventory_hostname in groups['logserver'] and elasticsearch_install|default(yes)

    - name: Import haproxy
      import_tasks: haproxy.yml
      when: groups['proxyserver'] is defined and inventory_hostname in groups['proxyserver']

    - name: Import silent
      import_tasks: silent.yml

    - name: Import varnish
      import_tasks: varnish.yml
      when: groups['varnishserver'] is defined and inventory_hostname in groups['varnishserver']

    - name: Import heartbeat
      import_tasks: heartbeat.yml
      when: netdata_heartbeat|default(true)

    - name: Set ownership
      file:
        path: /opt/netdata/etc/netdata
        owner: netdata
        group: netdata
        recurse: yes
        follow: no

  when: not excluded_roles or "netdata" not in excluded_roles
