Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 1 | {% from 'virtual-mcp11-k8s-contrail/underlay.yaml' import HOSTNAME_CFG01 with context %} |
| 2 | {% from 'virtual-mcp11-k8s-contrail/underlay.yaml' import REPOSITORY_SUITE with context %} |
Tatyana Leontovich | 3162aa2 | 2017-05-25 19:03:43 +0300 | [diff] [blame^] | 3 | {% from 'virtual-mcp11-k8s-contrail/underlay.yaml' import DOMAIN_NAME with context %} |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 4 | |
| 5 | {% set SALT_MODELS_REPOSITORY = os_env('SALT_MODELS_REPOSITORY','https://gerrit.mcp.mirantis.net/salt-models/mcp-virtual-lab') %} |
| 6 | {% set SALT_MODELS_COMMIT = os_env('SALT_MODELS_COMMIT','master') %} |
| 7 | |
| 8 | # Address pools for reclass cluster model are taken in the following order: |
| 9 | # 1. environment variables, |
| 10 | # 2. config.underlay.address_pools based on fuel-devops address pools |
| 11 | # (see generated '.ini' file after underlay is created), |
| 12 | # 3. defaults |
| 13 | {% set address_pools = config.underlay.address_pools %} |
| 14 | {% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('admin-pool01', '192.168.10.0/24')) %} |
| 15 | {% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '172.16.10.0/24')) %} |
| 16 | |
| 17 | {% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %} |
| 18 | {% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %} |
| 19 | |
Sergii Golovatiuk | c504a39 | 2017-05-22 21:41:06 +0200 | [diff] [blame] | 20 | - description: Configure repository on the cfg01 node |
| 21 | cmd: |
| 22 | echo "172.18.248.114 jenkins.mcp.mirantis.net gerrit.mcp.mirantis.net" >> /etc/hosts; |
| 23 | echo "185.135.196.10 apt-mk.mirantis.com" >> /etc/hosts; |
| 24 | echo "nameserver 172.18.208.44" >> /etc/resolv.conf; |
| 25 | echo "nameserver 8.8.8.8" >> /etc/resolv.conf; |
| 26 | which wget >/dev/null || (apt-get update; apt-get install -y wget); |
| 27 | echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial nightly salt extra" > /etc/apt/sources.list.d/mcp_salt.list; |
| 28 | wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -; |
| 29 | echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3 xenial main" > /etc/apt/sources.list.d/saltstack.list; |
| 30 | wget -O - https://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3/SALTSTACK-GPG-KEY.pub | apt-key add -; |
| 31 | node_name: {{ HOSTNAME_CFG01 }} |
| 32 | retry: {count: 1, delay: 1} |
| 33 | skip_fail: false |
| 34 | |
| 35 | - description: Update packages on cfg01 |
| 36 | cmd: apt-get clean; apt-get update |
| 37 | node_name: {{ HOSTNAME_CFG01 }} |
| 38 | retry: {count: 1, delay: 1} |
| 39 | skip_fail: false |
| 40 | |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 41 | - description: Installing salt master on cfg01 |
| 42 | cmd: eatmydata apt-get install -y reclass git salt-master |
| 43 | node_name: {{ HOSTNAME_CFG01 }} |
| 44 | retry: {count: 1, delay: 1} |
| 45 | skip_fail: false |
| 46 | |
Sergii Golovatiuk | c504a39 | 2017-05-22 21:41:06 +0200 | [diff] [blame] | 47 | - description: Install common packages on cfg01 |
| 48 | cmd: apt-get install -y python-pip wget curl tmux byobu iputils-ping traceroute htop tree |
| 49 | node_name: {{ HOSTNAME_CFG01 }} |
| 50 | retry: {count: 1, delay: 1} |
| 51 | skip_fail: false |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 52 | |
| 53 | - description: Configure salt-master on cfg01 |
| 54 | cmd: | |
| 55 | cat << 'EOF' >> /etc/salt/master.d/master.conf |
| 56 | file_roots: |
| 57 | base: |
| 58 | - /usr/share/salt-formulas/env |
| 59 | pillar_opts: False |
| 60 | open_mode: True |
| 61 | reclass: &reclass |
| 62 | storage_type: yaml_fs |
| 63 | inventory_base_uri: /srv/salt/reclass |
| 64 | ext_pillar: |
| 65 | - reclass: *reclass |
| 66 | master_tops: |
| 67 | reclass: *reclass |
| 68 | EOF |
| 69 | node_name: {{ HOSTNAME_CFG01 }} |
| 70 | retry: {count: 1, delay: 1} |
| 71 | skip_fail: false |
| 72 | |
| 73 | - description: Configure GIT settings and certificates |
| 74 | cmd: touch /root/.git_trusted_certs.pem; |
| 75 | for server in git.tcpcloud.eu github.com; do |
| 76 | openssl s_client -showcerts -connect $server:443 </dev/null |
| 77 | | openssl x509 -outform PEM |
| 78 | >> /root/.git_trusted_certs.pem; |
| 79 | done; |
| 80 | HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem; |
| 81 | HOME=/root git config --global user.email "tcp-qa@example.com"; |
| 82 | HOME=/root git config --global user.name "TCP QA"; |
| 83 | node_name: {{ HOSTNAME_CFG01 }} |
| 84 | retry: {count: 1, delay: 1} |
| 85 | skip_fail: false |
| 86 | |
| 87 | |
| 88 | - description: Clone reclass models with submodules |
| 89 | cmd: | |
| 90 | ssh-keyscan -H github.com >> ~/.ssh/known_hosts; |
| 91 | git clone -b {{ SALT_MODELS_COMMIT }} --recurse-submodules {{ SALT_MODELS_REPOSITORY }} /srv/salt/reclass; |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 92 | mkdir -p /srv/salt/reclass/classes/service; |
Sergii Golovatiuk | c504a39 | 2017-05-22 21:41:06 +0200 | [diff] [blame] | 93 | node_name: {{ HOSTNAME_CFG01 }} |
| 94 | retry: {count: 1, delay: 1} |
| 95 | skip_fail: false |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 96 | |
| 97 | # Replace firstly to an intermediate value to avoid intersection between |
| 98 | # already replaced and replacing networks. |
| 99 | # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice: |
| 100 | # 192.168.10 -> 10.16.0 (generated network for admin) |
| 101 | # 10.16.0 -> <external network> |
| 102 | # So let's replace constant networks to the keywords, and then keywords to the desired networks. |
Sergii Golovatiuk | c504a39 | 2017-05-22 21:41:06 +0200 | [diff] [blame] | 103 | - description: Fix model |
| 104 | cmd: | |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 105 | find /srv/salt/reclass/ -type f -exec sed -i 's/192\.168\.10\./==IPV4_NET_ADMIN_PREFIX==/g' {} + |
| 106 | find /srv/salt/reclass/ -type f -exec sed -i 's/172\.16\.10\./==IPV4_NET_CONTROL_PREFIX==/g' {} + |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 107 | find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}./g' {} + |
| 108 | find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}./g' {} + |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 109 | find /srv/salt/reclass/ -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} + |
| 110 | |
| 111 | # Disable checkouting the model from remote repository |
| 112 | cat << 'EOF' >> /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml |
Tatyana Leontovich | 3162aa2 | 2017-05-25 19:03:43 +0300 | [diff] [blame^] | 113 | parameters: |
| 114 | _param: |
| 115 | linux_system_codename: xenial |
| 116 | reclass_data_revision: master |
| 117 | linux: |
| 118 | system: |
| 119 | name: {{ HOSTNAME_CFG01 }} |
| 120 | domain: {{ DOMAIN_NAME }}.local |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 121 | # local storage |
| 122 | reclass: |
| 123 | storage: |
| 124 | data_source: |
| 125 | engine: local |
| 126 | EOF |
| 127 | |
| 128 | # Show the changes to the console |
| 129 | cd /srv/salt/reclass/; git diff |
| 130 | node_name: {{ HOSTNAME_CFG01 }} |
| 131 | retry: {count: 1, delay: 1} |
| 132 | skip_fail: false |
| 133 | |
| 134 | - description: Configure reclass |
| 135 | cmd: | |
| 136 | FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas}; |
Tatyana Leontovich | eed70d7 | 2017-05-25 16:32:17 +0300 | [diff] [blame] | 137 | FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt-mk.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt}; |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 138 | FORMULA_GPG=${FORMULA_GPG:-http://apt-mk.mirantis.com/public.gpg}; |
| 139 | which wget > /dev/null || (apt-get update; apt-get install -y wget); |
| 140 | echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list; |
| 141 | wget -O - "${FORMULA_GPG}" | apt-key add -; |
| 142 | apt-get clean; apt-get update; |
| 143 | [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service; |
Tatyana Leontovich | eed70d7 | 2017-05-25 16:32:17 +0300 | [diff] [blame] | 144 | declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon" "prometheus" "telegraf"); |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 145 | echo -e "\nInstalling all required salt formulas\n"; |
| 146 | eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}"; |
| 147 | for formula_service in "${formula_services[@]}"; do |
| 148 | echo -e "\nLink service metadata for formula ${formula_service} ...\n"; |
| 149 | [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service}; |
| 150 | done; |
| 151 | [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env; |
| 152 | [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd; |
| 153 | [ ! -d /etc/reclass ] && mkdir /etc/reclass; |
| 154 | |
| 155 | cat << 'EOF' >> /etc/reclass/reclass-config.yml |
| 156 | storage_type: yaml_fs |
| 157 | pretty_print: True |
| 158 | output: yaml |
| 159 | inventory_base_uri: /srv/salt/reclass |
| 160 | EOF |
| 161 | node_name: {{ HOSTNAME_CFG01 }} |
| 162 | retry: {count: 1, delay: 1} |
| 163 | skip_fail: false |
| 164 | |
| 165 | - description: Restart salt-master service |
| 166 | cmd: | |
| 167 | systemctl restart salt-master; |
| 168 | node_name: {{ HOSTNAME_CFG01 }} |
| 169 | retry: {count: 1, delay: 5} |
| 170 | skip_fail: false |
| 171 | |
| 172 | {% for ssh in config.underlay.ssh %} |
| 173 | - description: Configure salt-minion on {{ ssh['node_name'] }} |
| 174 | cmd: | |
| 175 | [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d; |
| 176 | cat << "EOF" >> /etc/salt/minion.d/minion.conf |
| 177 | id: {{ ssh['node_name'] }} |
| 178 | master: {{ config.salt.salt_master_host }} |
| 179 | EOF |
| 180 | eatmydata apt-get install -y salt-minion; |
| 181 | echo "Check for system info and metadata availability ..."; |
| 182 | salt-call --no-color grains.items; |
| 183 | salt-call --no-color pillar.items; |
| 184 | node_name: {{ ssh['node_name'] }} |
| 185 | retry: {count: 1, delay: 1} |
| 186 | skip_fail: false |
| 187 | {% endfor %} |
| 188 | |
| 189 | |
| 190 | - description: Accept salt keys from all the nodes |
| 191 | cmd: salt-key -A -y |
| 192 | node_name: {{ HOSTNAME_CFG01 }} |
| 193 | retry: {count: 1, delay: 5} |
| 194 | skip_fail: true |
| 195 | |
| 196 | |
| 197 | - description: Configure salt adoptors on cfg01 |
| 198 | cmd: | |
| 199 | ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt; |
| 200 | chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py |
| 201 | node_name: {{ HOSTNAME_CFG01 }} |
| 202 | retry: {count: 1, delay: 1} |
| 203 | skip_fail: false |
| 204 | |
| 205 | |
| 206 | # Prepare salt services and nodes settings |
| 207 | - description: Run 'linux' formula on cfg01 |
| 208 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 209 | -C 'I@salt:master' state.sls linux; |
| 210 | node_name: {{ HOSTNAME_CFG01 }} |
| 211 | retry: {count: 1, delay: 5} |
| 212 | skip_fail: false |
| 213 | |
| 214 | |
| 215 | - description: Run 'openssh' formula on cfg01 |
| 216 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 217 | -C 'I@salt:master' state.sls openssh; |
| 218 | salt --hard-crash --state-output=mixed --state-verbose=False |
| 219 | -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication |
| 220 | yes/' /etc/ssh/sshd_config && service ssh restart"; |
| 221 | node_name: {{ HOSTNAME_CFG01 }} |
| 222 | retry: {count: 3, delay: 5} |
| 223 | skip_fail: false |
| 224 | |
| 225 | |
| 226 | - description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962' |
| 227 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 228 | '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config" |
| 229 | node_name: {{ HOSTNAME_CFG01 }} |
| 230 | retry: {count: 1, delay: 1} |
| 231 | skip_fail: false |
| 232 | |
| 233 | - description: Run 'salt.master' formula on cfg01 |
| 234 | cmd: timeout 120 salt --hard-crash --state-output=mixed --state-verbose=False |
| 235 | -C 'I@salt:master' state.sls salt.master.service; |
| 236 | node_name: {{ HOSTNAME_CFG01 }} |
| 237 | retry: {count: 2, delay: 5} |
| 238 | skip_fail: false |
| 239 | |
| 240 | - description: Run 'salt' formula on cfg01 with workaround proposed in PROD-10894 |
| 241 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 242 | -C 'I@salt:master' state.sls salt; |
| 243 | salt --hard-crash --state-output=mixed --state-verbose=False |
| 244 | -C 'I@salt:master' saltutil.sync_all |
| 245 | node_name: {{ HOSTNAME_CFG01 }} |
| 246 | retry: {count: 5, delay: 5} |
| 247 | skip_fail: false |
| 248 | |
| 249 | - description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated |
| 250 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 251 | -C 'I@salt:master' state.sls reclass |
| 252 | node_name: {{ HOSTNAME_CFG01 }} |
| 253 | retry: {count: 1, delay: 5} |
| 254 | skip_fail: false |
| 255 | |
| 256 | - description: Refresh pillars on all minions |
| 257 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar |
| 258 | node_name: {{ HOSTNAME_CFG01 }} |
| 259 | retry: {count: 1, delay: 5} |
| 260 | skip_fail: false |
| 261 | |
| 262 | - description: Sync all salt resources |
| 263 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all |
| 264 | node_name: {{ HOSTNAME_CFG01 }} |
| 265 | retry: {count: 1, delay: 5} |
| 266 | skip_fail: false |
| 267 | |
| 268 | - description: Show reclass-salt --top |
| 269 | cmd: reclass-salt --top |
| 270 | node_name: {{ HOSTNAME_CFG01 }} |
| 271 | retry: {count: 1, delay: 5} |
| 272 | skip_fail: false |
| 273 | |
| 274 | - description: Execute salt.minion.cert |
| 275 | cmd: salt-call --no-color state.sls salt.minion.cert -l info; |
| 276 | node_name: {{ HOSTNAME_CFG01 }} |
| 277 | retry: {count: 1, delay: 5} |
| 278 | skip_fail: false |
| 279 | |
| 280 | # Bootstrap all nodes |
| 281 | |
| 282 | - description: Configure linux on controllers |
| 283 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False 'ctl*' state.sls |
| 284 | linux |
| 285 | node_name: {{ HOSTNAME_CFG01 }} |
| 286 | retry: {count: 1, delay: 5} |
| 287 | skip_fail: false |
| 288 | |
| 289 | - description: Configure linux on cmp |
| 290 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False 'cmp*' state.sls |
| 291 | linux |
| 292 | node_name: {{ HOSTNAME_CFG01 }} |
| 293 | retry: {count: 3, delay: 20} |
| 294 | skip_fail: false |
| 295 | |
| 296 | - description: Configure openssh on all nodes |
| 297 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not |
| 298 | cfg*' state.sls openssh;salt --hard-crash --state-output=mixed --state-verbose=False |
| 299 | -C '* and not cfg*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication |
| 300 | yes/' /etc/ssh/sshd_config && service ssh restart" |
| 301 | node_name: {{ HOSTNAME_CFG01 }} |
| 302 | retry: {count: 1, delay: 5} |
| 303 | skip_fail: false |
| 304 | |
| 305 | - description: Configure salt.minion on ctl |
| 306 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False 'ctl*' state.sls salt.minion |
| 307 | node_name: {{ HOSTNAME_CFG01 }} |
| 308 | retry: {count: 3, delay: 5} |
| 309 | skip_fail: false |
| 310 | |
| 311 | - description: Configure salt.minion on cmp |
| 312 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False 'cmp*' state.sls salt.minion |
| 313 | node_name: {{ HOSTNAME_CFG01 }} |
| 314 | retry: {count: 3, delay: 5} |
| 315 | skip_fail: false |
| 316 | |
| 317 | - description: Check salt minion versions on slaves |
| 318 | cmd: salt '*' test.version |
| 319 | node_name: {{ HOSTNAME_CFG01 }} |
| 320 | retry: {count: 1, delay: 5} |
| 321 | skip_fail: false |
| 322 | |
| 323 | - description: Check salt top states on nodes |
| 324 | cmd: salt '*' state.show_top |
| 325 | node_name: {{ HOSTNAME_CFG01 }} |
| 326 | retry: {count: 1, delay: 5} |
| 327 | skip_fail: false |
| 328 | |
| 329 | - description: Configure ntp and rsyslog on nodes |
| 330 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls ntp,rsyslog |
| 331 | node_name: {{ HOSTNAME_CFG01 }} |
| 332 | retry: {count: 1, delay: 10} |
| 333 | skip_fail: false |