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 %} |
| 3 | |
| 4 | {% set SALT_MODELS_REPOSITORY = os_env('SALT_MODELS_REPOSITORY','https://gerrit.mcp.mirantis.net/salt-models/mcp-virtual-lab') %} |
Valentyn Yakovlev | 08acf9f | 2017-06-07 14:02:36 +0300 | [diff] [blame] | 5 | {% set SALT_MODELS_BRANCH = os_env('SALT_MODELS_BRANCH','master') %} |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 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 %} |
Sergii Golovatiuk | f03899c | 2017-05-30 12:12:00 +0200 | [diff] [blame] | 14 | {% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('public-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')) %} |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 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 | |
Tatyana Leontovich | 508d0cb | 2017-05-26 15:46:24 +0300 | [diff] [blame] | 20 | # Install salt to the config node |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 21 | - description: Installing salt master on cfg01 |
Tatyana Leontovich | 508d0cb | 2017-05-26 15:46:24 +0300 | [diff] [blame] | 22 | cmd: apt-get install -y reclass git; apt-get install -y salt-master |
Sergii Golovatiuk | c504a39 | 2017-05-22 21:41:06 +0200 | [diff] [blame] | 23 | node_name: {{ HOSTNAME_CFG01 }} |
| 24 | retry: {count: 1, delay: 1} |
| 25 | skip_fail: false |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 26 | |
| 27 | - description: Configure salt-master on cfg01 |
| 28 | cmd: | |
| 29 | cat << 'EOF' >> /etc/salt/master.d/master.conf |
| 30 | file_roots: |
| 31 | base: |
| 32 | - /usr/share/salt-formulas/env |
| 33 | pillar_opts: False |
| 34 | open_mode: True |
| 35 | reclass: &reclass |
| 36 | storage_type: yaml_fs |
| 37 | inventory_base_uri: /srv/salt/reclass |
| 38 | ext_pillar: |
| 39 | - reclass: *reclass |
| 40 | master_tops: |
| 41 | reclass: *reclass |
| 42 | EOF |
| 43 | node_name: {{ HOSTNAME_CFG01 }} |
| 44 | retry: {count: 1, delay: 1} |
| 45 | skip_fail: false |
| 46 | |
| 47 | - description: Configure GIT settings and certificates |
| 48 | cmd: touch /root/.git_trusted_certs.pem; |
Matthew Mosesohn | d0632b8 | 2017-05-30 17:51:30 +0300 | [diff] [blame] | 49 | for server in github.com; do |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 50 | openssl s_client -showcerts -connect $server:443 </dev/null |
| 51 | | openssl x509 -outform PEM |
| 52 | >> /root/.git_trusted_certs.pem; |
| 53 | done; |
| 54 | HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem; |
| 55 | HOME=/root git config --global user.email "tcp-qa@example.com"; |
| 56 | HOME=/root git config --global user.name "TCP QA"; |
| 57 | node_name: {{ HOSTNAME_CFG01 }} |
| 58 | retry: {count: 1, delay: 1} |
| 59 | skip_fail: false |
| 60 | |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 61 | - description: Clone reclass models with submodules |
| 62 | cmd: | |
| 63 | ssh-keyscan -H github.com >> ~/.ssh/known_hosts; |
Valentyn Yakovlev | 08acf9f | 2017-06-07 14:02:36 +0300 | [diff] [blame] | 64 | git clone -b {{ SALT_MODELS_BRANCH }} --recurse-submodules {{ SALT_MODELS_REPOSITORY }} /srv/salt/reclass; |
| 65 | pushd /srv/salt/reclass && git checkout {{ SALT_MODELS_COMMIT }} && popd; |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 66 | mkdir -p /srv/salt/reclass/classes/service; |
Sergii Golovatiuk | f03899c | 2017-05-30 12:12:00 +0200 | [diff] [blame] | 67 | |
| 68 | # Replace firstly to an intermediate value to avoid intersection between |
| 69 | # already replaced and replacing networks. |
| 70 | # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice: |
| 71 | # 192.168.10 -> 10.16.0 (generated network for admin) |
| 72 | # 10.16.0 -> <external network> |
| 73 | # So let's replace constant networks to the keywords, and then keywords to the desired networks. |
| 74 | find /srv/salt/reclass/ -type f -exec sed -i 's/192\.168\.10\./==IPV4_NET_ADMIN_PREFIX==/g' {} + |
| 75 | find /srv/salt/reclass/ -type f -exec sed -i 's/172\.16\.10\./==IPV4_NET_CONTROL_PREFIX==/g' {} + |
| 76 | |
| 77 | find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}./g' {} + |
| 78 | find /srv/salt/reclass/ -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}./g' {} + |
| 79 | |
| 80 | find /srv/salt/reclass/ -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} + |
| 81 | find /srv/salt/reclass/ -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} + |
| 82 | |
| 83 | # Disable checkouting the model from remote repository |
| 84 | cat << 'EOF' >> /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml |
| 85 | # local storage |
Sergii Golovatiuk | 8f679ab | 2017-06-02 13:13:53 +0200 | [diff] [blame^] | 86 | reclass: |
| 87 | storage: |
| 88 | data_source: |
| 89 | engine: local |
Sergii Golovatiuk | f03899c | 2017-05-30 12:12:00 +0200 | [diff] [blame] | 90 | EOF |
| 91 | |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 92 | node_name: {{ HOSTNAME_CFG01 }} |
| 93 | retry: {count: 1, delay: 1} |
| 94 | skip_fail: false |
| 95 | |
| 96 | - description: Configure reclass |
| 97 | cmd: | |
| 98 | FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas}; |
Tatyana Leontovich | eed70d7 | 2017-05-25 16:32:17 +0300 | [diff] [blame] | 99 | 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] | 100 | FORMULA_GPG=${FORMULA_GPG:-http://apt-mk.mirantis.com/public.gpg}; |
| 101 | which wget > /dev/null || (apt-get update; apt-get install -y wget); |
| 102 | echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list; |
| 103 | wget -O - "${FORMULA_GPG}" | apt-key add -; |
| 104 | apt-get clean; apt-get update; |
| 105 | [ ! -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] | 106 | 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 | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 107 | echo -e "\nInstalling all required salt formulas\n"; |
| 108 | eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}"; |
| 109 | for formula_service in "${formula_services[@]}"; do |
| 110 | echo -e "\nLink service metadata for formula ${formula_service} ...\n"; |
| 111 | [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service}; |
| 112 | done; |
| 113 | [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env; |
| 114 | [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd; |
| 115 | [ ! -d /etc/reclass ] && mkdir /etc/reclass; |
| 116 | |
| 117 | cat << 'EOF' >> /etc/reclass/reclass-config.yml |
| 118 | storage_type: yaml_fs |
| 119 | pretty_print: True |
| 120 | output: yaml |
| 121 | inventory_base_uri: /srv/salt/reclass |
| 122 | EOF |
| 123 | node_name: {{ HOSTNAME_CFG01 }} |
| 124 | retry: {count: 1, delay: 1} |
| 125 | skip_fail: false |
| 126 | |
| 127 | - description: Restart salt-master service |
| 128 | cmd: | |
| 129 | systemctl restart salt-master; |
| 130 | node_name: {{ HOSTNAME_CFG01 }} |
| 131 | retry: {count: 1, delay: 5} |
| 132 | skip_fail: false |
| 133 | |
| 134 | {% for ssh in config.underlay.ssh %} |
| 135 | - description: Configure salt-minion on {{ ssh['node_name'] }} |
| 136 | cmd: | |
| 137 | [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d; |
| 138 | cat << "EOF" >> /etc/salt/minion.d/minion.conf |
| 139 | id: {{ ssh['node_name'] }} |
| 140 | master: {{ config.salt.salt_master_host }} |
| 141 | EOF |
| 142 | eatmydata apt-get install -y salt-minion; |
| 143 | echo "Check for system info and metadata availability ..."; |
| 144 | salt-call --no-color grains.items; |
| 145 | salt-call --no-color pillar.items; |
| 146 | node_name: {{ ssh['node_name'] }} |
| 147 | retry: {count: 1, delay: 1} |
| 148 | skip_fail: false |
| 149 | {% endfor %} |
| 150 | |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 151 | - description: Accept salt keys from all the nodes |
| 152 | cmd: salt-key -A -y |
| 153 | node_name: {{ HOSTNAME_CFG01 }} |
| 154 | retry: {count: 1, delay: 5} |
| 155 | skip_fail: true |
| 156 | |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 157 | - description: Configure salt adoptors on cfg01 |
| 158 | cmd: | |
| 159 | ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt; |
| 160 | chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py |
| 161 | node_name: {{ HOSTNAME_CFG01 }} |
| 162 | retry: {count: 1, delay: 1} |
| 163 | skip_fail: false |
| 164 | |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 165 | # Prepare salt services and nodes settings |
| 166 | - description: Run 'linux' formula on cfg01 |
| 167 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 168 | -C 'I@salt:master' state.sls linux; |
| 169 | node_name: {{ HOSTNAME_CFG01 }} |
Sergii Golovatiuk | 17ef149 | 2017-05-29 19:54:03 +0200 | [diff] [blame] | 170 | retry: {count: 3, delay: 5} |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 171 | skip_fail: false |
| 172 | |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 173 | - description: Run 'openssh' formula on cfg01 |
| 174 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 175 | -C 'I@salt:master' state.sls openssh; |
| 176 | salt --hard-crash --state-output=mixed --state-verbose=False |
| 177 | -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication |
| 178 | yes/' /etc/ssh/sshd_config && service ssh restart"; |
| 179 | node_name: {{ HOSTNAME_CFG01 }} |
| 180 | retry: {count: 3, delay: 5} |
| 181 | skip_fail: false |
| 182 | |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 183 | - description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962' |
| 184 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 185 | '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config" |
| 186 | node_name: {{ HOSTNAME_CFG01 }} |
| 187 | retry: {count: 1, delay: 1} |
| 188 | skip_fail: false |
| 189 | |
| 190 | - description: Run 'salt.master' formula on cfg01 |
| 191 | cmd: timeout 120 salt --hard-crash --state-output=mixed --state-verbose=False |
Sergii Golovatiuk | 8f679ab | 2017-06-02 13:13:53 +0200 | [diff] [blame^] | 192 | -C 'I@salt:master' state.sls salt.master; |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 193 | node_name: {{ HOSTNAME_CFG01 }} |
| 194 | retry: {count: 2, delay: 5} |
| 195 | skip_fail: false |
| 196 | |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 197 | - description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated |
| 198 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 199 | -C 'I@salt:master' state.sls reclass |
| 200 | node_name: {{ HOSTNAME_CFG01 }} |
| 201 | retry: {count: 1, delay: 5} |
| 202 | skip_fail: false |
| 203 | |
| 204 | - description: Refresh pillars on all minions |
| 205 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar |
| 206 | node_name: {{ HOSTNAME_CFG01 }} |
| 207 | retry: {count: 1, delay: 5} |
| 208 | skip_fail: false |
| 209 | |
Sergii Golovatiuk | 5b659d4 | 2017-05-26 17:38:06 +0200 | [diff] [blame] | 210 | - description: Show reclass-salt --top |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 211 | cmd: reclass-salt --top |
| 212 | node_name: {{ HOSTNAME_CFG01 }} |
| 213 | retry: {count: 1, delay: 5} |
| 214 | skip_fail: false |
| 215 | |
Sergii Golovatiuk | 8f679ab | 2017-06-02 13:13:53 +0200 | [diff] [blame^] | 216 | - description: Sync all salt resources |
| 217 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 218 | node_name: {{ HOSTNAME_CFG01 }} |
| 219 | retry: {count: 1, delay: 5} |
| 220 | skip_fail: false |
| 221 | |
Sergii Golovatiuk | 8f679ab | 2017-06-02 13:13:53 +0200 | [diff] [blame^] | 222 | - description: Configure linux on master |
| 223 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 224 | -C 'I@salt:master' state.sls 'linux.system' |
| 225 | node_name: {{ HOSTNAME_CFG01 }} |
| 226 | retry: {count: 1, delay: 5} |
| 227 | skip_fail: false |
| 228 | |
| 229 | - description: Configure minion on master |
| 230 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 231 | -C 'I@salt:master' state.sls 'salt.minion' |
| 232 | node_name: {{ HOSTNAME_CFG01 }} |
| 233 | retry: {count: 3, delay: 10} |
| 234 | skip_fail: false |
| 235 | |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 236 | # Bootstrap all nodes |
| 237 | |
Tatyana Leontovich | 508d0cb | 2017-05-26 15:46:24 +0300 | [diff] [blame] | 238 | - description: Configure linux on other nodes |
Sergii Golovatiuk | 8f679ab | 2017-06-02 13:13:53 +0200 | [diff] [blame^] | 239 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 240 | -C 'I@linux:system' state.sls 'linux' |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 241 | node_name: {{ HOSTNAME_CFG01 }} |
Sergii Golovatiuk | 17ef149 | 2017-05-29 19:54:03 +0200 | [diff] [blame] | 242 | retry: {count: 3, delay: 5} |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 243 | skip_fail: false |
| 244 | |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 245 | - description: Configure openssh on all nodes |
Sergii Golovatiuk | 8f679ab | 2017-06-02 13:13:53 +0200 | [diff] [blame^] | 246 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 247 | -C 'I@linux:system' state.sls openssh; |
| 248 | salt --hard-crash --state-output=mixed --state-verbose=False |
| 249 | -C 'I@linux:system' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication |
| 250 | yes/' /etc/ssh/sshd_config && service ssh reload" |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 251 | node_name: {{ HOSTNAME_CFG01 }} |
| 252 | retry: {count: 1, delay: 5} |
| 253 | skip_fail: false |
| 254 | |
Sergii Golovatiuk | 8f679ab | 2017-06-02 13:13:53 +0200 | [diff] [blame^] | 255 | - description: Configure salt.minion on all nodes |
| 256 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 257 | -C 'I@linux:system' state.sls salt.minion |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 258 | node_name: {{ HOSTNAME_CFG01 }} |
| 259 | retry: {count: 3, delay: 5} |
| 260 | skip_fail: false |
| 261 | |
Sergii Golovatiuk | 8f679ab | 2017-06-02 13:13:53 +0200 | [diff] [blame^] | 262 | - description: Configure ntp and rsyslog on nodes |
| 263 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 264 | -C 'I@linux:system' state.sls ntp,rsyslog |
| 265 | node_name: {{ HOSTNAME_CFG01 }} |
| 266 | retry: {count: 1, delay: 10} |
| 267 | skip_fail: false |
| 268 | |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 269 | - description: Check salt minion versions on slaves |
| 270 | cmd: salt '*' test.version |
| 271 | node_name: {{ HOSTNAME_CFG01 }} |
| 272 | retry: {count: 1, delay: 5} |
| 273 | skip_fail: false |
| 274 | |
| 275 | - description: Check salt top states on nodes |
| 276 | cmd: salt '*' state.show_top |
| 277 | node_name: {{ HOSTNAME_CFG01 }} |
| 278 | retry: {count: 1, delay: 5} |
| 279 | skip_fail: false |