-
Notifications
You must be signed in to change notification settings - Fork 4
/
manage_harvest.yml
218 lines (199 loc) · 5.73 KB
/
manage_harvest.yml
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
---
- hosts: localhost
name: Manage Harvest
vars:
default_harvest_image: ghcr.io/netapp/harvest:latest
default_prom_image: prom/prometheus:v2.33.1
default_grafana_image: grafana/grafana:8.3.4
default_alertmanger_image: prom/alertmanager
vars_files:
harvest/harvest.yml
collections:
- ansible.builtin
- community.docker
tasks:
- name: Verify images
docker_image:
name: "{{ item }}"
source: pull
loop:
- "{{ default_harvest_image }}"
- "{{ default_prom_image }}"
- "{{ default_grafana_image }}"
- "{{ default_alertmanger_image }}"
tags: setup
- name: Configure/Verify Prometheus targets
lineinfile:
path: ./prometheus/prometheus.yml
line: " - targets: ['harvest_{{ item }}:{{Pollers[item].ansible_port}}']"
loop: "{{ Pollers|list }}"
- name: Create Harvest Network
docker_network:
name: harvest
tags: setup
- name: Create Prometheus storage
docker_volume:
name: prometheus_data
- name: Setup/Verify Prometheus
docker_container:
name: harvest_prometheus
image: "{{ default_prom_image }}"
restart: true
restart_policy: unless-stopped
volumes:
- prometheus_data:/prometheus
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
- ./prometheus/alert.rules.yml:/etc/prometheus/alert.rules.yml
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.retention.time=1y'
ports: "9090:9090"
networks:
- name: harvest
tags: setup
- name: Setup/Verify Prometheus AlertManager
docker_container:
name: harvest_prometheus_alertmanager
image: prom/alertmanager
restart: true
restart_policy: unless-stopped
volumes:
- prometheus_data:/prometheus
- ./prometheus_alertmanager/alertmanager.yml:/etc/prometheus/alertmanager.yml
command:
- '--config.file=/etc/prometheus/alertmanager.yml'
ports: "9093:9093"
networks:
- name: harvest
tags: setup
- name: Setup/verify Grafana
docker_container:
name: harvest_grafana
image: "{{ default_grafana_image }}"
restart_policy: unless-stopped
env:
GF_SECURITY_ADMIN_PASSWORD=pass
ports:
- "3000:3000"
networks:
- name: harvest
tags: setup
- name: Setup/verify Harvest pollers
docker_container:
name: "harvest_{{ item }}"
image: "{{ default_harvest_image }}"
restart_policy: unless-stopped
volumes:
- ./harvest/:/etc/harvest/
- ./myconf/:/opt/harvest/myconf
command:
- --config
- /etc/harvest/harvest.yml
- -p
- "{{ item }}"
- --promPort
- "{{ Pollers[item].ansible_port }}"
- --confpath
- myconf:conf
networks:
- name: harvest
detach: true
loop: "{{ Pollers|list}}"
tags: setup
- name: Create bearer token
uri:
url: "http://{{ansible_default_ipv4.address}}:3000/api/auth/keys"
force_basic_auth: true
method: POST
user: admin
password: pass
headers:
Content-Type: application/json
body: '{"name": "apikeycurl", "role": "Admin"}'
register: login
tags: never, api
- name: Creating Prometheus datasource in Grafana
uri:
url: "http://{{ansible_default_ipv4.address}}:3000/api/datasources"
method: POST
headers:
Content-Type: application/json
Authorization: "Bearer {{ login.json.key }}"
body: '{"name": "Prometheus", "type": "prometheus", "access": "proxy", "url": "http://harvest_prometheus:9090", "isDefault": true, "basicAuth": false}'
tags: never, api
- name: Prep Grafana dashboard load
lineinfile:
path: ./harvest/harvest.yml
insertafter: '^Tools:'
regexp: ' grafana_api_token:'
line: ' grafana_api_token: {{ login.json.key }}'
tags: never, api
- name: Add Dashboards to Grafana
docker_container_exec:
container: "harvest_{{ Pollers|first }}"
command: sh -c "bin/harvest grafana import -a harvest_grafana:3000 --config /etc/harvest/harvest.yml"
tags: never, api, dashboard
- name: Stop Prometheus
docker_container:
name: harvest_prometheus
image: prom/prometheus
state: stopped
tags: never, stop
- name: Stop Grafana
docker_container:
name: harvest_grafana
image: "{{ default_grafana_image }}"
state: stopped
tags: never, stop
- name: Stop Harvest pollers
docker_container:
name: "harvest_{{ item }}"
image: "{{ default_harvest_image }}"
state: stopped
detach: true
loop: "{{ Pollers|list}}"
tags: never, stop
- name: Remove Prometheus
docker_container:
name: harvest_prometheus
state: absent
tags: never, del
- name: Remove Grafana
docker_container:
name: harvest_grafana
state: absent
tags: never, del
- name: Remove Harvest pollers
docker_container:
name: "harvest_{{ item }}"
state: absent
loop: "{{ Pollers|list}}"
tags: never, del, upgrade
- name: update images
docker_image:
name: "{{ default_harvest_image }}"
force_source: true
source: pull
tags: never, upgrade
- name: Update Harvest pollers
docker_container:
name: "harvest_{{ item }}"
image: "{{ default_harvest_image }}"
restart: true
volumes:
- ./harvest/:/etc/harvest/
- ./myconf/:/opt/harvest/myconf
command:
- --config
- /etc/harvest/harvest.yml
- -p
- "{{ item }}"
- --promPort
- "{{ Pollers[item].ansible_port }}"
- --confpath
- myconf:conf
networks:
- name: harvest
detach: true
loop: "{{ Pollers|list}}"
tags: never, upgrade