Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 1 | {# Collection of common macroses shared across different deployments #} |
| 2 | |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 3 | {% set SALT_MODELS_BRANCH = os_env('SALT_MODELS_BRANCH','master') %} |
| 4 | {% set SALT_MODELS_COMMIT = os_env('SALT_MODELS_COMMIT','master') %} |
| 5 | {# Reference to a patch that should be applied to the model if required, for example: export SALT_MODELS_REF_CHANGE=refs/changes/19/7219/12 #} |
| 6 | {% set SALT_MODELS_REF_CHANGE = os_env('SALT_MODELS_REF_CHANGE', '') %} |
| 7 | {# Pin to a specified commit in salt-models/reclass-system #} |
Dmitry Tyzhnenko | 778515f | 2017-08-25 14:52:54 +0300 | [diff] [blame] | 8 | {% set SALT_MODELS_SYSTEM_REPOSITORY = os_env('SALT_MODELS_SYSTEM_REPOSITORY','https://gerrit.mcp.mirantis.net/salt-models/reclass-system') %} |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 9 | {% set SALT_MODELS_SYSTEM_COMMIT = os_env('SALT_MODELS_SYSTEM_COMMIT','') %} |
Dmitry Tyzhnenko | 778515f | 2017-08-25 14:52:54 +0300 | [diff] [blame] | 10 | {% set SALT_MODELS_SYSTEM_REF_CHANGE = os_env('SALT_MODELS_SYSTEM_REF_CHANGE','') %} |
sgudz | 4d816eb | 2017-11-13 11:58:05 +0200 | [diff] [blame] | 11 | {% set COOKIECUTTER_REF_CHANGE = os_env('COOKIECUTTER_REF_CHANGE','') %} |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 12 | |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 13 | {% set REPOSITORY_SUITE = os_env('REPOSITORY_SUITE', 'testing') %} |
| 14 | |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 15 | {# Address pools for reclass cluster model are taken in the following order: |
| 16 | # 1. environment variables, |
| 17 | # 2. config.underlay.address_pools based on fuel-devops address pools |
| 18 | # (see generated '.ini' file after underlay is created), |
| 19 | # 3. defaults #} |
| 20 | {% set address_pools = config.underlay.address_pools %} |
| 21 | {% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('admin-pool01', '192.168.10.0/24')) %} |
| 22 | {% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '172.16.10.0/24')) %} |
| 23 | {% set IPV4_NET_TENANT = os_env('IPV4_NET_TENANT', address_pools.get('tenant-pool01', '10.1.0.0/24')) %} |
| 24 | {% set IPV4_NET_EXTERNAL = os_env('IPV4_NET_EXTERNAL', address_pools.get('external-pool01', '10.16.0.0/24')) %} |
| 25 | {% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %} |
| 26 | {% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %} |
| 27 | {% set IPV4_NET_TENANT_PREFIX = '.'.join(IPV4_NET_TENANT.split('.')[0:3]) %} |
| 28 | {% set IPV4_NET_EXTERNAL_PREFIX = '.'.join(IPV4_NET_EXTERNAL.split('.')[0:3]) %} |
| 29 | |
Victor Ryzhenkin | 4e077ad | 2017-08-10 13:42:11 +0400 | [diff] [blame] | 30 | {# Format for formula replacement: |
| 31 | # space separated string: |
| 32 | # export SALT_FORMULAS_REFS='apache:refs/changes/xxxx kubernetes:refs/changes/xxxx' #} |
| 33 | |
| 34 | {% set SALT_FORMULAS_REFS = os_env('SALT_FORMULAS_REFS', '') %} |
| 35 | {% set SALT_FORMULAS_REPO = os_env('SALT_FORMULAS_REPO', 'https://gerrit.mcp.mirantis.net/salt-formulas') %} |
| 36 | |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 37 | |
| 38 | {%- macro MACRO_INSTALL_SALT_MASTER() %} |
| 39 | {######################################} |
| 40 | - description: Installing salt master on cfg01 |
| 41 | cmd: eatmydata apt-get install -y reclass git salt-master |
| 42 | node_name: {{ HOSTNAME_CFG01 }} |
| 43 | retry: {count: 1, delay: 1} |
| 44 | skip_fail: false |
| 45 | |
| 46 | - description: Configure salt-master on cfg01 |
| 47 | cmd: | |
| 48 | cat << 'EOF' >> /etc/salt/master.d/master.conf |
| 49 | file_roots: |
| 50 | base: |
| 51 | - /usr/share/salt-formulas/env |
| 52 | pillar_opts: False |
| 53 | open_mode: True |
| 54 | reclass: &reclass |
| 55 | storage_type: yaml_fs |
| 56 | inventory_base_uri: /srv/salt/reclass |
| 57 | ext_pillar: |
| 58 | - reclass: *reclass |
| 59 | master_tops: |
| 60 | reclass: *reclass |
| 61 | EOF |
| 62 | node_name: {{ HOSTNAME_CFG01 }} |
| 63 | retry: {count: 1, delay: 1} |
| 64 | skip_fail: false |
| 65 | |
| 66 | - description: Configure GIT settings and certificates |
Dennis Dmitriev | 3e731a4 | 2017-08-30 17:12:59 +0300 | [diff] [blame] | 67 | cmd: | |
| 68 | set -e; |
| 69 | touch /root/.git_trusted_certs.pem; |
| 70 | for server in github.com; do \ |
| 71 | openssl s_client -showcerts -connect $server:443 </dev/null \ |
| 72 | | openssl x509 -outform PEM \ |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 73 | >> /root/.git_trusted_certs.pem; |
| 74 | done; |
| 75 | HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem; |
| 76 | HOME=/root git config --global user.email "tcp-qa@example.com"; |
| 77 | HOME=/root git config --global user.name "TCP QA"; |
| 78 | node_name: {{ HOSTNAME_CFG01 }} |
| 79 | retry: {count: 1, delay: 1} |
| 80 | skip_fail: false |
| 81 | {%- endmacro %} |
| 82 | |
| 83 | |
| 84 | {%- macro MACRO_CLONE_RECLASS_MODELS(IS_CONTRAIL_LAB=false) %} |
| 85 | {############################################################} |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 86 | {# Creates a 'cluster' model from cookiecutter-templates and 'environment' model from uploaded template #} |
| 87 | |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 88 | - description: Clone reclass models with submodules |
| 89 | cmd: | |
Dennis Dmitriev | 3e731a4 | 2017-08-30 17:12:59 +0300 | [diff] [blame] | 90 | set -e; |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 91 | ssh-keyscan -H github.com >> ~/.ssh/known_hosts; |
Tatyana Leontovich | 4416273 | 2017-08-28 12:36:00 +0300 | [diff] [blame] | 92 | export GIT_SSL_NO_VERIFY=true; git clone -b {{ SALT_MODELS_BRANCH }} --recurse-submodules {{ SALT_MODELS_REPOSITORY }} /srv/salt/reclass; |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 93 | pushd /srv/salt/reclass && \ |
| 94 | {%- if SALT_MODELS_REF_CHANGE != '' %} |
| 95 | {%- for item in SALT_MODELS_REF_CHANGE.split(" ") %} |
| 96 | git fetch {{ SALT_MODELS_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD && \ |
| 97 | {%- endfor %} |
| 98 | {%- elif SALT_MODELS_COMMIT != 'master' %} |
| 99 | git checkout {{ SALT_MODELS_COMMIT }} && \ |
| 100 | {%- endif %} |
| 101 | {%- if SALT_MODELS_SYSTEM_COMMIT != '' %} |
| 102 | pushd classes/system/ && \ |
| 103 | git checkout {{ SALT_MODELS_SYSTEM_COMMIT }} && \ |
| 104 | popd && \ |
sgudz | 4d816eb | 2017-11-13 11:58:05 +0200 | [diff] [blame] | 105 | {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %} |
Dmitry Tyzhnenko | 778515f | 2017-08-25 14:52:54 +0300 | [diff] [blame] | 106 | pushd classes/system/ && \ |
| 107 | {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %} |
| 108 | git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD && \ |
| 109 | {%- endfor %} |
| 110 | popd && \ |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 111 | {%- else %} |
| 112 | git submodule update --init --recursive && \ |
| 113 | {%- endif %} |
| 114 | popd; |
| 115 | mkdir -p /srv/salt/reclass/classes/service; |
Dennis Dmitriev | a14f556 | 2017-10-02 12:59:53 +0300 | [diff] [blame] | 116 | rm -rf /srv/salt/reclass/nodes/ # For backward compatibility. New cfg node will be regenerated here |
Dennis Dmitriev | b2e78be | 2017-09-26 23:25:24 +0300 | [diff] [blame] | 117 | mkdir -p /srv/salt/reclass/nodes/_generated/; |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 118 | |
| 119 | # Replace firstly to an intermediate value to avoid intersection between |
| 120 | # already replaced and replacing networks. |
| 121 | # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice: |
| 122 | # 192.168.10 -> 10.16.0 (generated network for admin) |
| 123 | # 10.16.0 -> <external network> |
| 124 | # So let's replace constant networks to the keywords, and then keywords to the desired networks. |
Dennis Dmitriev | 9d9ba9f | 2017-09-13 17:34:03 +0300 | [diff] [blame] | 125 | export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/" |
| 126 | find ${REPLACE_DIRS} -type f -exec sed -i 's/192\.168\.10\./==IPV4_NET_ADMIN_PREFIX==/g' {} + |
| 127 | find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.16\.10\./==IPV4_NET_CONTROL_PREFIX==/g' {} + |
| 128 | find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.1\.0\./==IPV4_NET_TENANT_PREFIX==/g' {} + |
| 129 | find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.16\.0\./==IPV4_NET_EXTERNAL_PREFIX==/g' {} + |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 130 | |
Dennis Dmitriev | 9d9ba9f | 2017-09-13 17:34:03 +0300 | [diff] [blame] | 131 | find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}./g' {} + |
| 132 | find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}./g' {} + |
| 133 | find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}./g' {} + |
| 134 | find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}./g' {} + |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 135 | |
Dennis Dmitriev | 9d9ba9f | 2017-09-13 17:34:03 +0300 | [diff] [blame] | 136 | find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} + |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 137 | |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 138 | {%- if IS_CONTRAIL_LAB %} |
| 139 | # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded |
Dennis Dmitriev | 9d9ba9f | 2017-09-13 17:34:03 +0300 | [diff] [blame] | 140 | find ${REPLACE_DIRS} -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} + |
Tatyana Leontovich | 3424bf6 | 2017-09-15 12:13:54 +0300 | [diff] [blame] | 141 | find ${REPLACE_DIRS} -type f -exec sed -i 's/infra_config_deploy_address: 1.*/infra_config_deploy_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {} + |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 142 | {%- endif %} |
| 143 | |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 144 | # Disable checkouting the model from remote repository |
Dennis Dmitriev | b2e78be | 2017-09-26 23:25:24 +0300 | [diff] [blame] | 145 | cat << 'EOF' >> /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml |
| 146 | classes: |
| 147 | - cluster.{{ LAB_CONFIG_NAME }}.infra.config |
| 148 | parameters: |
| 149 | _param: |
| 150 | linux_system_codename: xenial |
| 151 | reclass_data_revision: master |
| 152 | linux: |
| 153 | system: |
| 154 | name: cfg01 |
| 155 | domain: {{ DOMAIN_NAME }} |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 156 | reclass: |
| 157 | storage: |
| 158 | data_source: |
| 159 | engine: local |
| 160 | EOF |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 161 | |
| 162 | # Show the changes to the console |
| 163 | cd /srv/salt/reclass/; git diff |
| 164 | node_name: {{ HOSTNAME_CFG01 }} |
| 165 | retry: {count: 1, delay: 1} |
| 166 | skip_fail: false |
| 167 | {%- endmacro %} |
| 168 | |
| 169 | |
sgudz | 8c888ec | 2017-10-02 15:29:23 +0300 | [diff] [blame] | 170 | {%- macro MACRO_GENERATE_COOKIECUTTER_MODEL(IS_CONTRAIL_LAB=false, CONTROL_VLAN=None, TENANT_VLAN=None) %} |
Dennis Dmitriev | 9f141af | 2017-09-28 17:21:01 +0300 | [diff] [blame] | 171 | {###################################################################} |
Dennis Dmitriev | 1c1352a | 2017-09-28 21:45:27 +0300 | [diff] [blame] | 172 | {%- set CLUSTER_CONTEXT_PATH = '/tmp/' + CLUSTER_CONTEXT_NAME %} |
Dennis Dmitriev | ccdc87a | 2017-09-28 17:43:54 +0300 | [diff] [blame] | 173 | - description: "[EXPERIMENTAL] Upload cookiecutter-templates context to {{ HOSTNAME_CFG01 }}" |
| 174 | upload: |
| 175 | local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/ |
| 176 | local_filename: {{ CLUSTER_CONTEXT_NAME }} |
Dennis Dmitriev | 1c1352a | 2017-09-28 21:45:27 +0300 | [diff] [blame] | 177 | remote_path: /tmp/ |
Dennis Dmitriev | ccdc87a | 2017-09-28 17:43:54 +0300 | [diff] [blame] | 178 | node_name: {{ HOSTNAME_CFG01 }} |
| 179 | |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 180 | - description: Create cluster model from cookiecutter templates |
| 181 | cmd: | |
| 182 | set -e; |
| 183 | pip install cookiecutter |
| 184 | export GIT_SSL_NO_VERIFY=true; git clone https://gerrit.mcp.mirantis.net/mk/cookiecutter-templates /tmp/cookiecutter-templates |
sgudz | 4d816eb | 2017-11-13 11:58:05 +0200 | [diff] [blame] | 185 | |
| 186 | {%- if COOKIECUTTER_REF_CHANGE != '' %} |
| 187 | pushd /tmp/cookiecutter-templates |
| 188 | git fetch https://gerrit.mcp.mirantis.net/mk/cookiecutter-templates {{ COOKIECUTTER_REF_CHANGE }} && git checkout FETCH_HEAD |
| 189 | popd |
| 190 | {%- endif %} |
| 191 | |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 192 | mkdir -p /srv/salt/reclass/classes/cluster/ |
| 193 | mkdir -p /srv/salt/reclass/classes/system/ |
| 194 | mkdir -p /srv/salt/reclass/classes/service/ |
Dennis Dmitriev | a14f556 | 2017-10-02 12:59:53 +0300 | [diff] [blame] | 195 | rm -rf /srv/salt/reclass/nodes/ # For backward compatibility. New cfg node will be regenerated here |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 196 | mkdir -p /srv/salt/reclass/nodes/_generated |
| 197 | |
| 198 | # Override some context parameters |
| 199 | sed -i 's/cluster_name:.*/cluster_name: {{ LAB_CONFIG_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }} |
| 200 | sed -i 's/cluster_domain:.*/cluster_domain: {{ DOMAIN_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }} |
sgudz | 8c888ec | 2017-10-02 15:29:23 +0300 | [diff] [blame] | 201 | {%- if CONTROL_VLAN %} |
| 202 | sed -i 's/control_vlan:.*/control_vlan: {{ CONTROL_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }} |
| 203 | {%- endif %} |
| 204 | {%- if TENANT_VLAN %} |
| 205 | sed -i 's/tenant_vlan:.*/tenant_vlan: {{ TENANT_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }} |
| 206 | {%- endif %} |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 207 | |
| 208 | # Temporary workaround (with hardcoded address .90 -> .15) of bug https://mirantis.jira.com/browse/PROD-14377 |
sgudz | 8c888ec | 2017-10-02 15:29:23 +0300 | [diff] [blame] | 209 | # sed -i 's/salt_master_address:.*/salt_master_address: {{ IPV4_NET_CONTROL_PREFIX }}.15/g' {{ CLUSTER_CONTEXT_PATH }} |
| 210 | # sed -i 's/salt_master_management_address:.*/salt_master_management_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {{ CLUSTER_CONTEXT_PATH }} |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 211 | |
| 212 | # Replace firstly to an intermediate value to avoid intersection between |
| 213 | # already replaced and replacing networks. |
| 214 | # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice: |
| 215 | # 192.168.10 -> 10.16.0 (generated network for admin) |
| 216 | # 10.16.0 -> <external network> |
| 217 | # So let's replace constant networks to the keywords, and then keywords to the desired networks. |
| 218 | sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }} |
| 219 | sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }} |
| 220 | sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }} |
| 221 | sed -i 's/172\.17\.16\./==IPV4_NET_EXTERNAL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }} |
| 222 | |
Dennis Dmitriev | 39e64bd | 2017-09-21 22:37:40 +0300 | [diff] [blame] | 223 | sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }} |
| 224 | sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }} |
| 225 | sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }} |
| 226 | sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ IPV4_NET_EXTERNAL_PREFIX }}./g' {{ CLUSTER_CONTEXT_PATH }} |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 227 | |
| 228 | for i in $(ls /tmp/cookiecutter-templates/cluster_product/); do |
| 229 | python /tmp/cookiecutter-templates/generate.py \ |
| 230 | --template /tmp/cookiecutter-templates/cluster_product/$i \ |
| 231 | --config-file {{ CLUSTER_CONTEXT_PATH }} \ |
| 232 | --output-dir /srv/salt/reclass/classes/cluster/; |
| 233 | done |
| 234 | |
| 235 | export GIT_SSL_NO_VERIFY=true; git clone https://gerrit.mcp.mirantis.net/salt-models/reclass-system /srv/salt/reclass/classes/system/ |
| 236 | |
| 237 | # Create the cfg01 node and disable checkouting the model from remote repository |
| 238 | cat << 'EOF' >> /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml |
| 239 | classes: |
| 240 | - system.openssh.server.team.all |
| 241 | - cluster.{{ LAB_CONFIG_NAME }}.infra.config |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 242 | EOF |
| 243 | |
| 244 | node_name: {{ HOSTNAME_CFG01 }} |
| 245 | retry: {count: 1, delay: 1} |
| 246 | skip_fail: false |
| 247 | |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 248 | - description: Modify generated model and reclass-system if necessary |
| 249 | cmd: | |
| 250 | set -e; |
| 251 | {%- if SALT_MODELS_SYSTEM_COMMIT != '' %} |
| 252 | pushd /srv/salt/reclass/classes/system/ |
| 253 | git checkout {{ SALT_MODELS_SYSTEM_COMMIT }} && \ |
| 254 | popd |
sgudz | 4d816eb | 2017-11-13 11:58:05 +0200 | [diff] [blame] | 255 | {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %} |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 256 | pushd /srv/salt/reclass/classes/system/ |
| 257 | {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %} |
| 258 | git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD |
| 259 | {%- endfor %} |
| 260 | popd |
| 261 | {%- endif %} |
| 262 | |
| 263 | export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/" |
| 264 | find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} + |
| 265 | |
| 266 | {%- if IS_CONTRAIL_LAB %} |
| 267 | # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded |
| 268 | find ${REPLACE_DIRS} -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} + |
| 269 | find ${REPLACE_DIRS} -type f -exec sed -i 's/infra_config_deploy_address: 1.*/infra_config_deploy_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {} + |
| 270 | {%- endif %} |
| 271 | |
| 272 | node_name: {{ HOSTNAME_CFG01 }} |
| 273 | retry: {count: 1, delay: 1} |
| 274 | skip_fail: false |
| 275 | {%- endmacro %} |
| 276 | |
| 277 | |
Dennis Dmitriev | 9f141af | 2017-09-28 17:21:01 +0300 | [diff] [blame] | 278 | {%- macro MACRO_GENERATE_AND_ENABLE_ENVIRONMENT_MODEL() %} |
| 279 | {########################################################} |
Dennis Dmitriev | ccdc87a | 2017-09-28 17:43:54 +0300 | [diff] [blame] | 280 | |
Dennis Dmitriev | 9e18de7 | 2017-10-11 18:14:36 +0300 | [diff] [blame] | 281 | - description: "[EXPERIMENTAL] Clone 'environment-template' repository to {{ HOSTNAME_CFG01 }}" |
| 282 | cmd: | |
| 283 | set -e; |
| 284 | mkdir -p /tmp/environment/; |
| 285 | export GIT_SSL_NO_VERIFY=true; git clone https://github.com/Mirantis/environment-template /tmp/environment/environment_template |
Dennis Dmitriev | 9f141af | 2017-09-28 17:21:01 +0300 | [diff] [blame] | 286 | node_name: {{ HOSTNAME_CFG01 }} |
| 287 | skip_fail: false |
| 288 | |
Dennis Dmitriev | ccdc87a | 2017-09-28 17:43:54 +0300 | [diff] [blame] | 289 | {%- for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %} |
Dennis Dmitriev | 9f141af | 2017-09-28 17:21:01 +0300 | [diff] [blame] | 290 | - description: "[EXPERIMENTAL] Upload environment inventory to {{ HOSTNAME_CFG01 }}" |
| 291 | upload: |
| 292 | local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/ |
| 293 | local_filename: {{ ENVIRONMENT_CONTEXT_NAME }} |
| 294 | remote_path: /tmp/environment/ |
| 295 | node_name: {{ HOSTNAME_CFG01 }} |
Dennis Dmitriev | ccdc87a | 2017-09-28 17:43:54 +0300 | [diff] [blame] | 296 | {%- endfor %} |
Dennis Dmitriev | 9f141af | 2017-09-28 17:21:01 +0300 | [diff] [blame] | 297 | |
| 298 | - description: "[EXPERIMENTAL] Remove linux.network.interface object from the cluster/system models and use fixed 'environment' model instead" |
| 299 | cmd: | |
| 300 | set -e; |
| 301 | apt-get -y install python-virtualenv python-pip build-essential python-dev libssl-dev; |
| 302 | pip install git+https://github.com/dis-xcom/reclass-tools; |
| 303 | reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/cluster/; |
| 304 | reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/system/; |
| 305 | reclass-tools del-key parameters.linux.network.interface /usr/share/salt-formulas/reclass/; |
| 306 | |
| 307 | if ! reclass-tools get-key 'classes' /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml | grep -q "environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}$"; then |
| 308 | reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}.reclass_datasource_local' /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml --merge ; |
| 309 | reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}' /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml --merge ; |
| 310 | fi; |
| 311 | |
| 312 | node_name: {{ HOSTNAME_CFG01 }} |
| 313 | retry: {count: 1, delay: 5} |
| 314 | skip_fail: false |
| 315 | |
Dennis Dmitriev | 222ba8e | 2017-11-11 00:06:02 +0200 | [diff] [blame^] | 316 | - description: "Workaround for PROD-15923: all keepalive instances must be named 'VIP'" |
Dennis Dmitriev | 9f141af | 2017-09-28 17:21:01 +0300 | [diff] [blame] | 317 | cmd: | |
| 318 | set -e; |
Dennis Dmitriev | 222ba8e | 2017-11-11 00:06:02 +0200 | [diff] [blame^] | 319 | find /srv/salt/reclass/classes/{system,cluster}/ -name '*.yml' -type f -exec sed -ri '/^ keepalived:/{:1;N;/\n instance:/!b1 {N; /\n [[:graph:]]+:/ { s/\n instance:\n [[:graph:]]+:/\n instance:\n VIP:/ } } }' {} + |
Dennis Dmitriev | 9f141af | 2017-09-28 17:21:01 +0300 | [diff] [blame] | 320 | |
| 321 | node_name: {{ HOSTNAME_CFG01 }} |
| 322 | retry: {count: 1, delay: 5} |
| 323 | skip_fail: false |
| 324 | |
| 325 | - description: "[EXPERIMENTAL] Create environment model for virtual environment" |
| 326 | cmd: | |
| 327 | set -e; |
Dennis Dmitriev | 9f141af | 2017-09-28 17:21:01 +0300 | [diff] [blame] | 328 | reclass-tools render --template-dir /tmp/environment/environment_template/ \ |
| 329 | --output-dir /srv/salt/reclass/classes/environment/ \ |
Dennis Dmitriev | d55a856 | 2017-09-28 22:12:09 +0300 | [diff] [blame] | 330 | {% for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %} --context /tmp/environment/{{ENVIRONMENT_CONTEXT_NAME}}{% endfor %} \ |
Dennis Dmitriev | 9f141af | 2017-09-28 17:21:01 +0300 | [diff] [blame] | 331 | --env-name {{ ENVIRONMENT_MODEL_INVENTORY_NAME }} |
| 332 | node_name: {{ HOSTNAME_CFG01 }} |
| 333 | retry: {count: 1, delay: 5} |
| 334 | skip_fail: false |
sgudz | 8c888ec | 2017-10-02 15:29:23 +0300 | [diff] [blame] | 335 | |
| 336 | - description: Modify generated model and reclass-system |
| 337 | cmd: | |
| 338 | export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/" |
| 339 | find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} + |
| 340 | node_name: {{ HOSTNAME_CFG01 }} |
| 341 | retry: {count: 1, delay: 1} |
| 342 | skip_fail: false |
| 343 | |
Dennis Dmitriev | 9f141af | 2017-09-28 17:21:01 +0300 | [diff] [blame] | 344 | {%- endmacro %} |
| 345 | |
| 346 | |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 347 | {%- macro MACRO_CONFIGURE_RECLASS(FORMULA_SERVICES='') %} |
| 348 | {#######################################################} |
| 349 | - description: Configure reclass |
| 350 | cmd: | |
Dennis Dmitriev | 3e731a4 | 2017-08-30 17:12:59 +0300 | [diff] [blame] | 351 | set -e; |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 352 | FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas}; |
| 353 | FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt}; |
| 354 | FORMULA_GPG=${FORMULA_GPG:-http://apt.mirantis.com/public.gpg}; |
| 355 | which wget > /dev/null || (apt-get update; apt-get install -y wget); |
| 356 | echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list; |
| 357 | wget -O - "${FORMULA_GPG}" | apt-key add -; |
| 358 | apt-get clean; apt-get update; |
| 359 | [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service; |
| 360 | declare -a formula_services=({{ FORMULA_SERVICES }}); |
| 361 | echo -e "\nInstalling all required salt formulas\n"; |
| 362 | eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}"; |
| 363 | for formula_service in "${formula_services[@]}"; do |
| 364 | echo -e "\nLink service metadata for formula ${formula_service} ...\n"; |
| 365 | [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service}; |
| 366 | done; |
| 367 | [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env; |
| 368 | [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd; |
| 369 | [ ! -d /etc/reclass ] && mkdir /etc/reclass; |
| 370 | |
| 371 | cat << 'EOF' >> /etc/reclass/reclass-config.yml |
| 372 | storage_type: yaml_fs |
| 373 | pretty_print: True |
| 374 | output: yaml |
| 375 | inventory_base_uri: /srv/salt/reclass |
| 376 | EOF |
| 377 | node_name: {{ HOSTNAME_CFG01 }} |
| 378 | retry: {count: 1, delay: 1} |
| 379 | skip_fail: false |
| 380 | |
| 381 | - description: "*Workaround* remove all cfg01 nodes except {{ HOSTNAME_CFG01 }} to not depend on other clusters in 'reclass --top'" |
| 382 | cmd: | |
| 383 | # Remove all other nodes except {{ HOSTNAME_CFG01 }} to not rely on them for 'reclass --top' |
| 384 | find /srv/salt/reclass/nodes/ -type f -not -name {{ HOSTNAME_CFG01 }}.yml -delete |
| 385 | node_name: {{ HOSTNAME_CFG01 }} |
| 386 | retry: {count: 1, delay: 5} |
| 387 | skip_fail: false |
| 388 | |
| 389 | - description: Configure salt adoptors on cfg01 |
| 390 | cmd: | |
| 391 | ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt; |
| 392 | chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py |
| 393 | node_name: {{ HOSTNAME_CFG01 }} |
| 394 | retry: {count: 1, delay: 1} |
| 395 | skip_fail: false |
| 396 | |
| 397 | - description: Show reclass-salt --top for cfg01 node |
| 398 | cmd: reclass-salt --top |
| 399 | node_name: {{ HOSTNAME_CFG01 }} |
| 400 | retry: {count: 1, delay: 5} |
| 401 | skip_fail: false |
| 402 | |
| 403 | - description: Restart salt-master service |
| 404 | cmd: systemctl restart salt-master; |
| 405 | node_name: {{ HOSTNAME_CFG01 }} |
| 406 | retry: {count: 1, delay: 5} |
| 407 | skip_fail: false |
| 408 | {%- endmacro %} |
| 409 | |
| 410 | |
| 411 | {%- macro MACRO_INSTALL_SALT_MINIONS() %} |
| 412 | {#######################################} |
| 413 | {% for ssh in config.underlay.ssh %} |
| 414 | - description: Configure salt-minion on {{ ssh['node_name'] }} |
| 415 | cmd: | |
| 416 | [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d; |
| 417 | cat << "EOF" >> /etc/salt/minion.d/minion.conf |
| 418 | id: {{ ssh['node_name'] }} |
| 419 | master: {{ config.salt.salt_master_host }} |
| 420 | EOF |
| 421 | eatmydata apt-get install -y salt-minion; |
Dennis Dmitriev | 3e731a4 | 2017-08-30 17:12:59 +0300 | [diff] [blame] | 422 | service salt-minion restart; # For case if salt-minion was already installed |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 423 | node_name: {{ ssh['node_name'] }} |
| 424 | retry: {count: 1, delay: 1} |
| 425 | skip_fail: false |
| 426 | {% endfor %} |
| 427 | |
| 428 | |
| 429 | - description: Accept salt keys from all the nodes |
| 430 | cmd: salt-key -A -y |
| 431 | node_name: {{ HOSTNAME_CFG01 }} |
| 432 | retry: {count: 1, delay: 5} |
| 433 | skip_fail: true |
| 434 | {%- endmacro %} |
| 435 | |
| 436 | |
| 437 | {%- macro MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() %} |
| 438 | {##################################################} |
| 439 | |
| 440 | {# Prepare salt services and nodes settings #} |
| 441 | |
| 442 | - description: Run 'linux' formula on cfg01 |
| 443 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux; |
| 444 | node_name: {{ HOSTNAME_CFG01 }} |
| 445 | retry: {count: 3, delay: 5} |
| 446 | skip_fail: false |
| 447 | |
| 448 | - description: Run 'openssh' formula on cfg01 |
| 449 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
Dennis Dmitriev | 3e731a4 | 2017-08-30 17:12:59 +0300 | [diff] [blame] | 450 | -C 'I@salt:master' state.sls openssh && |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 451 | salt --hard-crash --state-output=mixed --state-verbose=False |
| 452 | -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication |
Dennis Dmitriev | 3e731a4 | 2017-08-30 17:12:59 +0300 | [diff] [blame] | 453 | yes/' /etc/ssh/sshd_config && service ssh reload" |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 454 | node_name: {{ HOSTNAME_CFG01 }} |
| 455 | retry: {count: 3, delay: 5} |
| 456 | skip_fail: false |
| 457 | |
| 458 | - description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962' |
| 459 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 460 | '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config" |
| 461 | node_name: {{ HOSTNAME_CFG01 }} |
| 462 | retry: {count: 1, delay: 1} |
| 463 | skip_fail: false |
| 464 | |
| 465 | - description: Run 'salt.master' formula on cfg01 |
Dennis Dmitriev | e575e98 | 2017-10-21 21:50:45 +0300 | [diff] [blame] | 466 | cmd: timeout 600 salt-call -l info --hard-crash --state-output=mixed --state-verbose=False state.sls salt.master; |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 467 | node_name: {{ HOSTNAME_CFG01 }} |
Dennis Dmitriev | e575e98 | 2017-10-21 21:50:45 +0300 | [diff] [blame] | 468 | retry: {count: 2, delay: 30} |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 469 | skip_fail: false |
| 470 | |
Victor Ryzhenkin | 4e077ad | 2017-08-10 13:42:11 +0400 | [diff] [blame] | 471 | {%- if SALT_FORMULAS_REFS != '' %} |
| 472 | - description: Replace needed formulas to desired version |
| 473 | cmd: | |
| 474 | set -e; |
Victor Ryzhenkin | c791368 | 2017-10-11 15:14:40 +0400 | [diff] [blame] | 475 | {%- for formula_set in SALT_FORMULAS_REFS.split(' ') %} |
| 476 | {% set formula = formula_set.split(':') %} |
| 477 | {% set formula_name = formula[0] %} |
| 478 | {% set formula_ref = formula[1] %} |
Dennis Dmitriev | bc57b80 | 2017-08-16 18:10:57 +0300 | [diff] [blame] | 479 | {% set formula_dir = '/tmp/salt-formula-' + formula_name %} |
Victor Ryzhenkin | 4e077ad | 2017-08-10 13:42:11 +0400 | [diff] [blame] | 480 | git clone {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_dir }} && |
| 481 | pushd {{ formula_dir }} && |
| 482 | git fetch {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_ref }} && |
| 483 | git checkout FETCH_HEAD && |
| 484 | popd && |
| 485 | if [ -d "{{ formula_dir }}" ]; then |
| 486 | echo "Going to replace packaged formula {{ formula_name }}" && |
| 487 | rm -rfv /usr/share/salt-formulas/{env,reclass/service}/{{ formula_name }} && |
Victor Ryzhenkin | c791368 | 2017-10-11 15:14:40 +0400 | [diff] [blame] | 488 | ln -v -s "{{ formula_dir }}/{{ formula_name }}" "/usr/share/salt-formulas/env/{{ formula_name }}" && |
| 489 | ln -v -s "{{ formula_dir }}/metadata/service/" "/usr/share/salt-formulas/reclass/service/{{ formula_name }}"; |
Victor Ryzhenkin | 4e077ad | 2017-08-10 13:42:11 +0400 | [diff] [blame] | 490 | else |
| 491 | echo "Stopped, directory /root/salt-formula-{{ formula_name }} does not exist!"; |
| 492 | fi |
| 493 | {%- endfor %} |
| 494 | node_name: {{ HOSTNAME_CFG01 }} |
| 495 | retry: {count: 1, delay: 10} |
| 496 | skip_fail: false |
| 497 | {%- endif %} |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 498 | |
| 499 | - description: Refresh pillars on salt-master minion |
| 500 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' saltutil.refresh_pillar |
| 501 | node_name: {{ HOSTNAME_CFG01 }} |
| 502 | retry: {count: 1, delay: 5} |
| 503 | skip_fail: false |
| 504 | |
Dennis Dmitriev | 3e731a4 | 2017-08-30 17:12:59 +0300 | [diff] [blame] | 505 | - description: Show reclass-salt --top for salt-master node |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 506 | cmd: reclass-salt --top |
| 507 | node_name: {{ HOSTNAME_CFG01 }} |
| 508 | retry: {count: 1, delay: 5} |
| 509 | skip_fail: false |
| 510 | |
| 511 | - description: Sync all salt resources on salt-master minion |
Dennis Dmitriev | 9a6cacc | 2017-08-14 00:08:41 +0300 | [diff] [blame] | 512 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' saltutil.sync_all && sleep 5 |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 513 | node_name: {{ HOSTNAME_CFG01 }} |
| 514 | retry: {count: 1, delay: 5} |
| 515 | skip_fail: false |
| 516 | |
| 517 | - description: Configure linux on master |
| 518 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system' |
| 519 | node_name: {{ HOSTNAME_CFG01 }} |
| 520 | retry: {count: 1, delay: 5} |
| 521 | skip_fail: false |
| 522 | |
| 523 | - description: Configure salt.minion on master |
| 524 | cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False |
| 525 | -C 'I@salt:master' state.sls salt.minion && sleep 10 |
| 526 | node_name: {{ HOSTNAME_CFG01 }} |
| 527 | retry: {count: 3, delay: 10} |
| 528 | skip_fail: false |
| 529 | |
| 530 | - description: Run state 'salt' on master (for salt.api, etc) |
| 531 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 532 | -C 'I@salt:master' state.sls salt |
| 533 | node_name: {{ HOSTNAME_CFG01 }} |
| 534 | retry: {count: 3, delay: 10} |
| 535 | skip_fail: false |
| 536 | {%- endmacro %} |
| 537 | |
| 538 | {%- macro MACRO_GENERATE_INVENTORY() %} |
| 539 | {#####################################} |
| 540 | - description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated |
| 541 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 542 | -C 'I@salt:master' state.sls reclass |
| 543 | node_name: {{ HOSTNAME_CFG01 }} |
| 544 | retry: {count: 1, delay: 5} |
| 545 | skip_fail: false |
| 546 | |
| 547 | - description: Refresh pillars on all minions |
| 548 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar |
| 549 | node_name: {{ HOSTNAME_CFG01 }} |
| 550 | retry: {count: 1, delay: 5} |
| 551 | skip_fail: false |
| 552 | |
Dennis Dmitriev | 3e731a4 | 2017-08-30 17:12:59 +0300 | [diff] [blame] | 553 | - description: Show reclass-salt --top for all generated nodes |
Dennis Dmitriev | 4386a07 | 2017-09-04 13:58:02 +0300 | [diff] [blame] | 554 | cmd: | |
| 555 | set -e |
| 556 | if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi |
| 557 | if salt-call sys.doc reclass.validate_pillar | grep -q reclass.validate_pillar ; then salt-call reclass.validate_pillar ; fi |
| 558 | reclass-salt --top |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 559 | node_name: {{ HOSTNAME_CFG01 }} |
| 560 | retry: {count: 1, delay: 5} |
| 561 | skip_fail: false |
| 562 | |
| 563 | - description: Sync all salt resources |
Dennis Dmitriev | 9a6cacc | 2017-08-14 00:08:41 +0300 | [diff] [blame] | 564 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5 |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 565 | node_name: {{ HOSTNAME_CFG01 }} |
| 566 | retry: {count: 1, delay: 5} |
| 567 | skip_fail: false |
| 568 | {%- endmacro %} |
| 569 | |
| 570 | |
| 571 | {%- macro MACRO_BOOTSTRAP_ALL_MINIONS() %} |
| 572 | {########################################} |
| 573 | # Bootstrap all nodes |
| 574 | - description: Configure linux on other nodes |
| 575 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux |
| 576 | node_name: {{ HOSTNAME_CFG01 }} |
| 577 | retry: {count: 5, delay: 10} |
| 578 | skip_fail: false |
| 579 | |
| 580 | - description: Configure openssh on all nodes |
Dennis Dmitriev | 3e731a4 | 2017-08-30 17:12:59 +0300 | [diff] [blame] | 581 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls openssh && |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 582 | salt --hard-crash --state-output=mixed --state-verbose=False |
| 583 | -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication |
| 584 | yes/' /etc/ssh/sshd_config && service ssh reload" |
| 585 | node_name: {{ HOSTNAME_CFG01 }} |
| 586 | retry: {count: 1, delay: 5} |
| 587 | skip_fail: false |
| 588 | |
| 589 | - description: Configure salt.minion on other nodes |
| 590 | cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls salt.minion && |
| 591 | sleep 10 |
| 592 | node_name: {{ HOSTNAME_CFG01 }} |
| 593 | retry: {count: 3, delay: 15} |
| 594 | skip_fail: false |
| 595 | |
| 596 | - description: Check salt minion versions on slaves |
| 597 | cmd: salt '*' test.version |
| 598 | node_name: {{ HOSTNAME_CFG01 }} |
| 599 | retry: {count: 3, delay: 15} |
| 600 | skip_fail: false |
| 601 | |
| 602 | - description: Check salt top states on nodes |
| 603 | cmd: salt '*' state.show_top |
| 604 | node_name: {{ HOSTNAME_CFG01 }} |
| 605 | retry: {count: 1, delay: 5} |
| 606 | skip_fail: false |
| 607 | |
| 608 | - description: Configure ntp and rsyslog on nodes |
| 609 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog |
| 610 | node_name: {{ HOSTNAME_CFG01 }} |
| 611 | retry: {count: 1, delay: 10} |
| 612 | skip_fail: false |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 613 | {%- endmacro %} |
Dennis Dmitriev | 9dada8a | 2017-08-30 17:38:55 +0300 | [diff] [blame] | 614 | |
| 615 | |
| 616 | {%- macro MACRO_NETWORKING_WORKAROUNDS() %} |
| 617 | {#########################################} |
| 618 | |
Oleksii Butenko | f72f9d1 | 2017-10-18 13:10:04 +0300 | [diff] [blame] | 619 | #- description: '*Workaround 1/2* of the bug PROD-9576 to get bond0-connectivity *without* rebooting nodes' |
| 620 | # cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False cmd.run |
| 621 | # "mkdir -p /tmp/PROD-9576; cd /tmp/PROD-9576; git clone https://gerrit.mcp.mirantis.net/salt-formulas/linux; cd linux; |
| 622 | # git fetch https://gerrit.mcp.mirantis.net/salt-formulas/linux refs/changes/54/2354/16 && git checkout FETCH_HEAD; |
| 623 | # cp -f linux/network/interface.sls /srv/salt/env/prd/linux/network/; |
| 624 | # cp -f linux/map.jinja /srv/salt/env/prd/linux/;" |
| 625 | # node_name: {{ HOSTNAME_CFG01 }} |
| 626 | # retry: {count: 1, delay: 5} |
| 627 | # skip_fail: false |
Dennis Dmitriev | 9dada8a | 2017-08-30 17:38:55 +0300 | [diff] [blame] | 628 | |
| 629 | - description: '*Workaround: Load bonding module before call state.linux' |
| 630 | cmd: salt -C "I@linux:network:interface:*:type:bond" cmd.run 'modprobe bonding' |
| 631 | node_name: {{ HOSTNAME_CFG01 }} |
| 632 | retry: {count: 1, delay: 5} |
Dennis Dmitriev | 0496eb7 | 2017-09-05 21:42:10 +0300 | [diff] [blame] | 633 | skip_fail: true |
Dennis Dmitriev | 9dada8a | 2017-08-30 17:38:55 +0300 | [diff] [blame] | 634 | |
| 635 | - description: '*Workaround* install bridge-utils before running linux formula' |
| 636 | # The formula removes default route and then tries to install the package, fails. |
| 637 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not |
| 638 | cfg01*' cmd.run 'sudo apt-get install -y bridge-utils' |
| 639 | node_name: {{ HOSTNAME_CFG01 }} |
| 640 | retry: {count: 1, delay: 5} |
| 641 | skip_fail: false |
| 642 | |
| 643 | {%- endmacro %} |
Victor Ryzhenkin | 9cc824c | 2017-10-12 19:02:23 +0400 | [diff] [blame] | 644 | |
| 645 | {%- macro ADJUST_K8S_OPTS() %} |
| 646 | {#########################################} |
| 647 | |
| 648 | - description: Set k8s deploy parameters |
| 649 | cmd: | |
| 650 | {% for k8s_opt, value in config.k8s_deploy.items() %} |
| 651 | {% if value|string() %} |
| 652 | salt-call reclass.cluster_meta_set name={{ k8s_opt }} value={{ value }}; |
| 653 | {% endif %} |
| 654 | {% endfor %} |
| 655 | node_name: {{ HOSTNAME_CFG01 }} |
| 656 | retry: {count: 1, delay: 1} |
| 657 | skip_fail: false |
| 658 | |
| 659 | {%- endmacro %} |