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