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