aboutsummaryrefslogtreecommitdiff
path: root/tasks/main.yml
blob: 19ca131a31a7fa252d108b8d3e102bf78ba630e2 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
- name: Setup Prometheus User
  user:
    name: "{{prometheus_user}}"
    home: "{{prometheus_home_dir}}"
    state: present
- set_fact: "prometheus_extract_dir=prometheus-{{prometheus_version}}.{{prometheus_os}}-{{prometheus_architecture}}"
- name: Create configuration directory
  file:
    state: directory
    dest: "{{prometheus_home_dir}}/conf"
    mode: '0700'
    owner: "{{prometheus_user}}"
- name: Create Data directory
  file:
    state: directory
    dest: "{{prometheus_data_dir}}"
    mode: '0700'
    owner: "{{prometheus_user}}"
- name: Download Prometheus
  get_url:
    url: "{{prometheus_url}}"
    dest: "{{prometheus_home_dir}}/prometheus-{{prometheus_version}}.tgz"
    mode: '0600'
    owner: "{{prometheus_user}}"
    checksum: 'sha256:{{prometheus_checksum}}'
# There's a bug  in become_user that doesn't set permissions on the temp directory
# which is asinine when my user has sudo persmissions.
- name: Extract Prometheus
  shell: |
    #!/bin/sh
    set -e
    if ! [ -e "{{prometheus_home_dir}}/{{prometheus_extract_dir}}" ] ; then
      su - '{{prometheus_user}}' -c 'tar xzf prometheus-{{prometheus_version}}.tgz'
      exit 50
    fi
  register: res
  changed_when: res is defined and res.rc == 50
  ignore_errors: true
  notify: Restart Prometheus
- name: Link prometheus directory
  file:
    state: link
    src: '{{prometheus_extract_dir}}'
    dest: '{{prometheus_home_dir}}/prometheus'
    force: yes
- name: Link configuration files
  file:
    state: link
    src: '../conf/{{item}}'
    dest: '{{prometheus_home_dir}}/prometheus/{{item}}'
    force: yes
  loop:
    - prometheus.yml
- name: Write prometheus configuration file
  copy:
    content: '{{prometheus_config | to_nice_yaml}}'
    dest: '{{prometheus_home_dir}}/conf/prometheus.yml'
    owner: '{{prometheus_user}}'
    mode: '0600'
  notify: Restart prometheus
  tags:
    - configuration
- name: Create Runit Directory
  file:
    state: directory
    dest: /etc/sv/prometheus
    owner: root
    mode: '0755'
- name: Write runit service
  template:
    src: prometheus.runit
    dest: /etc/sv/prometheus/run
    owner: root
    mode: '0755'
- name: Enable Runit service
  file:
    state: link
    src: /etc/sv/prometheus
    dest: /var/service/prometheus
- name: Include Aertmanager tasks
  include_tasks:
    file: alertmanager.yml
    apply:
      tags:
        - alertmanager
  tags:
    - alertmanager
  when: alertmanager