| Dennis Dmitriev | eac3aab | 2017-07-12 16:36:41 +0300 | [diff] [blame^] | 1 | {% 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 |  | 
 | 80 | - description: Setup salt-minion on docker swarm master | 
 | 81 |   cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@docker:swarm:role:master and {{ CICD_NODES_SELECTOR }}' state.sls salt && | 
 | 82 |     salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@docker:swarm:role:master and {{ CICD_NODES_SELECTOR }}' mine.flush && | 
 | 83 |     salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@docker:swarm:role:master and {{ CICD_NODES_SELECTOR }}' mine.update | 
 | 84 |   node_name: {{ HOSTNAME_CFG01 }} | 
 | 85 |   retry: {count: 3, delay: 15} | 
 | 86 |   skip_fail: false | 
 | 87 |  | 
 | 88 | - description: Install Docker Swarm on other nodes | 
 | 89 |   cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@docker:swarm and {{ CICD_NODES_SELECTOR }}' state.sls docker.swarm | 
 | 90 |   node_name: {{ HOSTNAME_CFG01 }} | 
 | 91 |   retry: {count: 1, delay: 5} | 
 | 92 |   skip_fail: false | 
 | 93 |  | 
 | 94 | - description: Show Docker Swarm nodes | 
 | 95 |   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' | 
 | 96 |   node_name: {{ HOSTNAME_CFG01 }} | 
 | 97 |   retry: {count: 1, delay: 5} | 
 | 98 |   skip_fail: false | 
 | 99 |  | 
 | 100 | # Configure OSS services | 
 | 101 | #----------------------- | 
 | 102 |  | 
 | 103 | - description: Setup devops portal | 
 | 104 |   cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@devops_portal:config:enabled' state.sls devops_portal.config | 
 | 105 |   node_name: {{ HOSTNAME_CFG01 }} | 
 | 106 |   retry: {count: 1, delay: 5} | 
 | 107 |   skip_fail: false | 
 | 108 |  | 
 | 109 | - description: Setup Rundeck server | 
 | 110 |   cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@rundeck:server' state.sls rundeck.server | 
 | 111 |   node_name: {{ HOSTNAME_CFG01 }} | 
 | 112 |   retry: {count: 1, delay: 5} | 
 | 113 |   skip_fail: false | 
 | 114 |  | 
 | 115 | # Deploy Docker services | 
 | 116 | #----------------------- | 
 | 117 |  | 
 | 118 | # Original comment from pipeline:  XXX: for some weird unknown reason, refresh_pillar is required to execute here | 
 | 119 |  | 
 | 120 | - description: "Workaround from the pipeline: XXX: for some weird unknown reason, refresh_pillar is required to execute here" | 
 | 121 |   cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@aptly:publisher' saltutil.refresh_pillar | 
 | 122 |   node_name: {{ HOSTNAME_CFG01 }} | 
 | 123 |   retry: {count: 1, delay: 5} | 
 | 124 |   skip_fail: false | 
 | 125 |  | 
 | 126 | - 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]" | 
 | 127 |   cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@aptly:publisher' state.sls aptly.publisher | 
 | 128 |   node_name: {{ HOSTNAME_CFG01 }} | 
 | 129 |   retry: {count: 1, delay: 5} | 
 | 130 |   skip_fail: false | 
 | 131 |  | 
 | 132 | - description: Install Docker client | 
 | 133 |   cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@docker:swarm:role:master' state.sls docker.client | 
 | 134 |   node_name: {{ HOSTNAME_CFG01 }} | 
 | 135 |   retry: {count: 3, delay: 5} | 
 | 136 |   skip_fail: false | 
 | 137 |  | 
 | 138 | - description: "Workaround from the pipeline: sync all salt objects" | 
 | 139 |   cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all | 
 | 140 |   node_name: {{ HOSTNAME_CFG01 }} | 
 | 141 |   retry: {count: 1, delay: 5} | 
 | 142 |   skip_fail: false | 
 | 143 |  | 
 | 144 |  | 
 | 145 | # Aptly | 
 | 146 | #------ | 
 | 147 |  | 
 | 148 | - description: Install Aptly and check it's API | 
 | 149 |   cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@aptly:server' state.sls aptly && | 
 | 150 |     timeout 90 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@aptly:server' cmd.run | 
 | 151 |       'export CICD_CONTROL_ADDRESS=$(salt-call --out=newline_values_only pillar.get _param:cicd_control_address); | 
 | 152 |        while true; do curl -sf http://${CICD_CONTROL_ADDRESS}:8084/api/version  && break; sleep 2; done' | 
 | 153 |   node_name: {{ HOSTNAME_CFG01 }} | 
 | 154 |   retry: {count: 3, delay: 10} | 
 | 155 |   skip_fail: false | 
 | 156 |  | 
 | 157 | # OpenLDAP | 
 | 158 | #--------- | 
 | 159 |  | 
 | 160 | - description: Install LDAP and check it's availability | 
 | 161 |   cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@openldap:client' state.sls openldap && | 
 | 162 |     timeout 60 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@openldap:client' cmd.run | 
 | 163 |       'export CICD_CONTROL_ADDRESS=$(salt-call --out=newline_values_only pillar.get _param:cicd_control_address); | 
 | 164 |        while true; do curl -sf ldap://${CICD_CONTROL_ADDRESS} >/dev/null && break; sleep 2; done' && | 
 | 165 |     sleep 20 | 
 | 166 |   node_name: {{ HOSTNAME_CFG01 }} | 
 | 167 |   retry: {count: 3, delay: 10} | 
 | 168 |   skip_fail: false | 
 | 169 |  | 
 | 170 | # Gerrit | 
 | 171 | #------- | 
 | 172 |  | 
 | 173 | - description: Install Gerrit and check it's availability | 
 | 174 |   cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@gerrit:client' state.sls gerrit && | 
 | 175 |     timeout 60 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@gerrit:client' cmd.run | 
 | 176 |       'export CICD_CONTROL_ADDRESS=$(salt-call --out=newline_values_only pillar.get _param:cicd_control_address); | 
 | 177 |        while true; do curl -sf http://${CICD_CONTROL_ADDRESS}:8080 >/dev/null && break; sleep 2; done' | 
 | 178 |   node_name: {{ HOSTNAME_CFG01 }} | 
 | 179 |   retry: {count: 3, delay: 10} | 
 | 180 |   skip_fail: false | 
 | 181 |  | 
 | 182 | # Jenkins | 
 | 183 | #-------- | 
 | 184 |  | 
 | 185 |  | 
 | 186 | - description: Install Jenkins and check it's availability | 
 | 187 |   cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@jenkins:client' state.sls jenkins | 
 | 188 |   # TODO: Jenkins requires authenticate token. Remove -f from curl for now. | 
 | 189 |   cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@jenkins:client' state.sls jenkins && | 
 | 190 |     timeout 60 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@jenkins:client' cmd.run | 
 | 191 |       'export CICD_CONTROL_ADDRESS=$(salt-call --out=newline_values_only pillar.get _param:cicd_control_address); | 
 | 192 |        while true; do curl -s http://${CICD_CONTROL_ADDRESS}:8081 >/dev/null && break; sleep 2; done' | 
 | 193 |   node_name: {{ HOSTNAME_CFG01 }} | 
 | 194 |   retry: {count: 3, delay: 10} | 
 | 195 |   skip_fail: false | 
 | 196 |  | 
 | 197 | # Postgres | 
 | 198 | #--------- | 
 | 199 |  | 
 | 200 | - description: Install PostgreSQL and create databases | 
 | 201 |   cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@postgresql:client' state.sls postgresql.client -b 1&& | 
 | 202 |     timeout 300 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@postgresql:client' cmd.run | 
 | 203 |       'while true; do if docker service logs postgresql_db | grep -q "ready to accept"; then break; else sleep 5; fi; done' | 
 | 204 |   node_name: {{ HOSTNAME_CFG01 }} | 
 | 205 |   retry: {count: 3, delay: 10} | 
 | 206 |   skip_fail: false | 
 | 207 |  | 
 | 208 | # Pushkin | 
 | 209 | #-------- | 
 | 210 |  | 
 | 211 | - description: Check Pushkin API availability | 
 | 212 |   cmd: timeout 60 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@postgresql:client' cmd.run | 
 | 213 |     'export CICD_CONTROL_ADDRESS=$(salt-call --out=newline_values_only pillar.get _param:cicd_control_address); | 
 | 214 |      while true; do curl -s http://${CICD_CONTROL_ADDRESS}:8887 && break; sleep 2; done' | 
 | 215 |   node_name: {{ HOSTNAME_CFG01 }} | 
 | 216 |   retry: {count: 1, delay: 10} | 
 | 217 |   skip_fail: false | 
 | 218 |  | 
 | 219 | # Rundeck | 
 | 220 | #-------- | 
 | 221 |  | 
 | 222 | - description: Install Rundeck and check availability | 
 | 223 |   cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@rundeck:client' state.sls rundeck.client && | 
 | 224 |     timeout 30 salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@rundeck:client' cmd.run | 
 | 225 |       'export CICD_CONTROL_ADDRESS=$(salt-call --out=newline_values_only pillar.get _param:cicd_control_address); | 
 | 226 |        while true; do curl -sf http://${CICD_CONTROL_ADDRESS}:4440 && break; sleep 2; done' | 
 | 227 |   node_name: {{ HOSTNAME_CFG01 }} | 
 | 228 |   retry: {count: 3, delay: 10} | 
 | 229 |   skip_fail: false | 
 | 230 |  | 
 | 231 | # Generate docs | 
 | 232 | #-------------- | 
 | 233 |  | 
 | 234 | - description: Install sphinx (may fail depending on the model) | 
 | 235 |   cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@sphinx:server' state.sls sphinx | 
 | 236 |   node_name: {{ HOSTNAME_CFG01 }} | 
 | 237 |   retry: {count: 1, delay: 10} | 
 | 238 |   skip_fail: true | 
 | 239 |  | 
 | 240 | - description: Generate docs (may fail depending on the model) | 
 | 241 |   cmd: salt-run state.orchestrate sphinx.orch.generate_doc | 
 | 242 |   node_name: {{ HOSTNAME_CFG01 }} | 
 | 243 |   retry: {count: 1, delay: 10} | 
 | 244 |   skip_fail: true | 
 | 245 |  | 
 | 246 | - description: Install nginx | 
 | 247 |   cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@nginx:server' state.sls nginx | 
 | 248 |   node_name: {{ HOSTNAME_CFG01 }} | 
 | 249 |   retry: {count: 3, delay: 10} | 
 | 250 |   skip_fail: false | 
 | 251 |  | 
 | 252 | # Final checks | 
 | 253 | #------------- | 
 | 254 |  | 
 | 255 | - description: Check for system services in failed state | 
 | 256 |   cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' cmd.run "systemctl --failed | grep -E 'loaded[ \t]+failed' && echo 'Command execution failed'  || true" | 
 | 257 |   node_name: {{ HOSTNAME_CFG01 }} | 
 | 258 |   retry: {count: 1, delay: 10} | 
 | 259 |   skip_fail: false |