blob: 34c42f015589958b67764286598fe2b780315a95 [file] [log] [blame]
Oleksii Butenkoffc09222018-09-21 12:37:16 +03001{# Collection of sl macroses #}
2
3{%- macro MACRO_INSTALL_DOCKER_SWARM() %}
4# Install docker swarm
5- description: Configure docker service
6 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@docker:swarm' state.sls docker.host
7 node_name: {{ HOSTNAME_CFG01 }}
8 retry: {count: 1, delay: 10}
9 skip_fail: false
10
11- description: Install docker swarm on master node
12 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@docker:swarm:role:master' state.sls docker.swarm
13 node_name: {{ HOSTNAME_CFG01 }}
14 retry: {count: 1, delay: 10}
15 skip_fail: false
16
17- description: Send grains to the swarm slave nodes
18 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@docker:swarm' state.sls salt.minion.grains
19 node_name: {{ HOSTNAME_CFG01 }}
20 retry: {count: 1, delay: 10}
21 skip_fail: false
22
23- description: Update mine
24 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@docker:swarm' mine.update
25 node_name: {{ HOSTNAME_CFG01 }}
26 retry: {count: 1, delay: 10}
27 skip_fail: false
28
29- description: Refresh modules
30 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@docker:swarm' saltutil.refresh_modules; sleep 5;
31 node_name: {{ HOSTNAME_CFG01 }}
32 retry: {count: 1, delay: 10}
33 skip_fail: false
34
35- description: Rerun swarm on slaves to proper token population
36 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@docker:swarm:role:master' state.sls docker.swarm
37 node_name: {{ HOSTNAME_CFG01 }}
38 retry: {count: 1, delay: 10}
39 skip_fail: false
40
41- description: Configure slave nodes
42 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@docker:swarm:role:manager' state.sls docker.swarm -b 1
43 node_name: {{ HOSTNAME_CFG01 }}
44 retry: {count: 1, delay: 10}
45 skip_fail: false
46
47- description: List registered Docker swarm nodes
48 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@docker:swarm:role:master' cmd.run 'docker node ls'
49 node_name: {{ HOSTNAME_CFG01 }}
50 retry: {count: 1, delay: 10}
51 skip_fail: false
52
53- description: Install keepalived on mon nodes
54 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
55 -C 'mon*' state.sls keepalived
56 node_name: {{ HOSTNAME_CFG01 }}
57 retry: {count: 1, delay: 10}
58 skip_fail: false
59
60- description: Check the VIP on mon nodes
61 cmd: |
62 SL_VIP=`salt-call --out=newline_values_only pillar.get _param:stacklight_monitor_address`;
63 echo "_param:stacklight_monitor_address (vip): ${SL_VIP}";
64 salt --hard-crash --state-output=mixed --state-verbose=False -C 'mon*' cmd.run "ip a | grep ${SL_VIP}" | grep -B1 ${SL_VIP}
65 node_name: {{ HOSTNAME_CFG01 }}
66 retry: {count: 1, delay: 5}
67 skip_fail: false
68{%- endmacro %}
69
obutenko863a8ef2018-11-20 11:06:58 +020070#{#%- macro MACRO_INSTALL_GLUSTERFS_CLIENT() %#}
71#- description: Install glusterfs client
72# cmd: salt --hard-crash --state-output=mixed --state-verbose=False
73# -C 'I@glusterfs:client' state.sls glusterfs.client
74# node_name: {{ HOSTNAME_CFG01 }}
75# retry: {count: 2, delay: 15}
76# skip_fail: false
77#{#%- endmacro %#}
Oleksii Butenko40772422018-10-01 16:52:49 +030078
Oleksii Butenkoffc09222018-09-21 12:37:16 +030079{%- macro MACRO_INSTALL_MONGODB() %}
80# Install slv2 infra
81# Install MongoDB for alerta
82- description: Install Mongo if target matches
83 cmd: |
84 if salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@mongodb:server' match.pillar 'mongodb:server' ; then
85 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@mongodb:server' state.sls mongodb.server
86 fi
87 node_name: {{ HOSTNAME_CFG01 }}
88 retry: {count: 1, delay: 10}
89 skip_fail: false
90{%- endmacro %}
91
92{%- macro MACRO_INSTALL_MONGODB_CLUSTER() %}
93# Create MongoDB cluster
94- description: Install Mongo if target matches
95 cmd: |
96 if salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@mongodb:server' match.pillar 'mongodb:server' ; then
97 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@mongodb:server' state.sls mongodb.cluster
98 fi
99 node_name: {{ HOSTNAME_CFG01 }}
100 retry: {count: 5, delay: 20}
101 skip_fail: false
Oleksii Butenko40772422018-10-01 16:52:49 +0300102{%- endmacro %}
Oleksii Butenkoffc09222018-09-21 12:37:16 +0300103
Oleksii Butenko40772422018-10-01 16:52:49 +0300104{%- macro MACRO_INSTALL_TELEGRAF_AND_PROMETHEUS() %}
Oleksii Butenkoffc09222018-09-21 12:37:16 +0300105- description: Install telegraf
106 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@telegraf:agent or I@telegraf:remote_agent' state.sls telegraf
107 node_name: {{ HOSTNAME_CFG01 }}
108 retry: {count: 2, delay: 10}
109 skip_fail: false
110
111- description: Configure Prometheus exporters, if pillar 'prometheus:exporters' exists on any server
112 cmd: |
113 if salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@prometheus:exporters' match.pillar 'prometheus:exporters' ; then
114 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@prometheus:exporters' state.sls prometheus
115 fi
116 node_name: {{ HOSTNAME_CFG01 }}
117 retry: {count: 1, delay: 10}
118 skip_fail: false
Oleksii Butenko40772422018-10-01 16:52:49 +0300119{%- endmacro %}
120
121{%- macro MACRO_INSTALL_ELASTICSEARCH_AND_KIBANA() %}
122- description: Install elasticsearch server
123 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@elasticsearch:server:enabled:true and *01*' state.sls elasticsearch.server
124 node_name: {{ HOSTNAME_CFG01 }}
125 retry: {count: 1, delay: 10}
126 skip_fail: false
Oleksii Butenkoffc09222018-09-21 12:37:16 +0300127
128- description: Install elasticsearch server
Oleksii Butenko40772422018-10-01 16:52:49 +0300129 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@elasticsearch:server:enabled:true' state.sls elasticsearch.server
Oleksii Butenkoffc09222018-09-21 12:37:16 +0300130 node_name: {{ HOSTNAME_CFG01 }}
131 retry: {count: 1, delay: 10}
132 skip_fail: false
133
134- description: Install kibana server
Oleksii Butenko40772422018-10-01 16:52:49 +0300135 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@kibana:server:enabled:true and *01*' state.sls kibana.server
136 node_name: {{ HOSTNAME_CFG01 }}
137 retry: {count: 1, delay: 10}
138 skip_fail: false
139
140- description: Install kibana server
141 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@kibana:server:enabled:true' state.sls kibana.server
Oleksii Butenkoffc09222018-09-21 12:37:16 +0300142 node_name: {{ HOSTNAME_CFG01 }}
143 retry: {count: 1, delay: 10}
144 skip_fail: false
145
146- description: Install elasticsearch client
Oleksii Butenko40772422018-10-01 16:52:49 +0300147 cmd: sleep 30; salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@elasticsearch:client' state.sls elasticsearch.client
Oleksii Butenkoffc09222018-09-21 12:37:16 +0300148 node_name: {{ HOSTNAME_CFG01 }}
149 retry: {count: 2, delay: 30}
150 skip_fail: false
151
152- description: Install kibana client
153 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@kibana:client' state.sls kibana.client
154 node_name: {{ HOSTNAME_CFG01 }}
155 retry: {count: 1, delay: 10}
156 skip_fail: false
157
158- description: Check influix db
159 cmd: |
160 INFLUXDB_SERVICE=`salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@influxdb:server' test.ping 1>/dev/null 2>&1 && echo true`;
161 echo "Influxdb service presence: ${INFLUXDB_SERVICE}";
162 if [[ "$INFLUXDB_SERVICE" == "true" ]]; then
Oleksii Butenko40772422018-10-01 16:52:49 +0300163 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@influxdb:server and *01*' state.sls influxdb;
164 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@influxdb:server' state.sls influxdb;
Oleksii Butenkoffc09222018-09-21 12:37:16 +0300165 fi
166 node_name: {{ HOSTNAME_CFG01 }}
167 retry: {count: 1, delay: 5}
Oleksii Butenko40772422018-10-01 16:52:49 +0300168 skip_fail: false
Oleksii Butenkoffc09222018-09-21 12:37:16 +0300169{%- endmacro %}
170
171{%- macro MACRO_INSTALL_LOG_COLLECTION() %}
172# Install service for the log collection
173- description: Configure fluentd
174 cmd: |
175 FLUENTD_SERVICE=`salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@fluentd:agent' test.ping 1>/dev/null 2>&1 && echo true`;
176 echo "Fluentd service presence: ${FLUENTD_SERVICE}";
177 if [[ "$FLUENTD_SERVICE" == "true" ]]; then
178 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@fluentd:agent' state.sls fluentd
179 else
180 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@heka:log_collector' state.sls heka.log_collector
181 fi
182 node_name: {{ HOSTNAME_CFG01 }}
183 retry: {count: 1, delay: 10}
184 skip_fail: false
185{%- endmacro %}
186
187{%- macro MACRO_INSTALL_CEILOMETER_COLLECTOR() %}
188# Install heka ceilometer collector
189- description: Install heka ceilometer if they exists
190 cmd: |
191 CEILO=`salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@heka:ceilometer_collector:enabled' test.ping 1>/dev/null 2>&1 && echo true`;
192 echo "Ceilometer service presence: ${CEILO}";
193 if [[ "$CEILO" == "true" ]]; then
194 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@heka:ceilometer_collector:enabled' state.sls heka.ceilometer_collector;
195 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@heka:ceilometer_collector:enabled' service.restart ceilometer_collector
196 fi
197 node_name: {{ HOSTNAME_CFG01 }}
198 retry: {count: 1, delay: 10}
199 skip_fail: false
200{%- endmacro %}
201
Oleksii Butenkoffc09222018-09-21 12:37:16 +0300202{%- macro MACRO_CONFIGURE_SERVICES() %}
Oleksii Butenko40772422018-10-01 16:52:49 +0300203# Collect grains needed to configure the services
204- description: Collect Grains
205 cmd: |
206 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:minion' state.sls salt.minion.grains;
207 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:minion' saltutil.refresh_modules;
208 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:minion' mine.update
Oleksii Butenkoffc09222018-09-21 12:37:16 +0300209 node_name: {{ HOSTNAME_CFG01 }}
210 retry: {count: 1, delay: 10}
211 skip_fail: false
Oleksii Butenkoffc09222018-09-21 12:37:16 +0300212
Oleksii Butenko40772422018-10-01 16:52:49 +0300213- description: Check docker ps
214 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@docker:swarm and I@prometheus:server' state.sls prometheus
215 node_name: {{ HOSTNAME_CFG01 }}
216 retry: {count: 2, delay: 10}
217 skip_fail: false
218
219- description: Configure Remote Collector in Docker Swarm for Openstack deployments
220 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@docker:swarm and I@prometheus:server' state.sls heka.remote_collector
221 node_name: {{ HOSTNAME_CFG01 }}
222 retry: {count: 1, delay: 10}
223 skip_fail: false
224
Oleksii Butenkoffc09222018-09-21 12:37:16 +0300225- description: launch prometheus containers
226 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@docker:swarm:role:master and I@prometheus:server' state.sls docker.client
227 node_name: {{ HOSTNAME_CFG01 }}
228 retry: {count: 2, delay: 10}
229 skip_fail: false
230
231- description: Check docker ps
232 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@docker:swarm and I@prometheus:server' cmd.run "docker ps"
233 node_name: {{ HOSTNAME_CFG01 }}
Oleksii Butenkoffc09222018-09-21 12:37:16 +0300234 retry: {count: 1, delay: 10}
235 skip_fail: false
236
Oleksii Butenko40772422018-10-01 16:52:49 +0300237- description: "check grafana service"
238 cmd: timeout 60 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@grafana:server' cmd.run
239 'export SL_VIP=`salt-call --out=newline_values_only pillar.get _param:stacklight_monitor_address`;
240 curl -sf http://${SL_VIP}:15013/;'
Oleksii Butenkoffc09222018-09-21 12:37:16 +0300241 node_name: {{ HOSTNAME_CFG01 }}
Oleksii Butenko40772422018-10-01 16:52:49 +0300242 retry: {count: 1, delay: 10}
243 skip_fail: true
244
245- description: Configure Grafana dashboards and datasources
246 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@grafana:client' state.sls grafana.client
247 node_name: {{ HOSTNAME_CFG01 }}
248 retry: {count: 5, delay: 60}
249 skip_fail: false
250
251- description: "check grafana service"
252 cmd: timeout 60 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@grafana:server' cmd.run
253 'export SL_VIP=`salt-call --out=newline_values_only pillar.get _param:stacklight_monitor_address`;
254 curl -sf http://${SL_VIP}:15013/;'
255 node_name: {{ HOSTNAME_CFG01 }}
256 retry: {count: 1, delay: 10}
257 skip_fail: true
258
259- description: Configure Alerta if it is exists
260 cmd: |
261 if salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@prometheus:alerta' match.pillar 'prometheus:alerta' ; then
262 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@docker:swarm and I@prometheus:alerta' state.sls prometheus.alerta
263 fi
264 node_name: {{ HOSTNAME_CFG01 }}
265 retry: {count: 1, delay: 10}
Oleksii Butenkoffc09222018-09-21 12:37:16 +0300266 skip_fail: false
267
268- description: Run salt minion to create cert files
Oleksii Butenko40772422018-10-01 16:52:49 +0300269 cmd: salt --hard-crash --state-output=mixed --state-verbose=False "*" state.sls salt.minion.cert
Oleksii Butenkoffc09222018-09-21 12:37:16 +0300270 node_name: {{ HOSTNAME_CFG01 }}
271 retry: {count: 1, delay: 10}
Oleksii Butenko40772422018-10-01 16:52:49 +0300272 skip_fail: true
273{%- endmacro %}