---

- name: base packages installed
  package:
    name: 
    - prometheus
    - nginx
- name: alerts directory
  file:
    state: directory
    path: /etc/prometheus/alerts
- name: prometheus template
  template:
    src: prometheus.yml.j2
    dest: /etc/prometheus/prometheus.yml
  notify: restart prometheus
  tags: prometheus_conf
- name: prometheus site template
  template:
    src: prometheus_site.j2
    dest: /etc/nginx/sites-available/prometheus
  notify: reload nginx
  tags: nginx
- name: site link
  file:
    state: link
    path: /etc/nginx/sites-enabled/prometheus
    src: ../sites-available/prometheus
  notify: reload nginx
  tags: nginx

- name: monitoring target yml files
  copy:
    force: no
    dest: '/etc/prometheus/{{item}}.yml'
    content: '- targets:'
  with_items:
    - 'lxc'
    - 'bare_metal'
    - 'postfix'
  tags: target_yml

- name: prometheus started and enabled
  service:
    name: prometheus
    state: started
    enabled: yes


- name: core alerts
  copy:
    src: core_alerts.yml
    dest: /etc/prometheus/alerts/core.yml
  tags: alerts