Dennis Dmitriev | ab83ea4 | 2017-05-12 16:52:45 +0300 | [diff] [blame] | 1 | {% from 'virtual-mcp11-ovs-dpdk/underlay.yaml' import HOSTNAME_CFG01 with context %} |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame] | 2 | {% from 'virtual-mcp11-ovs-dpdk/underlay.yaml' import REPOSITORY_SUITE with context %} |
Dennis Dmitriev | 99b26fe | 2017-04-26 12:34:44 +0300 | [diff] [blame] | 3 | |
| 4 | {% set SALT_MODELS_REPOSITORY = os_env('SALT_MODELS_REPOSITORY','https://gerrit.mcp.mirantis.net/salt-models/mcp-virtual-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 | 99b26fe | 2017-04-26 12:34:44 +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 %} |
| 8 | {% from 'shared-salt.yaml' import IPV4_NET_CONTROL_PREFIX with context %} |
Tatyana Leontovich | d8bf14f | 2017-04-19 12:20:50 +0300 | [diff] [blame] | 9 | |
| 10 | # Install salt to the config node |
| 11 | |
Tatyana Leontovich | d8bf14f | 2017-04-19 12:20:50 +0300 | [diff] [blame] | 12 | - description: Installing salt master on cfg01 |
Dennis Dmitriev | 99b26fe | 2017-04-26 12:34:44 +0300 | [diff] [blame] | 13 | cmd: eatmydata apt-get install -y reclass git salt-master |
Tatyana Leontovich | d8bf14f | 2017-04-19 12:20:50 +0300 | [diff] [blame] | 14 | node_name: {{ HOSTNAME_CFG01 }} |
| 15 | retry: {count: 1, delay: 1} |
| 16 | skip_fail: false |
| 17 | |
Tatyana Leontovich | d8bf14f | 2017-04-19 12:20:50 +0300 | [diff] [blame] | 18 | - description: Configure salt-master on cfg01 |
| 19 | cmd: | |
| 20 | cat << 'EOF' >> /etc/salt/master.d/master.conf |
| 21 | file_roots: |
| 22 | base: |
| 23 | - /usr/share/salt-formulas/env |
| 24 | pillar_opts: False |
| 25 | open_mode: True |
| 26 | reclass: &reclass |
| 27 | storage_type: yaml_fs |
| 28 | inventory_base_uri: /srv/salt/reclass |
| 29 | ext_pillar: |
| 30 | - reclass: *reclass |
| 31 | master_tops: |
| 32 | reclass: *reclass |
| 33 | EOF |
| 34 | node_name: {{ HOSTNAME_CFG01 }} |
| 35 | retry: {count: 1, delay: 1} |
| 36 | skip_fail: false |
| 37 | |
| 38 | - description: Configure GIT settings and certificates |
| 39 | cmd: touch /root/.git_trusted_certs.pem; |
Matthew Mosesohn | d0632b8 | 2017-05-30 17:51:30 +0300 | [diff] [blame] | 40 | for server in github.com; do |
Tatyana Leontovich | d8bf14f | 2017-04-19 12:20:50 +0300 | [diff] [blame] | 41 | openssl s_client -showcerts -connect $server:443 </dev/null |
| 42 | | openssl x509 -outform PEM |
| 43 | >> /root/.git_trusted_certs.pem; |
| 44 | done; |
| 45 | HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem; |
| 46 | HOME=/root git config --global user.email "tcp-qa@example.com"; |
| 47 | HOME=/root git config --global user.name "TCP QA"; |
| 48 | node_name: {{ HOSTNAME_CFG01 }} |
| 49 | retry: {count: 1, delay: 1} |
| 50 | skip_fail: false |
| 51 | |
| 52 | |
| 53 | - description: Clone reclass models with submodules |
| 54 | cmd: | |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame^] | 55 | {{ SHARED.MACRO_CLONE_RECLASS_MODELS() }} |
Dennis Dmitriev | 99b26fe | 2017-04-26 12:34:44 +0300 | [diff] [blame] | 56 | # Show the changes to the console |
| 57 | cd /srv/salt/reclass/; git diff |
Tatyana Leontovich | d8bf14f | 2017-04-19 12:20:50 +0300 | [diff] [blame] | 58 | node_name: {{ HOSTNAME_CFG01 }} |
| 59 | retry: {count: 1, delay: 1} |
| 60 | skip_fail: false |
| 61 | |
| 62 | - description: Configure reclass |
| 63 | cmd: | |
| 64 | FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas}; |
obutenko | 89aedf8 | 2017-08-04 12:50:37 +0300 | [diff] [blame] | 65 | FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt}; |
| 66 | FORMULA_GPG=${FORMULA_GPG:-http://apt.mirantis.com/public.gpg}; |
Tatyana Leontovich | d8bf14f | 2017-04-19 12:20:50 +0300 | [diff] [blame] | 67 | which wget > /dev/null || (apt-get update; apt-get install -y wget); |
Tatyana Leontovich | 543afa9 | 2017-04-21 14:48:03 +0300 | [diff] [blame] | 68 | echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list; |
Tatyana Leontovich | d8bf14f | 2017-04-19 12:20:50 +0300 | [diff] [blame] | 69 | wget -O - "${FORMULA_GPG}" | apt-key add -; |
| 70 | apt-get clean; apt-get update; |
| 71 | [ ! -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] | 72 | declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon" "prometheus" "telegraf" "elasticsearch"); |
Tatyana Leontovich | d8bf14f | 2017-04-19 12:20:50 +0300 | [diff] [blame] | 73 | echo -e "\nInstalling all required salt formulas\n"; |
Dennis Dmitriev | 99b26fe | 2017-04-26 12:34:44 +0300 | [diff] [blame] | 74 | eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}"; |
Tatyana Leontovich | d8bf14f | 2017-04-19 12:20:50 +0300 | [diff] [blame] | 75 | for formula_service in "${formula_services[@]}"; do |
| 76 | echo -e "\nLink service metadata for formula ${formula_service} ...\n"; |
| 77 | [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service}; |
| 78 | done; |
| 79 | [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env; |
| 80 | [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd; |
| 81 | [ ! -d /etc/reclass ] && mkdir /etc/reclass; |
| 82 | |
| 83 | cat << 'EOF' >> /etc/reclass/reclass-config.yml |
| 84 | storage_type: yaml_fs |
| 85 | pretty_print: True |
| 86 | output: yaml |
| 87 | inventory_base_uri: /srv/salt/reclass |
| 88 | EOF |
| 89 | node_name: {{ HOSTNAME_CFG01 }} |
| 90 | retry: {count: 1, delay: 1} |
| 91 | skip_fail: false |
| 92 | |
Dennis Dmitriev | 99b26fe | 2017-04-26 12:34:44 +0300 | [diff] [blame] | 93 | - description: Restart salt-master service |
| 94 | cmd: | |
| 95 | systemctl restart salt-master; |
| 96 | node_name: {{ HOSTNAME_CFG01 }} |
| 97 | retry: {count: 1, delay: 5} |
| 98 | skip_fail: false |
| 99 | |
| 100 | {% for ssh in config.underlay.ssh %} |
| 101 | - description: Configure salt-minion on {{ ssh['node_name'] }} |
Tatyana Leontovich | d8bf14f | 2017-04-19 12:20:50 +0300 | [diff] [blame] | 102 | cmd: | |
| 103 | [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d; |
| 104 | cat << "EOF" >> /etc/salt/minion.d/minion.conf |
Dennis Dmitriev | 99b26fe | 2017-04-26 12:34:44 +0300 | [diff] [blame] | 105 | id: {{ ssh['node_name'] }} |
| 106 | master: {{ config.salt.salt_master_host }} |
Tatyana Leontovich | d8bf14f | 2017-04-19 12:20:50 +0300 | [diff] [blame] | 107 | EOF |
Dennis Dmitriev | 99b26fe | 2017-04-26 12:34:44 +0300 | [diff] [blame] | 108 | eatmydata apt-get install -y salt-minion; |
Dennis Dmitriev | a9e6da8 | 2017-04-26 23:23:22 +0300 | [diff] [blame] | 109 | echo "Check for system info and metadata availability ..."; |
Dennis Dmitriev | 99b26fe | 2017-04-26 12:34:44 +0300 | [diff] [blame] | 110 | salt-call --no-color grains.items; |
Dennis Dmitriev | a9e6da8 | 2017-04-26 23:23:22 +0300 | [diff] [blame] | 111 | salt-call --no-color pillar.items; |
Dennis Dmitriev | 99b26fe | 2017-04-26 12:34:44 +0300 | [diff] [blame] | 112 | node_name: {{ ssh['node_name'] }} |
Tatyana Leontovich | d8bf14f | 2017-04-19 12:20:50 +0300 | [diff] [blame] | 113 | retry: {count: 1, delay: 1} |
| 114 | skip_fail: false |
Dennis Dmitriev | 99b26fe | 2017-04-26 12:34:44 +0300 | [diff] [blame] | 115 | {% endfor %} |
| 116 | |
Tatyana Leontovich | d8bf14f | 2017-04-19 12:20:50 +0300 | [diff] [blame] | 117 | |
Dennis Dmitriev | 8f0f80f | 2017-04-27 01:04:39 +0300 | [diff] [blame] | 118 | - description: Accept salt keys from all the nodes |
| 119 | cmd: salt-key -A -y |
| 120 | node_name: {{ HOSTNAME_CFG01 }} |
| 121 | retry: {count: 1, delay: 5} |
| 122 | skip_fail: true |
| 123 | |
Tatyana Leontovich | d8bf14f | 2017-04-19 12:20:50 +0300 | [diff] [blame] | 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 | |
Tatyana Leontovich | d8bf14f | 2017-04-19 12:20:50 +0300 | [diff] [blame] | 132 | # Prepare salt services and nodes settings |
| 133 | - description: Run 'linux' formula on cfg01 |
Tatyana Leontovich | 1801312 | 2017-06-09 20:24:50 +0300 | [diff] [blame] | 134 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux; |
Tatyana Leontovich | d8bf14f | 2017-04-19 12:20:50 +0300 | [diff] [blame] | 135 | node_name: {{ HOSTNAME_CFG01 }} |
| 136 | retry: {count: 1, delay: 5} |
| 137 | skip_fail: false |
| 138 | |
| 139 | - description: Run 'openssh' formula on cfg01 |
| 140 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 141 | -C 'I@salt:master' state.sls openssh; |
| 142 | salt --hard-crash --state-output=mixed --state-verbose=False |
| 143 | -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication |
Tatyana Leontovich | 1801312 | 2017-06-09 20:24:50 +0300 | [diff] [blame] | 144 | yes/' /etc/ssh/sshd_config && service ssh reload"; |
Tatyana Leontovich | d8bf14f | 2017-04-19 12:20:50 +0300 | [diff] [blame] | 145 | node_name: {{ HOSTNAME_CFG01 }} |
| 146 | retry: {count: 3, delay: 5} |
| 147 | skip_fail: false |
| 148 | |
| 149 | - description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962' |
| 150 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 151 | '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config" |
| 152 | node_name: {{ HOSTNAME_CFG01 }} |
| 153 | retry: {count: 1, delay: 1} |
| 154 | skip_fail: false |
| 155 | |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame] | 156 | - description: Run 'salt.master' formula on cfg01 |
Dennis Dmitriev | d9a4aed | 2017-07-27 09:17:17 +0300 | [diff] [blame] | 157 | cmd: timeout 120 salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls salt.master; |
Tatyana Leontovich | d8bf14f | 2017-04-19 12:20:50 +0300 | [diff] [blame] | 158 | node_name: {{ HOSTNAME_CFG01 }} |
Dennis Dmitriev | 4db5bf2 | 2017-05-13 19:31:17 +0300 | [diff] [blame] | 159 | retry: {count: 2, delay: 5} |
Dennis Dmitriev | 2d60c8e | 2017-05-12 18:34:01 +0300 | [diff] [blame] | 160 | skip_fail: false |
Tatyana Leontovich | d8bf14f | 2017-04-19 12:20:50 +0300 | [diff] [blame] | 161 | |
Tatyana Leontovich | d8bf14f | 2017-04-19 12:20:50 +0300 | [diff] [blame] | 162 | - description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated |
| 163 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 164 | -C 'I@salt:master' state.sls reclass |
| 165 | node_name: {{ HOSTNAME_CFG01 }} |
| 166 | retry: {count: 1, delay: 5} |
| 167 | skip_fail: false |
| 168 | |
| 169 | - description: Refresh pillars on all minions |
| 170 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar |
| 171 | node_name: {{ HOSTNAME_CFG01 }} |
| 172 | retry: {count: 1, delay: 5} |
| 173 | skip_fail: false |
| 174 | |
Tatyana Leontovich | d8bf14f | 2017-04-19 12:20:50 +0300 | [diff] [blame] | 175 | - description: Show reclass-salt --top |
Dennis Dmitriev | 4db5bf2 | 2017-05-13 19:31:17 +0300 | [diff] [blame] | 176 | cmd: reclass-salt --top |
| 177 | node_name: {{ HOSTNAME_CFG01 }} |
| 178 | retry: {count: 1, delay: 5} |
| 179 | skip_fail: false |
| 180 | |
Tatyana Leontovich | 1801312 | 2017-06-09 20:24:50 +0300 | [diff] [blame] | 181 | - description: Sync all salt resources |
| 182 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all |
Tatyana Leontovich | d8bf14f | 2017-04-19 12:20:50 +0300 | [diff] [blame] | 183 | node_name: {{ HOSTNAME_CFG01 }} |
| 184 | retry: {count: 1, delay: 5} |
| 185 | skip_fail: false |
| 186 | |
Tatyana Leontovich | 1801312 | 2017-06-09 20:24:50 +0300 | [diff] [blame] | 187 | - description: Configure linux on master |
| 188 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system' |
| 189 | node_name: {{ HOSTNAME_CFG01 }} |
| 190 | retry: {count: 1, delay: 5} |
| 191 | skip_fail: false |
| 192 | |
| 193 | - description: Configure minion on master |
Dennis Dmitriev | 980db16 | 2017-07-27 09:40:01 +0300 | [diff] [blame] | 194 | cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False |
Tatyana Leontovich | 1801312 | 2017-06-09 20:24:50 +0300 | [diff] [blame] | 195 | -C 'I@salt:master' state.sls 'salt.minion' |
| 196 | node_name: {{ HOSTNAME_CFG01 }} |
| 197 | retry: {count: 3, delay: 10} |
| 198 | skip_fail: false |
Tatyana Leontovich | d8bf14f | 2017-04-19 12:20:50 +0300 | [diff] [blame] | 199 | |
| 200 | # Bootstrap all nodes |
| 201 | |
Dennis Dmitriev | a9e6da8 | 2017-04-26 23:23:22 +0300 | [diff] [blame] | 202 | - description: Configure linux on other nodes |
Tatyana Leontovich | 1801312 | 2017-06-09 20:24:50 +0300 | [diff] [blame] | 203 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls 'linux' |
Tatyana Leontovich | d8bf14f | 2017-04-19 12:20:50 +0300 | [diff] [blame] | 204 | node_name: {{ HOSTNAME_CFG01 }} |
| 205 | retry: {count: 1, delay: 5} |
| 206 | skip_fail: false |
| 207 | |
Tatyana Leontovich | d8bf14f | 2017-04-19 12:20:50 +0300 | [diff] [blame] | 208 | - description: Configure openssh on all nodes |
Tatyana Leontovich | 1801312 | 2017-06-09 20:24:50 +0300 | [diff] [blame] | 209 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls openssh; |
| 210 | salt --hard-crash --state-output=mixed --state-verbose=False |
| 211 | -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication |
| 212 | yes/' /etc/ssh/sshd_config && service ssh reload" |
Tatyana Leontovich | d8bf14f | 2017-04-19 12:20:50 +0300 | [diff] [blame] | 213 | node_name: {{ HOSTNAME_CFG01 }} |
| 214 | retry: {count: 1, delay: 5} |
| 215 | skip_fail: false |
| 216 | |
Dennis Dmitriev | a9e6da8 | 2017-04-26 23:23:22 +0300 | [diff] [blame] | 217 | - description: Configure salt.minion on other nodes |
Dennis Dmitriev | 980db16 | 2017-07-27 09:40:01 +0300 | [diff] [blame] | 218 | cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls salt.minion |
Tatyana Leontovich | d8bf14f | 2017-04-19 12:20:50 +0300 | [diff] [blame] | 219 | node_name: {{ HOSTNAME_CFG01 }} |
| 220 | retry: {count: 3, delay: 5} |
| 221 | skip_fail: false |
| 222 | |
| 223 | - description: Check salt minion versions on slaves |
| 224 | cmd: salt '*' test.version |
| 225 | node_name: {{ HOSTNAME_CFG01 }} |
| 226 | retry: {count: 1, delay: 5} |
| 227 | skip_fail: false |
| 228 | |
| 229 | - description: Check salt top states on nodes |
| 230 | cmd: salt '*' state.show_top |
| 231 | node_name: {{ HOSTNAME_CFG01 }} |
| 232 | retry: {count: 1, delay: 5} |
| 233 | skip_fail: false |
| 234 | |
| 235 | - description: Configure ntp and rsyslog on nodes |
Tatyana Leontovich | 1801312 | 2017-06-09 20:24:50 +0300 | [diff] [blame] | 236 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog |
Tatyana Leontovich | d8bf14f | 2017-04-19 12:20:50 +0300 | [diff] [blame] | 237 | node_name: {{ HOSTNAME_CFG01 }} |
| 238 | retry: {count: 1, delay: 10} |
| 239 | skip_fail: false |
| 240 | |
Dennis Dmitriev | 99b26fe | 2017-04-26 12:34:44 +0300 | [diff] [blame] | 241 | - description: Hack gtw node |
| 242 | cmd: salt 'gtw*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.110/24 dev ens4; ip addr flush dev ens4"; |
| 243 | node_name: {{ HOSTNAME_CFG01 }} |
| 244 | retry: {count: 1, delay: 10} |
| 245 | skip_fail: false |
| 246 | |
| 247 | - description: Hack cmp01 node |
| 248 | cmd: salt 'cmp01*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.105/24 dev ens4; ip addr flush dev ens4"; |
| 249 | node_name: {{ HOSTNAME_CFG01 }} |
| 250 | retry: {count: 1, delay: 10} |
| 251 | skip_fail: false |
| 252 | |
| 253 | - description: Hack cmp02 node |
| 254 | cmd: salt 'cmp02*' cmd.run "ip addr del {{ IPV4_NET_CONTROL_PREFIX }}.106/24 dev ens4; ip addr flush dev ens4"; |
| 255 | node_name: {{ HOSTNAME_CFG01 }} |
| 256 | retry: {count: 1, delay: 10} |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame^] | 257 | skip_fail: false |