---
- name: install apt-transport-https
  apt:
    name: apt-transport-https
    state: latest

- name: install elastic GPG key
  apt_key:
    url: https://artifacts.elastic.co/GPG-KEY-elasticsearch
    state: present

- name: install elastic repository
  apt_repository:
    repo: deb https://artifacts.elastic.co/packages/7.x/apt stable main

- name: install metricbeat
  apt:
    name: metricbeat
    state: latest

- name: install metricbeat configuration
  template:
    src: metricbeat.yml.j2
    dest: /etc/metricbeat/metricbeat.yml
  notify: restart metricbeat

- name: enable metricbeat dashboard
  command: metricbeat setup
  when: inventory_hostname == groups['mediaserver'][0]

- name: enable sql metricbeat configuration
  template:
    src: postgresql.yml.j2
    dest: /etc/metricbeat/modules.d/postgresql.yml
  when: "'postgres' in group_names"
  notify: restart metricbeat

...
