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') %} |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 5 | # Other salt model repository parameters see in shared-salt.yaml |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +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 %} |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 8 | |
Tatyana Leontovich | 508d0cb | 2017-05-26 15:46:24 +0300 | [diff] [blame] | 9 | # Install salt to the config node |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 10 | |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 11 | - description: Installing salt master on cfg01 |
Tatyana Leontovich | 508d0cb | 2017-05-26 15:46:24 +0300 | [diff] [blame] | 12 | 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] | 13 | node_name: {{ HOSTNAME_CFG01 }} |
| 14 | retry: {count: 1, delay: 1} |
| 15 | skip_fail: false |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 16 | |
| 17 | - description: Configure salt-master on cfg01 |
| 18 | cmd: | |
| 19 | cat << 'EOF' >> /etc/salt/master.d/master.conf |
| 20 | file_roots: |
| 21 | base: |
| 22 | - /usr/share/salt-formulas/env |
| 23 | pillar_opts: False |
| 24 | open_mode: True |
| 25 | reclass: &reclass |
| 26 | storage_type: yaml_fs |
| 27 | inventory_base_uri: /srv/salt/reclass |
| 28 | ext_pillar: |
| 29 | - reclass: *reclass |
| 30 | master_tops: |
| 31 | reclass: *reclass |
| 32 | EOF |
| 33 | node_name: {{ HOSTNAME_CFG01 }} |
| 34 | retry: {count: 1, delay: 1} |
| 35 | skip_fail: false |
| 36 | |
| 37 | - description: Configure GIT settings and certificates |
| 38 | cmd: touch /root/.git_trusted_certs.pem; |
Matthew Mosesohn | d0632b8 | 2017-05-30 17:51:30 +0300 | [diff] [blame] | 39 | for server in github.com; do |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 40 | openssl s_client -showcerts -connect $server:443 </dev/null |
| 41 | | openssl x509 -outform PEM |
| 42 | >> /root/.git_trusted_certs.pem; |
| 43 | done; |
| 44 | HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem; |
| 45 | HOME=/root git config --global user.email "tcp-qa@example.com"; |
| 46 | HOME=/root git config --global user.name "TCP QA"; |
| 47 | node_name: {{ HOSTNAME_CFG01 }} |
| 48 | retry: {count: 1, delay: 1} |
| 49 | skip_fail: false |
| 50 | |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 51 | - description: Clone reclass models with submodules |
| 52 | cmd: | |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 53 | {{ SHARED.MACRO_CLONE_RECLASS_MODELS() }} |
Sergii Golovatiuk | 44a4352 | 2017-07-20 12:55:13 +0200 | [diff] [blame] | 54 | # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded |
Sergii Golovatiuk | f03899c | 2017-05-30 12:12:00 +0200 | [diff] [blame] | 55 | find /srv/salt/reclass/ -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} + |
Sergii Golovatiuk | 01e3a2d | 2017-08-02 11:28:26 +0200 | [diff] [blame] | 56 | # Show the changes to the console |
| 57 | cd /srv/salt/reclass/; git diff |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +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 | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 67 | which wget > /dev/null || (apt-get update; apt-get install -y wget); |
| 68 | echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list; |
| 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 | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 73 | echo -e "\nInstalling all required salt formulas\n"; |
| 74 | eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}"; |
| 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 | |
| 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'] }} |
| 102 | cmd: | |
| 103 | [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d; |
| 104 | cat << "EOF" >> /etc/salt/minion.d/minion.conf |
| 105 | id: {{ ssh['node_name'] }} |
| 106 | master: {{ config.salt.salt_master_host }} |
| 107 | EOF |
| 108 | eatmydata apt-get install -y salt-minion; |
| 109 | echo "Check for system info and metadata availability ..."; |
Sergii Golovatiuk | f648ad4 | 2017-06-23 13:39:11 +0200 | [diff] [blame] | 110 | salt-call --hard-crash --no-color grains.items; |
| 111 | salt-call --hard-crash --no-color pillar.items; |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 112 | node_name: {{ ssh['node_name'] }} |
| 113 | retry: {count: 1, delay: 1} |
| 114 | skip_fail: false |
| 115 | {% endfor %} |
| 116 | |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 117 | - description: Accept salt keys from all the nodes |
| 118 | cmd: salt-key -A -y |
| 119 | node_name: {{ HOSTNAME_CFG01 }} |
| 120 | retry: {count: 1, delay: 5} |
| 121 | skip_fail: true |
| 122 | |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 123 | - description: Configure salt adoptors on cfg01 |
| 124 | cmd: | |
| 125 | ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt; |
| 126 | chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py |
| 127 | node_name: {{ HOSTNAME_CFG01 }} |
| 128 | retry: {count: 1, delay: 1} |
| 129 | skip_fail: false |
| 130 | |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 131 | # Prepare salt services and nodes settings |
| 132 | - description: Run 'linux' formula on cfg01 |
| 133 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 134 | -C 'I@salt:master' state.sls linux; |
| 135 | node_name: {{ HOSTNAME_CFG01 }} |
Sergii Golovatiuk | 01e3a2d | 2017-08-02 11:28:26 +0200 | [diff] [blame] | 136 | retry: {count: 2, delay: 5} |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 137 | skip_fail: false |
| 138 | |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 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 |
| 144 | yes/' /etc/ssh/sshd_config && service ssh restart"; |
| 145 | node_name: {{ HOSTNAME_CFG01 }} |
| 146 | retry: {count: 3, delay: 5} |
| 147 | skip_fail: false |
| 148 | |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 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 | |
| 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 |
Sergii Golovatiuk | 8f679ab | 2017-06-02 13:13:53 +0200 | [diff] [blame] | 158 | -C 'I@salt:master' state.sls salt.master; |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 159 | node_name: {{ HOSTNAME_CFG01 }} |
| 160 | retry: {count: 2, delay: 5} |
| 161 | skip_fail: false |
| 162 | |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +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 | |
Sergii Golovatiuk | 5b659d4 | 2017-05-26 17:38:06 +0200 | [diff] [blame] | 176 | - description: Show reclass-salt --top |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 177 | cmd: reclass-salt --top |
| 178 | node_name: {{ HOSTNAME_CFG01 }} |
| 179 | retry: {count: 1, delay: 5} |
| 180 | skip_fail: false |
| 181 | |
Sergii Golovatiuk | 8f679ab | 2017-06-02 13:13:53 +0200 | [diff] [blame] | 182 | - description: Sync all salt resources |
| 183 | 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] | 184 | node_name: {{ HOSTNAME_CFG01 }} |
| 185 | retry: {count: 1, delay: 5} |
| 186 | skip_fail: false |
| 187 | |
Sergii Golovatiuk | 8f679ab | 2017-06-02 13:13:53 +0200 | [diff] [blame] | 188 | - description: Configure linux on master |
| 189 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 190 | -C 'I@salt:master' state.sls 'linux.system' |
| 191 | node_name: {{ HOSTNAME_CFG01 }} |
| 192 | retry: {count: 1, delay: 5} |
| 193 | skip_fail: false |
| 194 | |
| 195 | - description: Configure minion on master |
Sergii Golovatiuk | f648ad4 | 2017-06-23 13:39:11 +0200 | [diff] [blame] | 196 | cmd: salt-call --hard-crash -l debug state.sls 'salt.minion' |
Sergii Golovatiuk | 8f679ab | 2017-06-02 13:13:53 +0200 | [diff] [blame] | 197 | node_name: {{ HOSTNAME_CFG01 }} |
| 198 | retry: {count: 3, delay: 10} |
| 199 | skip_fail: false |
| 200 | |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 201 | # Bootstrap all nodes |
| 202 | |
Tatyana Leontovich | 508d0cb | 2017-05-26 15:46:24 +0300 | [diff] [blame] | 203 | - description: Configure linux on other nodes |
Sergii Golovatiuk | 8f679ab | 2017-06-02 13:13:53 +0200 | [diff] [blame] | 204 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 205 | -C 'I@linux:system' state.sls 'linux' |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 206 | node_name: {{ HOSTNAME_CFG01 }} |
Sergii Golovatiuk | 17ef149 | 2017-05-29 19:54:03 +0200 | [diff] [blame] | 207 | retry: {count: 3, delay: 5} |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 208 | skip_fail: false |
| 209 | |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 210 | - description: Configure openssh on all nodes |
Sergii Golovatiuk | 8f679ab | 2017-06-02 13:13:53 +0200 | [diff] [blame] | 211 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 212 | -C 'I@linux:system' state.sls openssh; |
| 213 | salt --hard-crash --state-output=mixed --state-verbose=False |
| 214 | -C 'I@linux:system' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication |
| 215 | yes/' /etc/ssh/sshd_config && service ssh reload" |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 216 | node_name: {{ HOSTNAME_CFG01 }} |
| 217 | retry: {count: 1, delay: 5} |
| 218 | skip_fail: false |
| 219 | |
Sergii Golovatiuk | 8f679ab | 2017-06-02 13:13:53 +0200 | [diff] [blame] | 220 | - description: Configure salt.minion on all nodes |
Sergii Golovatiuk | 01e3a2d | 2017-08-02 11:28:26 +0200 | [diff] [blame] | 221 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
Sergii Golovatiuk | 8f679ab | 2017-06-02 13:13:53 +0200 | [diff] [blame] | 222 | -C 'I@linux:system' state.sls salt.minion |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 223 | node_name: {{ HOSTNAME_CFG01 }} |
Sergii Golovatiuk | 01e3a2d | 2017-08-02 11:28:26 +0200 | [diff] [blame] | 224 | retry: {count: 2, delay: 5} |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 225 | skip_fail: false |
| 226 | |
Sergii Golovatiuk | 8f679ab | 2017-06-02 13:13:53 +0200 | [diff] [blame] | 227 | - description: Configure ntp and rsyslog on nodes |
| 228 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 229 | -C 'I@linux:system' state.sls ntp,rsyslog |
| 230 | node_name: {{ HOSTNAME_CFG01 }} |
Sergii Golovatiuk | 01e3a2d | 2017-08-02 11:28:26 +0200 | [diff] [blame] | 231 | retry: {count: 2, delay: 10} |
Sergii Golovatiuk | 8f679ab | 2017-06-02 13:13:53 +0200 | [diff] [blame] | 232 | skip_fail: false |
| 233 | |
Tatyana Leontovich | bb6d1a7 | 2017-05-17 14:10:38 +0300 | [diff] [blame] | 234 | - description: Check salt minion versions on slaves |
| 235 | cmd: salt '*' test.version |
| 236 | node_name: {{ HOSTNAME_CFG01 }} |
| 237 | retry: {count: 1, delay: 5} |
| 238 | skip_fail: false |
| 239 | |
| 240 | - description: Check salt top states on nodes |
| 241 | cmd: salt '*' state.show_top |
| 242 | node_name: {{ HOSTNAME_CFG01 }} |
| 243 | retry: {count: 1, delay: 5} |
| 244 | skip_fail: false |