Dennis Dmitriev | 77d886c | 2017-05-24 13:13:26 +0300 | [diff] [blame] | 1 | {% from 'physical_mcp11_dvr/underlay.yaml' import HOSTNAME_CFG01 with context %} |
| 2 | {% from 'physical_mcp11_dvr/underlay.yaml' import REPOSITORY_SUITE with context %} |
| 3 | |
| 4 | {% set SALT_MODELS_REPOSITORY = os_env('SALT_MODELS_REPOSITORY','https://gerrit.mcp.mirantis.net/salt-models/mcp-baremetal-lab') %} |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 5 | # Other salt model repository parameters see in shared-salt.yaml |
Dennis Dmitriev | 77d886c | 2017-05-24 13:13:26 +0300 | [diff] [blame] | 6 | |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 7 | {% import 'shared-salt.yaml' as SHARED with context %} |
Dennis Dmitriev | 77d886c | 2017-05-24 13:13:26 +0300 | [diff] [blame] | 8 | |
| 9 | # Install salt to the config node |
| 10 | |
Dennis Dmitriev | 77d886c | 2017-05-24 13:13:26 +0300 | [diff] [blame] | 11 | - description: Installing salt master on cfg01 |
| 12 | cmd: eatmydata apt-get install -y reclass git salt-master |
| 13 | node_name: {{ HOSTNAME_CFG01 }} |
| 14 | retry: {count: 1, delay: 1} |
| 15 | skip_fail: false |
| 16 | |
Dennis Dmitriev | 77d886c | 2017-05-24 13:13:26 +0300 | [diff] [blame] | 17 | - description: Configure salt-master on cfg01 |
| 18 | cmd: | |
| 19 | cat << 'EOF' >> /etc/salt/master.d/master.conf |
| 20 | file_roots: |
| 21 | base: |
| 22 | - /usr/share/salt-formulas/env |
| 23 | pillar_opts: False |
| 24 | open_mode: True |
| 25 | reclass: &reclass |
| 26 | storage_type: yaml_fs |
| 27 | inventory_base_uri: /srv/salt/reclass |
| 28 | ext_pillar: |
| 29 | - reclass: *reclass |
| 30 | master_tops: |
| 31 | reclass: *reclass |
| 32 | EOF |
| 33 | node_name: {{ HOSTNAME_CFG01 }} |
| 34 | retry: {count: 1, delay: 1} |
| 35 | skip_fail: false |
| 36 | |
| 37 | - description: Configure GIT settings and certificates |
| 38 | cmd: touch /root/.git_trusted_certs.pem; |
Matthew Mosesohn | d0632b8 | 2017-05-30 17:51:30 +0300 | [diff] [blame] | 39 | for server in github.com; do |
Dennis Dmitriev | 77d886c | 2017-05-24 13:13:26 +0300 | [diff] [blame] | 40 | openssl s_client -showcerts -connect $server:443 </dev/null |
| 41 | | openssl x509 -outform PEM |
| 42 | >> /root/.git_trusted_certs.pem; |
| 43 | done; |
| 44 | HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem; |
| 45 | HOME=/root git config --global user.email "tcp-qa@example.com"; |
| 46 | HOME=/root git config --global user.name "TCP QA"; |
| 47 | node_name: {{ HOSTNAME_CFG01 }} |
| 48 | retry: {count: 1, delay: 1} |
| 49 | skip_fail: false |
| 50 | |
| 51 | |
| 52 | - description: Clone reclass models with submodules |
| 53 | cmd: | |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 54 | {{ SHARED.MACRO_CLONE_RECLASS_MODELS() }} |
Dennis Dmitriev | 77d886c | 2017-05-24 13:13:26 +0300 | [diff] [blame] | 55 | # Show the changes to the console |
| 56 | cd /srv/salt/reclass/; git diff |
| 57 | node_name: {{ HOSTNAME_CFG01 }} |
| 58 | retry: {count: 1, delay: 1} |
| 59 | skip_fail: false |
| 60 | |
| 61 | - description: Configure reclass |
| 62 | cmd: | |
| 63 | FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas}; |
obutenko | 89aedf8 | 2017-08-04 12:50:37 +0300 | [diff] [blame] | 64 | FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt.mirantis.com/xenial stable salt}; |
| 65 | FORMULA_GPG=${FORMULA_GPG:-http://apt.mirantis.com/public.gpg}; |
Dennis Dmitriev | 77d886c | 2017-05-24 13:13:26 +0300 | [diff] [blame] | 66 | which wget > /dev/null || (apt-get update; apt-get install -y wget); |
| 67 | echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list; |
| 68 | wget -O - "${FORMULA_GPG}" | apt-key add -; |
| 69 | apt-get clean; apt-get update; |
| 70 | [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service; |
Tatyana Leontovich | 644446f | 2017-06-08 13:43:36 +0300 | [diff] [blame] | 71 | declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon" "prometheus" "telegraf" "elasticsearch"); |
Dennis Dmitriev | 77d886c | 2017-05-24 13:13:26 +0300 | [diff] [blame] | 72 | echo -e "\nInstalling all required salt formulas\n"; |
| 73 | eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}"; |
| 74 | for formula_service in "${formula_services[@]}"; do |
| 75 | echo -e "\nLink service metadata for formula ${formula_service} ...\n"; |
| 76 | [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service}; |
| 77 | done; |
| 78 | [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env; |
| 79 | [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd; |
| 80 | [ ! -d /etc/reclass ] && mkdir /etc/reclass; |
| 81 | |
| 82 | cat << 'EOF' >> /etc/reclass/reclass-config.yml |
| 83 | storage_type: yaml_fs |
| 84 | pretty_print: True |
| 85 | output: yaml |
| 86 | inventory_base_uri: /srv/salt/reclass |
| 87 | EOF |
| 88 | node_name: {{ HOSTNAME_CFG01 }} |
| 89 | retry: {count: 1, delay: 1} |
| 90 | skip_fail: false |
| 91 | |
| 92 | - description: Restart salt-master service |
| 93 | cmd: | |
Dennis Dmitriev | 266ec07 | 2017-05-25 13:39:17 +0300 | [diff] [blame] | 94 | systemctl restart salt-master; sleep 60 |
Dennis Dmitriev | 77d886c | 2017-05-24 13:13:26 +0300 | [diff] [blame] | 95 | node_name: {{ HOSTNAME_CFG01 }} |
| 96 | retry: {count: 1, delay: 5} |
| 97 | skip_fail: false |
| 98 | |
| 99 | {% for ssh in config.underlay.ssh %} |
| 100 | - description: Configure salt-minion on {{ ssh['node_name'] }} |
| 101 | cmd: | |
| 102 | [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d; |
| 103 | cat << "EOF" >> /etc/salt/minion.d/minion.conf |
| 104 | id: {{ ssh['node_name'] }} |
| 105 | master: {{ config.salt.salt_master_host }} |
| 106 | EOF |
| 107 | eatmydata apt-get install -y salt-minion; |
| 108 | echo "Check for system info and metadata availability ..."; |
| 109 | salt-call --no-color grains.items; |
| 110 | salt-call --no-color pillar.items; |
| 111 | node_name: {{ ssh['node_name'] }} |
| 112 | retry: {count: 1, delay: 1} |
| 113 | skip_fail: false |
| 114 | {% endfor %} |
| 115 | |
| 116 | |
| 117 | - description: Accept salt keys from all the nodes |
| 118 | cmd: salt-key -A -y |
| 119 | node_name: {{ HOSTNAME_CFG01 }} |
| 120 | retry: {count: 1, delay: 5} |
| 121 | skip_fail: true |
| 122 | |
| 123 | |
| 124 | - description: Configure salt adoptors on cfg01 |
| 125 | cmd: | |
| 126 | ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt; |
| 127 | chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py |
| 128 | node_name: {{ HOSTNAME_CFG01 }} |
| 129 | retry: {count: 1, delay: 1} |
| 130 | skip_fail: false |
| 131 | |
| 132 | |
| 133 | # Prepare salt services and nodes settings |
| 134 | - description: Run 'linux' formula on cfg01 |
| 135 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 136 | -C 'I@salt:master' state.sls linux; |
| 137 | node_name: {{ HOSTNAME_CFG01 }} |
| 138 | retry: {count: 3, delay: 5} |
| 139 | skip_fail: false |
| 140 | |
| 141 | |
| 142 | - description: Run 'openssh' formula on cfg01 |
| 143 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 144 | -C 'I@salt:master' state.sls openssh; |
| 145 | salt --hard-crash --state-output=mixed --state-verbose=False |
| 146 | -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication |
| 147 | yes/' /etc/ssh/sshd_config && service ssh restart"; |
| 148 | node_name: {{ HOSTNAME_CFG01 }} |
| 149 | retry: {count: 3, delay: 5} |
| 150 | skip_fail: false |
| 151 | |
| 152 | |
| 153 | - description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962' |
| 154 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 155 | '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config" |
| 156 | node_name: {{ HOSTNAME_CFG01 }} |
| 157 | retry: {count: 1, delay: 1} |
| 158 | skip_fail: false |
| 159 | |
| 160 | - description: Run 'salt.master' formula on cfg01 |
| 161 | cmd: timeout 120 salt --hard-crash --state-output=mixed --state-verbose=False |
| 162 | -C 'I@salt:master' state.sls salt.master.service; |
| 163 | node_name: {{ HOSTNAME_CFG01 }} |
| 164 | retry: {count: 2, delay: 5} |
| 165 | skip_fail: false |
| 166 | |
| 167 | - description: Run 'salt' formula on cfg01 with workaround proposed in PROD-10894 |
| 168 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 169 | -C 'I@salt:master' state.sls salt; |
| 170 | salt --hard-crash --state-output=mixed --state-verbose=False |
| 171 | -C 'I@salt:master' saltutil.sync_all |
| 172 | node_name: {{ HOSTNAME_CFG01 }} |
| 173 | retry: {count: 5, delay: 5} |
| 174 | skip_fail: false |
| 175 | |
| 176 | - description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated |
| 177 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 178 | -C 'I@salt:master' state.sls reclass |
| 179 | node_name: {{ HOSTNAME_CFG01 }} |
| 180 | retry: {count: 1, delay: 5} |
| 181 | skip_fail: false |
| 182 | |
| 183 | |
| 184 | |
Dennis Dmitriev | e17bcaf | 2017-05-25 00:26:57 +0300 | [diff] [blame] | 185 | - description: Refresh pillars for present baremetal nodes |
| 186 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar |
Dennis Dmitriev | 77d886c | 2017-05-24 13:13:26 +0300 | [diff] [blame] | 187 | node_name: {{ HOSTNAME_CFG01 }} |
| 188 | retry: {count: 1, delay: 5} |
| 189 | skip_fail: false |
| 190 | |
Dennis Dmitriev | e17bcaf | 2017-05-25 00:26:57 +0300 | [diff] [blame] | 191 | - description: Sync all salt resources for present baremetal nodes |
| 192 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all |
| 193 | node_name: {{ HOSTNAME_CFG01 }} |
| 194 | retry: {count: 1, delay: 5} |
| 195 | skip_fail: false |
| 196 | |
| 197 | - description: Configure linux for present baremetal nodes |
| 198 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not |
| 199 | cfg01*' state.sls linux |
| 200 | node_name: {{ HOSTNAME_CFG01 }} |
| 201 | retry: {count: 3, delay: 5} |
| 202 | skip_fail: false |
| 203 | |
| 204 | - description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-9576 to get bond0-connectivity *without* rebooting nodes' |
| 205 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' cmd.run |
| 206 | "cat /etc/network/interfaces | grep bond-slaves | awk '{print \$2}' | xargs -I {} ifenslave bond0 {}" |
Dennis Dmitriev | 77d886c | 2017-05-24 13:13:26 +0300 | [diff] [blame] | 207 | node_name: {{ HOSTNAME_CFG01 }} |
| 208 | retry: {count: 1, delay: 5} |
| 209 | skip_fail: false |
| 210 | |
| 211 | - description: ovs-dvr-vlan model specific Execute 'libvirt' states to create necessary libvirt networks |
| 212 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False 'kvm*' state.sls libvirt |
| 213 | node_name: {{ HOSTNAME_CFG01 }} |
| 214 | retry: {count: 1, delay: 10} |
| 215 | skip_fail: false |
| 216 | |
| 217 | - description: Create VMs for control plane |
| 218 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False 'kvm*' state.sls salt.control |
| 219 | node_name: {{ HOSTNAME_CFG01 }} |
| 220 | retry: {count: 3, delay: 10} |
| 221 | skip_fail: false |
| 222 | |
| 223 | |
| 224 | |
| 225 | - description: Refresh pillars on all minions |
| 226 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar |
| 227 | node_name: {{ HOSTNAME_CFG01 }} |
| 228 | retry: {count: 1, delay: 5} |
| 229 | skip_fail: false |
| 230 | |
| 231 | - description: Sync all salt resources |
| 232 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all |
| 233 | node_name: {{ HOSTNAME_CFG01 }} |
| 234 | retry: {count: 1, delay: 5} |
| 235 | skip_fail: false |
| 236 | |
| 237 | - description: Show reclass-salt --top for generated nodes |
| 238 | cmd: reclass-salt --top -u /srv/salt/reclass/nodes/_generated/ |
| 239 | node_name: {{ HOSTNAME_CFG01 }} |
| 240 | retry: {count: 1, delay: 5} |
| 241 | skip_fail: false |
| 242 | |
| 243 | - description: Execute salt.minion.cert |
| 244 | cmd: salt-call --no-color state.sls salt.minion.cert -l info; |
| 245 | node_name: {{ HOSTNAME_CFG01 }} |
| 246 | retry: {count: 1, delay: 5} |
| 247 | skip_fail: false |
| 248 | |
| 249 | |
| 250 | # Bootstrap all nodes |
| 251 | |
| 252 | - description: Configure linux on other nodes |
| 253 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not |
| 254 | cfg01*' state.sls linux |
| 255 | node_name: {{ HOSTNAME_CFG01 }} |
| 256 | retry: {count: 3, delay: 5} |
| 257 | skip_fail: false |
| 258 | |
| 259 | - description: Configure openssh on all nodes |
| 260 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not |
| 261 | cfg01*' state.sls openssh;salt --hard-crash --state-output=mixed --state-verbose=False |
| 262 | -C '* and not cfg*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication |
| 263 | yes/' /etc/ssh/sshd_config && service ssh restart" |
| 264 | node_name: {{ HOSTNAME_CFG01 }} |
| 265 | retry: {count: 1, delay: 5} |
| 266 | skip_fail: false |
| 267 | |
| 268 | - description: Configure salt.minion on other nodes |
| 269 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not |
| 270 | cfg01*' state.sls salt.minion |
| 271 | node_name: {{ HOSTNAME_CFG01 }} |
| 272 | retry: {count: 3, delay: 5} |
| 273 | skip_fail: false |
| 274 | |
| 275 | - description: Check salt minion versions on slaves |
| 276 | cmd: salt '*' test.version |
| 277 | node_name: {{ HOSTNAME_CFG01 }} |
| 278 | retry: {count: 1, delay: 5} |
| 279 | skip_fail: false |
| 280 | |
| 281 | - description: Check salt top states on nodes |
| 282 | cmd: salt '*' state.show_top |
| 283 | node_name: {{ HOSTNAME_CFG01 }} |
| 284 | retry: {count: 1, delay: 5} |
| 285 | skip_fail: false |
| 286 | |
| 287 | - description: Configure ntp and rsyslog on nodes |
| 288 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls ntp,rsyslog |
| 289 | node_name: {{ HOSTNAME_CFG01 }} |
| 290 | retry: {count: 1, delay: 10} |
| 291 | skip_fail: false |