blob: 9d6ead7c48ae8934b5b2f6b270ef75147bb00f38 [file] [log] [blame]
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +03001{% from 'virtual-mcp-ocata-cicd/underlay.yaml' import HOSTNAME_CFG01 with context %}
2
3# Pattern that helps salt to select CICD nodes
4{% set CICD_NODES_SELECTOR = os_env('CICD_NODES_SELECTOR','cid*') %}
5
6# Install OSS: Operational Support System Tools
7
8# Keepalived
9#-----------
10- description: Install keepalived on {{ CICD_NODES_SELECTOR }} nodes
11 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@haproxy:proxy and {{ CICD_NODES_SELECTOR }}' state.sls keepalived
12 node_name: {{ HOSTNAME_CFG01 }}
13 retry: {count: 1, delay: 10}
14 skip_fail: false
15
16- description: Install haproxy on {{ CICD_NODES_SELECTOR }} nodes
17 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@haproxy:proxy and {{ CICD_NODES_SELECTOR }}' state.sls haproxy
18 node_name: {{ HOSTNAME_CFG01 }}
19 retry: {count: 1, delay: 10}
20 skip_fail: false
21
22- description: Check the VIP
23 cmd: |
24 CICD_CONTROL_ADDRESS=`salt-call --out=newline_values_only pillar.get _param:cicd_control_address`;
25 echo "_param:cicd_control_address (vip): ${CICD_CONTROL_ADDRESS}";
26 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@haproxy:proxy and {{ CICD_NODES_SELECTOR }}' cmd.run "ip a | grep ${CICD_CONTROL_ADDRESS}" | grep -B1 ${CICD_CONTROL_ADDRESS}
27 node_name: {{ HOSTNAME_CFG01 }}
28 retry: {count: 1, delay: 5}
29 skip_fail: false
30
31# Glusterfs
32#-----------
33
34- description: Prepare glusterfs service
35 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@glusterfs:server and {{ CICD_NODES_SELECTOR }}' state.sls glusterfs.server.service
36 node_name: {{ HOSTNAME_CFG01 }}
37 retry: {count: 1, delay: 5}
38 skip_fail: false
39
40- description: Setup glusterfs server
41 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@glusterfs:server and {{ CICD_NODES_SELECTOR }}' state.sls glusterfs.server.setup -b 1
42 node_name: {{ HOSTNAME_CFG01 }}
43 retry: {count: 2, delay: 5}
44 skip_fail: false
45
46- description: Setup glusterfs client
47 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@glusterfs:client and {{ CICD_NODES_SELECTOR }}' state.sls glusterfs.client
48 node_name: {{ HOSTNAME_CFG01 }}
49 retry: {count: 1, delay: 5}
50 skip_fail: false
51
52- description: Check the gluster status
53 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
54 -C 'I@glusterfs:client and {{ CICD_NODES_SELECTOR }}*' cmd.run 'gluster peer status; gluster volume status' -b 1
55 node_name: {{ HOSTNAME_CFG01 }}
56 retry: {count: 1, delay: 5}
57 skip_fail: false
58
59# Setup Docker Swarm
60#-------------------
61
62- description: "Workaround: create /var/lib/jenkins to get Jenkins slaves working"
63 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@jenkins:client' cmd.run 'mkdir -p /var/lib/jenkins'
64 node_name: {{ HOSTNAME_CFG01 }}
65 retry: {count: 1, delay: 10}
66 skip_fail: false
67
68- description: Prepare Docker host
69 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@docker:host and {{ CICD_NODES_SELECTOR }}' state.sls docker.host
70 node_name: {{ HOSTNAME_CFG01 }}
71 retry: {count: 1, delay: 5}
72 skip_fail: false
73
74- description: Install Docker Swarm master
75 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@docker:swarm:role:master and {{ CICD_NODES_SELECTOR }}' state.sls docker.swarm
76 node_name: {{ HOSTNAME_CFG01 }}
77 retry: {count: 1, delay: 5}
78 skip_fail: false
79
Dennis Dmitriev41f0b792017-07-27 18:08:50 +030080- description: Collect grains
81 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@docker:swarm:role:master and {{ CICD_NODES_SELECTOR }}' state.sls salt.minion.grains &&
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +030082 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@docker:swarm:role:master and {{ CICD_NODES_SELECTOR }}' mine.flush &&
Dennis Dmitriev41f0b792017-07-27 18:08:50 +030083 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@docker:swarm:role:master and {{ CICD_NODES_SELECTOR }}' mine.update &&
84 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@docker:swarm and {{ CICD_NODES_SELECTOR }}' saltutil.refresh_modules &&
85 sleep 10
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +030086 node_name: {{ HOSTNAME_CFG01 }}
87 retry: {count: 3, delay: 15}
88 skip_fail: false
89
90- description: Install Docker Swarm on other nodes
91 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@docker:swarm and {{ CICD_NODES_SELECTOR }}' state.sls docker.swarm
92 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitriev41f0b792017-07-27 18:08:50 +030093 retry: {count: 2, delay: 5}
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +030094 skip_fail: false
95
96- description: Show Docker Swarm nodes
97 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@docker:swarm:role:master and {{ CICD_NODES_SELECTOR }}' cmd.run 'docker node ls'
98 node_name: {{ HOSTNAME_CFG01 }}
99 retry: {count: 1, delay: 5}
100 skip_fail: false
101
102# Configure OSS services
103#-----------------------
104
105- description: Setup devops portal
106 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@devops_portal:config:enabled' state.sls devops_portal.config
107 node_name: {{ HOSTNAME_CFG01 }}
108 retry: {count: 1, delay: 5}
109 skip_fail: false
110
111- description: Setup Rundeck server
112 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@rundeck:server' state.sls rundeck.server
113 node_name: {{ HOSTNAME_CFG01 }}
114 retry: {count: 1, delay: 5}
115 skip_fail: false
116
117# Deploy Docker services
118#-----------------------
119
120# Original comment from pipeline: XXX: for some weird unknown reason, refresh_pillar is required to execute here
121
122- description: "Workaround from the pipeline: XXX: for some weird unknown reason, refresh_pillar is required to execute here"
123 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@aptly:publisher' saltutil.refresh_pillar
124 node_name: {{ HOSTNAME_CFG01 }}
125 retry: {count: 1, delay: 5}
126 skip_fail: false
127
128- description: "Workaround from the pipeline: We need /etc/aptly-publisher.yaml to be present before services are deployed. [dd: there were issues when /etc/aptly-publisher.yaml becomes a directory, so this step should be considered]"
129 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@aptly:publisher' state.sls aptly.publisher
130 node_name: {{ HOSTNAME_CFG01 }}
131 retry: {count: 1, delay: 5}
132 skip_fail: false
133
134- description: Install Docker client
Dennis Dmitrievf8546172017-07-20 21:57:05 +0300135 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@docker:swarm:role:master and {{ CICD_NODES_SELECTOR }}' state.sls docker.client
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300136 node_name: {{ HOSTNAME_CFG01 }}
137 retry: {count: 3, delay: 5}
138 skip_fail: false
139
140- description: "Workaround from the pipeline: sync all salt objects"
141 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
142 node_name: {{ HOSTNAME_CFG01 }}
143 retry: {count: 1, delay: 5}
144 skip_fail: false
145
146
147# Aptly
148#------
149
Dennis Dmitriev41f0b792017-07-27 18:08:50 +0300150- description: "Wait for Aptly to come up in container..."
151 cmd: timeout 300 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@aptly:server' cmd.run
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300152 'export CICD_CONTROL_ADDRESS=$(salt-call --out=newline_values_only pillar.get _param:cicd_control_address);
153 while true; do curl -sf http://${CICD_CONTROL_ADDRESS}:8084/api/version && break; sleep 2; done'
154 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitriev41f0b792017-07-27 18:08:50 +0300155 retry: {count: 3, delay: 15}
156 skip_fail: false
157
158- description: "Setup Aptly"
159 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@aptly:server' state.sls aptly
160 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300161 retry: {count: 3, delay: 10}
162 skip_fail: false
163
164# OpenLDAP
165#---------
166
Dennis Dmitriev41f0b792017-07-27 18:08:50 +0300167- description: "Waiting for OpenLDAP to come up in container..."
168 cmd: timeout 60 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@openldap:client' cmd.run
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300169 'export CICD_CONTROL_ADDRESS=$(salt-call --out=newline_values_only pillar.get _param:cicd_control_address);
Dennis Dmitriev41f0b792017-07-27 18:08:50 +0300170 while true; do curl -sf ldap://${CICD_CONTROL_ADDRESS} && break; sleep 2; done'
171 node_name: {{ HOSTNAME_CFG01 }}
172 retry: {count: 3, delay: 10}
173 skip_fail: false
174
175- description: "Setup OpenLDAP"
176 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@openldap:client' state.sls openldap &&
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300177 sleep 20
178 node_name: {{ HOSTNAME_CFG01 }}
179 retry: {count: 3, delay: 10}
180 skip_fail: false
181
182# Gerrit
183#-------
184
Dennis Dmitriev41f0b792017-07-27 18:08:50 +0300185- description: "Waiting for Gerrit to come up in container..."
186 cmd: timeout 60 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@gerrit:client' cmd.run
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300187 'export CICD_CONTROL_ADDRESS=$(salt-call --out=newline_values_only pillar.get _param:cicd_control_address);
Dennis Dmitriev41f0b792017-07-27 18:08:50 +0300188 while true; do curl -sf http://${CICD_CONTROL_ADDRESS}:8080/config/server/version && break; sleep 2; done'
189 node_name: {{ HOSTNAME_CFG01 }}
190 retry: {count: 3, delay: 10}
191 skip_fail: false
192
193- description: "Setup Gerrit"
194 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@gerrit:client' state.sls gerrit
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300195 node_name: {{ HOSTNAME_CFG01 }}
196 retry: {count: 3, delay: 10}
197 skip_fail: false
198
199# Jenkins
200#--------
201
Dennis Dmitriev41f0b792017-07-27 18:08:50 +0300202- description: "Waiting for Jenkins to come up in container..."
203 cmd: timeout 60 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@jenkins:client' cmd.run
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300204 'export CICD_CONTROL_ADDRESS=$(salt-call --out=newline_values_only pillar.get _param:cicd_control_address);
Dennis Dmitrievf8546172017-07-20 21:57:05 +0300205 export JENKINS_CLIENT_USER=$(salt-call --out=newline_values_only pillar.get _param:jenkins_client_user);
206 export JENKINS_CLIENT_PASSWORD=$(salt-call --out=newline_values_only pillar.get _param:jenkins_client_password);
207 while true; do
208 curl -f -u ${JENKINS_CLIENT_USER}:${JENKINS_CLIENT_PASSWORD} http://${CICD_CONTROL_ADDRESS}:8081/api/json?pretty=true && break;
209 sleep 2;
210 done'
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300211 node_name: {{ HOSTNAME_CFG01 }}
212 retry: {count: 3, delay: 10}
213 skip_fail: false
214
Dennis Dmitriev41f0b792017-07-27 18:08:50 +0300215- description: "Setup Jenkins"
216 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@jenkins:client' state.sls jenkins
217 node_name: {{ HOSTNAME_CFG01 }}
218 retry: {count: 3, delay: 10}
219 skip_fail: false
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300220
Dennis Dmitriev41f0b792017-07-27 18:08:50 +0300221# Postgres && Pushkin
222#--------------------
223
224- description: "Waiting for postgresql database to come up in container..."
225 cmd: timeout 300 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@postgresql:client' cmd.run
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300226 'while true; do if docker service logs postgresql_db | grep -q "ready to accept"; then break; else sleep 5; fi; done'
227 node_name: {{ HOSTNAME_CFG01 }}
228 retry: {count: 3, delay: 10}
229 skip_fail: false
230
Dennis Dmitriev41f0b792017-07-27 18:08:50 +0300231- description: ("Create PostgreSQL databases, it fails at first run because of known deadlock:\n"
232 "1. State postgresql.client cannot insert values into 'pushkin' database because it is created empty,\n"
233 "2. Container with Pushkin cannot start and fill the database scheme until state postgresql.client created users.")
234 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@postgresql:client' state.sls postgresql.client -b 1 &&
235 timeout 300 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@postgresql:client' cmd.run
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300236 'export CICD_CONTROL_ADDRESS=$(salt-call --out=newline_values_only pillar.get _param:cicd_control_address);
Dennis Dmitrievf8546172017-07-20 21:57:05 +0300237 while true; do curl -sf http://${CICD_CONTROL_ADDRESS}:8887/apps && break; sleep 2; done'
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300238 node_name: {{ HOSTNAME_CFG01 }}
Dennis Dmitriev41f0b792017-07-27 18:08:50 +0300239 retry: {count: 3, delay: 100}
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300240 skip_fail: false
241
242# Rundeck
243#--------
244
Dennis Dmitriev41f0b792017-07-27 18:08:50 +0300245- description: Waiting for Rundeck to come up in container...
246 cmd: timeout 30 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@rundeck:client' cmd.run
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300247 'export CICD_CONTROL_ADDRESS=$(salt-call --out=newline_values_only pillar.get _param:cicd_control_address);
248 while true; do curl -sf http://${CICD_CONTROL_ADDRESS}:4440 && break; sleep 2; done'
249 node_name: {{ HOSTNAME_CFG01 }}
250 retry: {count: 3, delay: 10}
251 skip_fail: false
252
Dennis Dmitriev41f0b792017-07-27 18:08:50 +0300253- description: Setup Rundeck
254 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@rundeck:client' state.sls rundeck.client
255 node_name: {{ HOSTNAME_CFG01 }}
256 retry: {count: 3, delay: 10}
257 skip_fail: false
258
259# Elasticsearch
260#--------------
261
262- description: 'Waiting for Elasticsearch to come up in container...'
263 cmd: timeout 30 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@elasticsearch:client' cmd.run
264 'export CICD_CONTROL_ADDRESS=$(salt-call --out=newline_values_only pillar.get _param:cicd_control_address);
265 while true; do curl -sf http://${CICD_CONTROL_ADDRESS}:9200/?pretty && break; sleep 2; done'
266 node_name: {{ HOSTNAME_CFG01 }}
267 retry: {count: 3, delay: 10}
268 skip_fail: false
269
270- description: Setup Elasticsearch
271 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@elasticsearch:client' state.sls elasticsearch.client
272 node_name: {{ HOSTNAME_CFG01 }}
273 retry: {count: 3, delay: 10}
274 skip_fail: false
275
276
277
Dennis Dmitrieveac3aab2017-07-12 16:36:41 +0300278# Generate docs
279#--------------
280
281- description: Install sphinx (may fail depending on the model)
282 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@sphinx:server' state.sls sphinx
283 node_name: {{ HOSTNAME_CFG01 }}
284 retry: {count: 1, delay: 10}
285 skip_fail: true
286
287- description: Generate docs (may fail depending on the model)
288 cmd: salt-run state.orchestrate sphinx.orch.generate_doc
289 node_name: {{ HOSTNAME_CFG01 }}
290 retry: {count: 1, delay: 10}
291 skip_fail: true
292
293- description: Install nginx
294 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@nginx:server' state.sls nginx
295 node_name: {{ HOSTNAME_CFG01 }}
296 retry: {count: 3, delay: 10}
297 skip_fail: false
298
299# Final checks
300#-------------
301
302- description: Check for system services in failed state
303 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' cmd.run "systemctl --failed | grep -E 'loaded[ \t]+failed' && echo 'Command execution failed' || true"
304 node_name: {{ HOSTNAME_CFG01 }}
305 retry: {count: 1, delay: 10}
306 skip_fail: false