forked from aerospike-community/aerospike-ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaerospike-monitoring-setup.yml
197 lines (174 loc) · 6.02 KB
/
aerospike-monitoring-setup.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
---
- name: Create monitoring instance
hosts: local
connection: local
gather_facts: yes
vars:
instance_tag: "{{ monitoring_tag }}"
instance_function: monitoring
# Doesn't make a lot of sense to have more than one monitoring instance, but if you want you can do it
# by changing the parameters below
instance_count: 1
az_list:
- "{{ cluster_az_list[0] }}"
instance_type: "{{ monitoring_instance_type }}"
tasks:
- name: Import configuration properties
include_vars:
dir: vars
- name: "Setup {{ instance_function }} instance vars"
include_vars: modules/instance-setup-vars.yml
- name: "Setup {{ instance_function }} instances"
import_tasks: modules/instance-setup.yml
- name: Set up Prometheus / Grafana
hosts: "{{ monitoring_tag }}"
gather_facts: true
become: yes
remote_user: "{{ os_config['remote_user'] }}"
vars_files:
- vars/cluster-config.yml
- vars/constants.yml
- vars/os-level-config.yml
tasks:
- name: Get service facts
service_facts:
- name: Import configuration properties
include_vars:
dir: vars
# When Prometheus is installed, we update the config file - might be necessary as we have added nodes
- import_tasks: modules/prometheus-configuration.yml
when: hostvars[inventory_hostname].services[prometheus_service_name] is defined
# When Prometheus is *not* installed, do the full install
- block:
- name: Some magic to help us install grafana on amzn linux
shell: |
set -e
curl --silent --location https://rpm.nodesource.com/setup_14.x | sudo bash -
curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
rpm --import https://dl.yarnpkg.com/rpm/pubkey.gpg
cat <<EOF | sudo tee /etc/yum.repos.d/grafana.repo
[grafana]
name=grafana
baseurl=https://packages.grafana.com/oss/rpm
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://packages.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
EOF
when: operating_system == amzn_linux_os
- name: If Ubuntu, update package cache & do some specifics to install yarn
shell: |
set -e
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update
when: operating_system == ubuntu_os
- name: Install go/make/git/nodejs
package:
name:
- "{{ os_config['go_package_name'] }}"
- make
- git
- nodejs
- yarn
state: latest
become: yes
- name: Install grafana (Ubuntu)
shell: |
set -e
sudo apt-get install -y apt-transport-https
sudo apt-get install -y software-properties-common wget
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
sudo apt-get update
sudo apt-get install -y grafana
when: operating_system == ubuntu_os
- name: Install grafana (Amzn Linux)
package:
name:
- grafana
state: latest
become: yes
when: operating_system == amzn_linux_os
- name: Set up prometheus config directory
file:
path: "{{ prometheus_config_directory }}"
state: directory
owner: root
group: root
mode: 0555
- import_tasks: modules/prometheus-configuration.yml
- name: Add Prometheus systemd file
copy:
src: "assets/systemd/prometheus.service"
dest: "/usr/lib/systemd/system/prometheus.service"
owner: root
group: root
mode: 0644
- name: Install and start Prometheus
shell: |
wget https://github.com/prometheus/prometheus/releases/download/v2.14.0/prometheus-2.14.0.linux-amd64.tar.gz -P /tmp
cd /tmp
tar -zxpvf prometheus-2.14.0.linux-amd64.tar.gz
cp prometheus-2.14.0.linux-amd64/prometheus /usr/local/bin
mkdir /var/lib/prometheus
grafana-cli plugins install camptocamp-prometheus-alertmanager-datasource
sysctl vm.max_map_count=131072
systemctl daemon-reload
become: yes
when: hostvars[inventory_hostname].services[prometheus_service_name] is not defined
- name: Get dashboards
git:
clone: "yes"
dest: "{{ ansible_env.HOME }}/aerospike-monitoring"
repo: "https://github.com/aerospike/aerospike-monitoring.git"
- name: Configure Grafana
shell: |
set -e
sed -i 's!^;provisioning.*$!provisioning = /etc/grafana/provisioning!' /etc/grafana/grafana.ini
sed -i 's!^.*http_port.*$!http_port = {{ grafana_port }}!' /etc/grafana/grafana.ini
become: yes
- name: Add Grafana configuration files
copy:
src: "{{ item }}"
dest: "/etc/grafana/provisioning"
directory_mode: 0755
owner: root
group: root
mode: 0755
loop:
- "assets/grafana/dashboards"
- "assets/grafana/datasources"
- name: Add Aerospike dashboards
copy:
src: "{{ ansible_env.HOME }}/aerospike-monitoring/config/grafana/dashboards"
remote_src: yes
dest: "/var/lib/grafana"
directory_mode: 0755
owner: root
group: root
mode: 0755
- name: Add Summit Demo dashboards
copy:
src: "assets/grafana/summit-demo/{{ item }}"
dest: "/var/lib/grafana/dashboards"
owner: root
group: root
mode: 0777
loop:
- Summit-Talk-01.json
- Summit-Talk-02.json
- Summit-Talk-03.json
- name: Start prometheus, if not started
service:
name: prometheus
state: restarted
- name: Start grafana, if not started
service:
name: grafana-server
state: restarted
- name: "Grafana dashboard available at http://{{ inventory_hostname }}:{{ grafana_port }}"
debug:
msg: "Success!!!"