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