summaryrefslogtreecommitdiffstats
path: root/roles/prometheus/tasks/main.yml
blob: 1f639c6d9480295f63a3ad0c436610c7bc7831c4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
---
- name: "Include OS-specific variables"
  ansible.builtin.include_vars: "{{ ansible_facts['os_family'] | lower }}.yml"

- name: "Create prometheus group"
  become: true
  ansible.builtin.group:
    name: "prometheus"
    system: true

- name: "Create prometheus user"
  become: true
  ansible.builtin.user:
    name: "prometheus"
    group: "prometheus"
    system: true
    shell: "/usr/sbin/nologin"
    create_home: false

- name: "Create prometheus directories"
  become: true
  ansible.builtin.file:
    path: "{{ item }}"
    state: "directory"
    owner: "prometheus"
    group: "prometheus"
    mode: "0755"
  loop:
    - "/etc/prometheus"
    - "/var/lib/prometheus"

- name: "Install prometheus"
  become: true
  ansible.builtin.package:
    name: "prometheus"
    state: "present"

- name: "Create prometheus configuration"
  become: true
  ansible.builtin.template:
    src: "prometheus.yml.j2"
    dest: "/etc/prometheus/prometheus.yml"
    owner: "prometheus"
    group: "prometheus"
    mode: "0644"
  notify: "Restart prometheus"

# NOTE: show systemd configurations using: systemctl cat prometheus
- name: "Configure prometheus host/port via environment file"
  become: true
  ansible.builtin.copy:
    content: |
      PROMETHEUS_ARGS="--web.listen-address={{ prometheus_host }}:{{ prometheus_port }}"
    dest: "{{ prometheus_env_file }}"
    mode: "0644"
  notify: "Restart prometheus"

- name: "Start and enable prometheus"
  become: true
  ansible.builtin.systemd_service:
    name: "prometheus"
    state: "started"
    enabled: true