blob: d41d1c1922173869be5b2ec2e33ef28cda44d23a [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
70{%- macro MACRO_INSTALL_MONGODB() %}
71# Install slv2 infra
72# Install MongoDB for alerta
73- description: Install Mongo if target matches
74 cmd: |
75 if salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@mongodb:server' match.pillar 'mongodb:server' ; then
76 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@mongodb:server' state.sls mongodb.server
77 fi
78 node_name: {{ HOSTNAME_CFG01 }}
79 retry: {count: 1, delay: 10}
80 skip_fail: false
81{%- endmacro %}
82
83{%- macro MACRO_INSTALL_MONGODB_CLUSTER() %}
84# Create MongoDB cluster
85- description: Install Mongo if target matches
86 cmd: |
87 if salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@mongodb:server' match.pillar 'mongodb:server' ; then
88 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@mongodb:server' state.sls mongodb.cluster
89 fi
90 node_name: {{ HOSTNAME_CFG01 }}
91 retry: {count: 5, delay: 20}
92 skip_fail: false
93
94- description: Install telegraf
95 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@telegraf:agent or I@telegraf:remote_agent' state.sls telegraf
96 node_name: {{ HOSTNAME_CFG01 }}
97 retry: {count: 2, delay: 10}
98 skip_fail: false
99
100- description: Configure Prometheus exporters, if pillar 'prometheus:exporters' exists on any server
101 cmd: |
102 if salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@prometheus:exporters' match.pillar 'prometheus:exporters' ; then
103 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@prometheus:exporters' state.sls prometheus
104 fi
105 node_name: {{ HOSTNAME_CFG01 }}
106 retry: {count: 1, delay: 10}
107 skip_fail: false
108
109- description: Install elasticsearch server
110 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@elasticsearch:server' state.sls elasticsearch.server -b 1
111 node_name: {{ HOSTNAME_CFG01 }}
112 retry: {count: 1, delay: 10}
113 skip_fail: false
114
115- description: Install kibana server
116 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@kibana:server' state.sls kibana.server -b 1
117 node_name: {{ HOSTNAME_CFG01 }}
118 retry: {count: 1, delay: 10}
119 skip_fail: false
120
121- description: Install elasticsearch client
122 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@elasticsearch:client' state.sls elasticsearch.client
123 node_name: {{ HOSTNAME_CFG01 }}
124 retry: {count: 2, delay: 30}
125 skip_fail: false
126
127- description: Install kibana client
128 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@kibana:client' state.sls kibana.client
129 node_name: {{ HOSTNAME_CFG01 }}
130 retry: {count: 1, delay: 10}
131 skip_fail: false
132
133- description: Check influix db
134 cmd: |
135 INFLUXDB_SERVICE=`salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@influxdb:server' test.ping 1>/dev/null 2>&1 && echo true`;
136 echo "Influxdb service presence: ${INFLUXDB_SERVICE}";
137 if [[ "$INFLUXDB_SERVICE" == "true" ]]; then
138 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@influxdb:server' state.sls influxdb
139 fi
140 node_name: {{ HOSTNAME_CFG01 }}
141 retry: {count: 1, delay: 5}
142 skip_fail: true
143{%- endmacro %}
144
145{%- macro MACRO_INSTALL_PROMETEUS() %}
146# Install Prometheus LTS(optional if set in model)
147- description: Prometheus LTS(optional if set in model)
148 cmd: |
149 PROMETHEUS_SERVICE=`salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@prometheus:relay' test.ping 1>/dev/null 2>&1 && echo true`;
150 echo "PROMETHEUS rely service presence: ${PROMETHEUS_SERVICE}";
151 if [[ "$PROMETHEUS_SERVICE" == "true" ]]; then
152 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@prometheus:relay' state.sls prometheus
153 fi
154 node_name: {{ HOSTNAME_CFG01 }}
155 retry: {count: 1, delay: 5}
156 skip_fail: true
157{%- endmacro %}
158
159{%- macro MACRO_INSTALL_LOG_COLLECTION() %}
160# Install service for the log collection
161- description: Configure fluentd
162 cmd: |
163 FLUENTD_SERVICE=`salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@fluentd:agent' test.ping 1>/dev/null 2>&1 && echo true`;
164 echo "Fluentd service presence: ${FLUENTD_SERVICE}";
165 if [[ "$FLUENTD_SERVICE" == "true" ]]; then
166 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@fluentd:agent' state.sls fluentd
167 else
168 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@heka:log_collector' state.sls heka.log_collector
169 fi
170 node_name: {{ HOSTNAME_CFG01 }}
171 retry: {count: 1, delay: 10}
172 skip_fail: false
173{%- endmacro %}
174
175{%- macro MACRO_INSTALL_CEILOMETER_COLLECTOR() %}
176# Install heka ceilometer collector
177- description: Install heka ceilometer if they exists
178 cmd: |
179 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`;
180 echo "Ceilometer service presence: ${CEILO}";
181 if [[ "$CEILO" == "true" ]]; then
182 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@heka:ceilometer_collector:enabled' state.sls heka.ceilometer_collector;
183 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@heka:ceilometer_collector:enabled' service.restart ceilometer_collector
184 fi
185 node_name: {{ HOSTNAME_CFG01 }}
186 retry: {count: 1, delay: 10}
187 skip_fail: false
188{%- endmacro %}
189
190{%- macro MACRO_COLLECT_GRAINS() %}
191# Collect grains needed to configure the services
192
193- description: Get grains
194 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:minion' state.sls salt.minion.grains
195 node_name: {{ HOSTNAME_CFG01 }}
196 retry: {count: 1, delay: 10}
197 skip_fail: false
198
199- description: Sync modules
200 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:minion' saltutil.refresh_modules
201 node_name: {{ HOSTNAME_CFG01 }}
202 retry: {count: 1, delay: 10}
203 skip_fail: false
204
205- description: Update mine
206 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:minion' mine.update; sleep 5;
207 node_name: {{ HOSTNAME_CFG01 }}
208 retry: {count: 5, delay: 15}
209 skip_fail: false
210{%- endmacro %}
211
212{%- macro MACRO_CONFIGURE_SERVICES() %}
213# Configure the services running in Docker Swarm
214- description: Configure prometheus in docker swarm
215 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@docker:swarm and I@prometheus:server' state.sls prometheus,heka.remote_collector
216 node_name: {{ HOSTNAME_CFG01 }}
217 retry: {count: 1, delay: 10}
218 skip_fail: false
219{%- endmacro %}
220
221{%- macro MACRO_LAUNCH_CONTAINERS() %}
222# Launch containers
223- description: launch prometheus containers
224 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@docker:swarm:role:master and I@prometheus:server' state.sls docker.client
225 node_name: {{ HOSTNAME_CFG01 }}
226 retry: {count: 2, delay: 10}
227 skip_fail: false
228
229- description: Check docker ps
230 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@docker:swarm and I@prometheus:server' cmd.run "docker ps"
231 node_name: {{ HOSTNAME_CFG01 }}
232 retry: {count: 2, delay: 10}
233 skip_fail: false
234
235- description: Install sphinx
236 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@sphinx:server' state.sls sphinx
237 node_name: {{ HOSTNAME_CFG01 }}
238 retry: {count: 1, delay: 10}
239 skip_fail: false
240
241- description: Configure Grafana dashboards and datasources
242 cmd: sleep 30; salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@grafana:client' state.sls grafana.client
243 node_name: {{ HOSTNAME_CFG01 }}
244 retry: {count: 2, delay: 10}
245 skip_fail: false
246
247- description: Run salt minion to create cert files
248 cmd: salt --hard-crash --state-output=mixed --state-verbose=False "*" state.sls salt.minion
249 node_name: {{ HOSTNAME_CFG01 }}
250 retry: {count: 1, delay: 10}
251 skip_fail: false
252{%- endmacro %}