-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprometheus.yaml
128 lines (112 loc) · 3.48 KB
/
prometheus.yaml
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
- hosts: all
become: true
vars:
packages:
download_url: https://github.com/prometheus/prometheus/releases/download/v2.45.0/prometheus-2.45.0.linux-amd64.tar.gz
package_name: prometheus-2.45.0.linux-amd64.tar.gz
temp_dir: /tmp
config_dir: /etc/prometheus
data_dir: /var/lib/prometheus
tasks:
- name: Download Prometheus
get_url:
url: "{{ packages.download_url }}"
dest: "{{ temp_dir }}/{{ packages.package_name }}"
- name: Extract Prometheus
unarchive:
src: "{{ temp_dir }}/{{ packages.package_name }}"
dest: "{{ temp_dir }}"
remote_src: yes
- name: Create prometheus group
group:
name: prometheus
state: present
- name: Create prometheus user
user:
name: prometheus
group: prometheus
shell: /sbin/nologin
system: yes
createhome: no
- name: Create Config and Data Directory
file:
path: "{{ config_dir }}"
state: directory
- name: Create Config and Data Directory
file:
path: "{{ data_dir }}"
owner: prometheus
group: prometheus
state: directory
- name: Copy Prometheus Binary Files
copy:
src: "{{ item }}"
dest: /usr/local/bin
owner: root
mode: "0755"
group: root
remote_src: yes
with_items:
- "{{ temp_dir }}/prometheus-2.45.0.linux-amd64/prometheus"
- "{{ temp_dir }}/prometheus-2.45.0.linux-amd64/promtool"
- name: Copy Prometheus Files
copy:
src: "{{ item }}"
dest: "{{ config_dir }}"
owner: root
group: root
remote_src: yes
with_items:
- "{{ temp_dir }}/prometheus-2.45.0.linux-amd64/consoles"
- "{{ temp_dir }}/prometheus-2.45.0.linux-amd64/console_libraries"
- name: Creating Prometheus Config
copy:
dest: "/etc/prometheus/prometheus.yml"
content: |
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
- job_name: "node-exporter"
static_configs:
- targets: ["localhost:9090"]
- name: Creating Prometheus Service Daemon
copy:
dest: "/etc/systemd/system/prometheus.service"
content: |
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/bin/prometheus \
--config.file /etc/prometheus/prometheus.yml \
--storage.tsdb.path /var/lib/prometheus/ \
--web.console.templates=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries
[Install]
WantedBy=multi-user.target
- name: Daemon Reload
systemd:
name: prometheus
state: reloaded
- name: Start Prometheus Service
systemd:
name: prometheus
state: started
enabled: yes
- name: Clean Temporary Directory
file:
path: "{{ item }}"
state: absent
force: yes
with_items:
- "{{ temp_dir }}/prometheus-2.45.0.linux-amd64"
- "{{ temp_dir }}/{{ packages.package_name }}"