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','') %} |
sgudz | cced67d | 2017-10-11 15:56:09 +0300 | [diff] [blame] | 12 | {% set ENVIRONMENT_TEMPLATE_REF_CHANGE = os_env('ENVIRONMENT_TEMPLATE_REF_CHANGE','') %} |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 13 | |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 14 | {% set REPOSITORY_SUITE = os_env('REPOSITORY_SUITE', 'testing') %} |
| 15 | |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 16 | {# Address pools for reclass cluster model are taken in the following order: |
| 17 | # 1. environment variables, |
| 18 | # 2. config.underlay.address_pools based on fuel-devops address pools |
| 19 | # (see generated '.ini' file after underlay is created), |
| 20 | # 3. defaults #} |
| 21 | {% set address_pools = config.underlay.address_pools %} |
| 22 | {% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('admin-pool01', '192.168.10.0/24')) %} |
| 23 | {% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '172.16.10.0/24')) %} |
| 24 | {% set IPV4_NET_TENANT = os_env('IPV4_NET_TENANT', address_pools.get('tenant-pool01', '10.1.0.0/24')) %} |
| 25 | {% set IPV4_NET_EXTERNAL = os_env('IPV4_NET_EXTERNAL', address_pools.get('external-pool01', '10.16.0.0/24')) %} |
| 26 | {% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %} |
| 27 | {% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %} |
| 28 | {% set IPV4_NET_TENANT_PREFIX = '.'.join(IPV4_NET_TENANT.split('.')[0:3]) %} |
| 29 | {% set IPV4_NET_EXTERNAL_PREFIX = '.'.join(IPV4_NET_EXTERNAL.split('.')[0:3]) %} |
| 30 | |
Victor Ryzhenkin | 4e077ad | 2017-08-10 13:42:11 +0400 | [diff] [blame] | 31 | {# Format for formula replacement: |
| 32 | # space separated string: |
| 33 | # export SALT_FORMULAS_REFS='apache:refs/changes/xxxx kubernetes:refs/changes/xxxx' #} |
| 34 | |
| 35 | {% set SALT_FORMULAS_REFS = os_env('SALT_FORMULAS_REFS', '') %} |
| 36 | {% set SALT_FORMULAS_REPO = os_env('SALT_FORMULAS_REPO', 'https://gerrit.mcp.mirantis.net/salt-formulas') %} |
| 37 | |
Victor Ryzhenkin | 66593e9 | 2017-11-28 19:38:33 +0400 | [diff] [blame] | 38 | # Needed for using different models in different templates |
| 39 | {% set CLUSTER_NAME = os_env('DOMAIN_NAME', LAB_CONFIG_NAME) %} |
| 40 | |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 41 | |
| 42 | {%- macro MACRO_INSTALL_SALT_MASTER() %} |
| 43 | {######################################} |
| 44 | - description: Installing salt master on cfg01 |
| 45 | cmd: eatmydata apt-get install -y reclass git salt-master |
| 46 | node_name: {{ HOSTNAME_CFG01 }} |
| 47 | retry: {count: 1, delay: 1} |
| 48 | skip_fail: false |
| 49 | |
| 50 | - description: Configure salt-master on cfg01 |
| 51 | cmd: | |
| 52 | cat << 'EOF' >> /etc/salt/master.d/master.conf |
| 53 | file_roots: |
| 54 | base: |
| 55 | - /usr/share/salt-formulas/env |
| 56 | pillar_opts: False |
| 57 | open_mode: True |
| 58 | reclass: &reclass |
| 59 | storage_type: yaml_fs |
| 60 | inventory_base_uri: /srv/salt/reclass |
| 61 | ext_pillar: |
| 62 | - reclass: *reclass |
| 63 | master_tops: |
| 64 | reclass: *reclass |
| 65 | EOF |
| 66 | node_name: {{ HOSTNAME_CFG01 }} |
| 67 | retry: {count: 1, delay: 1} |
| 68 | skip_fail: false |
| 69 | |
| 70 | - description: Configure GIT settings and certificates |
Dennis Dmitriev | 3e731a4 | 2017-08-30 17:12:59 +0300 | [diff] [blame] | 71 | cmd: | |
| 72 | set -e; |
| 73 | touch /root/.git_trusted_certs.pem; |
| 74 | for server in github.com; do \ |
| 75 | openssl s_client -showcerts -connect $server:443 </dev/null \ |
| 76 | | openssl x509 -outform PEM \ |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 77 | >> /root/.git_trusted_certs.pem; |
| 78 | done; |
| 79 | HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem; |
| 80 | HOME=/root git config --global user.email "tcp-qa@example.com"; |
| 81 | HOME=/root git config --global user.name "TCP QA"; |
| 82 | node_name: {{ HOSTNAME_CFG01 }} |
| 83 | retry: {count: 1, delay: 1} |
| 84 | skip_fail: false |
| 85 | {%- endmacro %} |
| 86 | |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 87 | {%- macro MACRO_CLONE_RECLASS_MODELS(IS_CONTRAIL_LAB=false) %} |
| 88 | {############################################################} |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 89 | {# Creates a 'cluster' model from cookiecutter-templates and 'environment' model from uploaded template #} |
| 90 | |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 91 | - description: Clone reclass models with submodules |
| 92 | cmd: | |
Dennis Dmitriev | 3e731a4 | 2017-08-30 17:12:59 +0300 | [diff] [blame] | 93 | set -e; |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 94 | ssh-keyscan -H github.com >> ~/.ssh/known_hosts; |
Tatyana Leontovich | 4416273 | 2017-08-28 12:36:00 +0300 | [diff] [blame] | 95 | 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] | 96 | pushd /srv/salt/reclass && \ |
| 97 | {%- if SALT_MODELS_REF_CHANGE != '' %} |
| 98 | {%- for item in SALT_MODELS_REF_CHANGE.split(" ") %} |
| 99 | git fetch {{ SALT_MODELS_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD && \ |
| 100 | {%- endfor %} |
| 101 | {%- elif SALT_MODELS_COMMIT != 'master' %} |
| 102 | git checkout {{ SALT_MODELS_COMMIT }} && \ |
| 103 | {%- endif %} |
| 104 | {%- if SALT_MODELS_SYSTEM_COMMIT != '' %} |
| 105 | pushd classes/system/ && \ |
| 106 | git checkout {{ SALT_MODELS_SYSTEM_COMMIT }} && \ |
| 107 | popd && \ |
sgudz | 4d816eb | 2017-11-13 11:58:05 +0200 | [diff] [blame] | 108 | {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %} |
Dmitry Tyzhnenko | 778515f | 2017-08-25 14:52:54 +0300 | [diff] [blame] | 109 | pushd classes/system/ && \ |
| 110 | {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %} |
| 111 | git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD && \ |
| 112 | {%- endfor %} |
| 113 | popd && \ |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 114 | {%- else %} |
| 115 | git submodule update --init --recursive && \ |
| 116 | {%- endif %} |
| 117 | popd; |
| 118 | mkdir -p /srv/salt/reclass/classes/service; |
Dennis Dmitriev | a14f556 | 2017-10-02 12:59:53 +0300 | [diff] [blame] | 119 | 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] | 120 | mkdir -p /srv/salt/reclass/nodes/_generated/; |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 121 | |
| 122 | # Replace firstly to an intermediate value to avoid intersection between |
| 123 | # already replaced and replacing networks. |
| 124 | # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice: |
| 125 | # 192.168.10 -> 10.16.0 (generated network for admin) |
| 126 | # 10.16.0 -> <external network> |
| 127 | # 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] | 128 | export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/" |
| 129 | find ${REPLACE_DIRS} -type f -exec sed -i 's/192\.168\.10\./==IPV4_NET_ADMIN_PREFIX==/g' {} + |
| 130 | find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.16\.10\./==IPV4_NET_CONTROL_PREFIX==/g' {} + |
| 131 | find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.1\.0\./==IPV4_NET_TENANT_PREFIX==/g' {} + |
| 132 | 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] | 133 | |
Dennis Dmitriev | 9d9ba9f | 2017-09-13 17:34:03 +0300 | [diff] [blame] | 134 | find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}./g' {} + |
| 135 | find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}./g' {} + |
| 136 | find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}./g' {} + |
| 137 | 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] | 138 | |
Dennis Dmitriev | 9d9ba9f | 2017-09-13 17:34:03 +0300 | [diff] [blame] | 139 | 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] | 140 | |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 141 | {%- if IS_CONTRAIL_LAB %} |
| 142 | # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded |
Dennis Dmitriev | 9d9ba9f | 2017-09-13 17:34:03 +0300 | [diff] [blame] | 143 | 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] | 144 | 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] | 145 | {%- endif %} |
| 146 | |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 147 | # Disable checkouting the model from remote repository |
Dennis Dmitriev | b2e78be | 2017-09-26 23:25:24 +0300 | [diff] [blame] | 148 | cat << 'EOF' >> /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml |
| 149 | classes: |
Victor Ryzhenkin | 66593e9 | 2017-11-28 19:38:33 +0400 | [diff] [blame] | 150 | - cluster.{{ CLUSTER_NAME }}.infra.config |
Dennis Dmitriev | b2e78be | 2017-09-26 23:25:24 +0300 | [diff] [blame] | 151 | parameters: |
| 152 | _param: |
| 153 | linux_system_codename: xenial |
| 154 | reclass_data_revision: master |
| 155 | linux: |
| 156 | system: |
| 157 | name: cfg01 |
| 158 | domain: {{ DOMAIN_NAME }} |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 159 | reclass: |
| 160 | storage: |
| 161 | data_source: |
| 162 | engine: local |
| 163 | EOF |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 164 | |
| 165 | # Show the changes to the console |
| 166 | cd /srv/salt/reclass/; git diff |
| 167 | node_name: {{ HOSTNAME_CFG01 }} |
| 168 | retry: {count: 1, delay: 1} |
| 169 | skip_fail: false |
| 170 | {%- endmacro %} |
| 171 | |
| 172 | |
sgudz | 8c888ec | 2017-10-02 15:29:23 +0300 | [diff] [blame] | 173 | {%- 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] | 174 | {###################################################################} |
Dennis Dmitriev | 1c1352a | 2017-09-28 21:45:27 +0300 | [diff] [blame] | 175 | {%- set CLUSTER_CONTEXT_PATH = '/tmp/' + CLUSTER_CONTEXT_NAME %} |
Dennis Dmitriev | ccdc87a | 2017-09-28 17:43:54 +0300 | [diff] [blame] | 176 | - description: "[EXPERIMENTAL] Upload cookiecutter-templates context to {{ HOSTNAME_CFG01 }}" |
| 177 | upload: |
| 178 | local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/ |
| 179 | local_filename: {{ CLUSTER_CONTEXT_NAME }} |
Dennis Dmitriev | 1c1352a | 2017-09-28 21:45:27 +0300 | [diff] [blame] | 180 | remote_path: /tmp/ |
Dennis Dmitriev | ccdc87a | 2017-09-28 17:43:54 +0300 | [diff] [blame] | 181 | node_name: {{ HOSTNAME_CFG01 }} |
| 182 | |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 183 | - description: Create cluster model from cookiecutter templates |
| 184 | cmd: | |
| 185 | set -e; |
| 186 | pip install cookiecutter |
| 187 | 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] | 188 | |
| 189 | {%- if COOKIECUTTER_REF_CHANGE != '' %} |
| 190 | pushd /tmp/cookiecutter-templates |
| 191 | git fetch https://gerrit.mcp.mirantis.net/mk/cookiecutter-templates {{ COOKIECUTTER_REF_CHANGE }} && git checkout FETCH_HEAD |
| 192 | popd |
| 193 | {%- endif %} |
| 194 | |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 195 | mkdir -p /srv/salt/reclass/classes/cluster/ |
| 196 | mkdir -p /srv/salt/reclass/classes/system/ |
| 197 | mkdir -p /srv/salt/reclass/classes/service/ |
Dennis Dmitriev | a14f556 | 2017-10-02 12:59:53 +0300 | [diff] [blame] | 198 | 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] | 199 | mkdir -p /srv/salt/reclass/nodes/_generated |
| 200 | |
| 201 | # Override some context parameters |
| 202 | sed -i 's/cluster_name:.*/cluster_name: {{ LAB_CONFIG_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }} |
| 203 | sed -i 's/cluster_domain:.*/cluster_domain: {{ DOMAIN_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }} |
sgudz | 8c888ec | 2017-10-02 15:29:23 +0300 | [diff] [blame] | 204 | {%- if CONTROL_VLAN %} |
| 205 | sed -i 's/control_vlan:.*/control_vlan: {{ CONTROL_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }} |
| 206 | {%- endif %} |
| 207 | {%- if TENANT_VLAN %} |
| 208 | sed -i 's/tenant_vlan:.*/tenant_vlan: {{ TENANT_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }} |
| 209 | {%- endif %} |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 210 | |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 211 | # Replace firstly to an intermediate value to avoid intersection between |
| 212 | # already replaced and replacing networks. |
| 213 | # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice: |
| 214 | # 192.168.10 -> 10.16.0 (generated network for admin) |
| 215 | # 10.16.0 -> <external network> |
| 216 | # So let's replace constant networks to the keywords, and then keywords to the desired networks. |
| 217 | sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }} |
| 218 | sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }} |
| 219 | sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }} |
| 220 | sed -i 's/172\.17\.16\./==IPV4_NET_EXTERNAL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }} |
| 221 | |
Dennis Dmitriev | 39e64bd | 2017-09-21 22:37:40 +0300 | [diff] [blame] | 222 | sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }} |
| 223 | sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }} |
| 224 | sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }} |
| 225 | 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] | 226 | |
| 227 | for i in $(ls /tmp/cookiecutter-templates/cluster_product/); do |
| 228 | python /tmp/cookiecutter-templates/generate.py \ |
| 229 | --template /tmp/cookiecutter-templates/cluster_product/$i \ |
| 230 | --config-file {{ CLUSTER_CONTEXT_PATH }} \ |
| 231 | --output-dir /srv/salt/reclass/classes/cluster/; |
| 232 | done |
| 233 | |
| 234 | export GIT_SSL_NO_VERIFY=true; git clone https://gerrit.mcp.mirantis.net/salt-models/reclass-system /srv/salt/reclass/classes/system/ |
| 235 | |
| 236 | # Create the cfg01 node and disable checkouting the model from remote repository |
| 237 | cat << 'EOF' >> /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml |
| 238 | classes: |
| 239 | - system.openssh.server.team.all |
| 240 | - cluster.{{ LAB_CONFIG_NAME }}.infra.config |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 241 | EOF |
| 242 | |
| 243 | node_name: {{ HOSTNAME_CFG01 }} |
| 244 | retry: {count: 1, delay: 1} |
| 245 | skip_fail: false |
| 246 | |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 247 | - description: Modify generated model and reclass-system if necessary |
| 248 | cmd: | |
| 249 | set -e; |
| 250 | {%- if SALT_MODELS_SYSTEM_COMMIT != '' %} |
| 251 | pushd /srv/salt/reclass/classes/system/ |
| 252 | git checkout {{ SALT_MODELS_SYSTEM_COMMIT }} && \ |
| 253 | popd |
sgudz | 4d816eb | 2017-11-13 11:58:05 +0200 | [diff] [blame] | 254 | {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %} |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 255 | pushd /srv/salt/reclass/classes/system/ |
| 256 | {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %} |
| 257 | git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD |
| 258 | {%- endfor %} |
| 259 | popd |
| 260 | {%- endif %} |
| 261 | |
| 262 | export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/" |
| 263 | find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} + |
| 264 | |
| 265 | {%- if IS_CONTRAIL_LAB %} |
| 266 | # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded |
| 267 | find ${REPLACE_DIRS} -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} + |
| 268 | find ${REPLACE_DIRS} -type f -exec sed -i 's/infra_config_deploy_address: 1.*/infra_config_deploy_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {} + |
| 269 | {%- endif %} |
| 270 | |
| 271 | node_name: {{ HOSTNAME_CFG01 }} |
| 272 | retry: {count: 1, delay: 1} |
| 273 | skip_fail: false |
| 274 | {%- endmacro %} |
| 275 | |
| 276 | |
Dennis Dmitriev | 9f141af | 2017-09-28 17:21:01 +0300 | [diff] [blame] | 277 | {%- macro MACRO_GENERATE_AND_ENABLE_ENVIRONMENT_MODEL() %} |
| 278 | {########################################################} |
Dennis Dmitriev | ccdc87a | 2017-09-28 17:43:54 +0300 | [diff] [blame] | 279 | |
sgudz | cced67d | 2017-10-11 15:56:09 +0300 | [diff] [blame] | 280 | - description: "[EXPERIMENTAL] Clone 'environment-template' repository to {{ HOSTNAME_CFG01 }}." |
Dennis Dmitriev | 9e18de7 | 2017-10-11 18:14:36 +0300 | [diff] [blame] | 281 | cmd: | |
| 282 | set -e; |
| 283 | mkdir -p /tmp/environment/; |
| 284 | 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] | 285 | node_name: {{ HOSTNAME_CFG01 }} |
| 286 | skip_fail: false |
| 287 | |
sgudz | cced67d | 2017-10-11 15:56:09 +0300 | [diff] [blame] | 288 | {%- if ENVIRONMENT_TEMPLATE_REF_CHANGE != '' %} |
| 289 | - description: Fetch changes for environment templates |
| 290 | cmd: | |
| 291 | set -e; |
| 292 | pushd /tmp/environment/environment_template && |
| 293 | git fetch https://github.com/Mirantis/environment-template {{ ENVIRONMENT_TEMPLATE_REF_CHANGE }} && |
| 294 | git checkout FETCH_HEAD && |
| 295 | popd |
| 296 | node_name: {{ HOSTNAME_CFG01 }} |
| 297 | skip_fail: false |
| 298 | {%- endif %} |
| 299 | |
Dennis Dmitriev | ccdc87a | 2017-09-28 17:43:54 +0300 | [diff] [blame] | 300 | {%- for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %} |
Dennis Dmitriev | 9f141af | 2017-09-28 17:21:01 +0300 | [diff] [blame] | 301 | - description: "[EXPERIMENTAL] Upload environment inventory to {{ HOSTNAME_CFG01 }}" |
| 302 | upload: |
| 303 | local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/ |
| 304 | local_filename: {{ ENVIRONMENT_CONTEXT_NAME }} |
| 305 | remote_path: /tmp/environment/ |
| 306 | node_name: {{ HOSTNAME_CFG01 }} |
Dennis Dmitriev | ccdc87a | 2017-09-28 17:43:54 +0300 | [diff] [blame] | 307 | {%- endfor %} |
Dennis Dmitriev | 9f141af | 2017-09-28 17:21:01 +0300 | [diff] [blame] | 308 | |
| 309 | - description: "[EXPERIMENTAL] Remove linux.network.interface object from the cluster/system models and use fixed 'environment' model instead" |
| 310 | cmd: | |
| 311 | set -e; |
| 312 | apt-get -y install python-virtualenv python-pip build-essential python-dev libssl-dev; |
| 313 | pip install git+https://github.com/dis-xcom/reclass-tools; |
| 314 | reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/cluster/; |
| 315 | reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/system/; |
| 316 | reclass-tools del-key parameters.linux.network.interface /usr/share/salt-formulas/reclass/; |
| 317 | |
| 318 | if ! reclass-tools get-key 'classes' /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml | grep -q "environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}$"; then |
| 319 | reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}.reclass_datasource_local' /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml --merge ; |
| 320 | reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}' /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml --merge ; |
| 321 | fi; |
| 322 | |
| 323 | node_name: {{ HOSTNAME_CFG01 }} |
| 324 | retry: {count: 1, delay: 5} |
| 325 | skip_fail: false |
| 326 | |
Dennis Dmitriev | 222ba8e | 2017-11-11 00:06:02 +0200 | [diff] [blame] | 327 | - description: "Workaround for PROD-15923: all keepalive instances must be named 'VIP'" |
Dennis Dmitriev | 9f141af | 2017-09-28 17:21:01 +0300 | [diff] [blame] | 328 | cmd: | |
| 329 | set -e; |
Dennis Dmitriev | 222ba8e | 2017-11-11 00:06:02 +0200 | [diff] [blame] | 330 | 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] | 331 | |
| 332 | node_name: {{ HOSTNAME_CFG01 }} |
| 333 | retry: {count: 1, delay: 5} |
| 334 | skip_fail: false |
| 335 | |
| 336 | - description: "[EXPERIMENTAL] Create environment model for virtual environment" |
| 337 | cmd: | |
| 338 | set -e; |
Dennis Dmitriev | 9f141af | 2017-09-28 17:21:01 +0300 | [diff] [blame] | 339 | reclass-tools render --template-dir /tmp/environment/environment_template/ \ |
| 340 | --output-dir /srv/salt/reclass/classes/environment/ \ |
Dennis Dmitriev | d55a856 | 2017-09-28 22:12:09 +0300 | [diff] [blame] | 341 | {% 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] | 342 | --env-name {{ ENVIRONMENT_MODEL_INVENTORY_NAME }} |
| 343 | node_name: {{ HOSTNAME_CFG01 }} |
| 344 | retry: {count: 1, delay: 5} |
| 345 | skip_fail: false |
sgudz | 8c888ec | 2017-10-02 15:29:23 +0300 | [diff] [blame] | 346 | |
| 347 | - description: Modify generated model and reclass-system |
| 348 | cmd: | |
| 349 | export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/" |
| 350 | find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} + |
| 351 | node_name: {{ HOSTNAME_CFG01 }} |
| 352 | retry: {count: 1, delay: 1} |
| 353 | skip_fail: false |
| 354 | |
Dennis Dmitriev | 9f141af | 2017-09-28 17:21:01 +0300 | [diff] [blame] | 355 | {%- endmacro %} |
| 356 | |
| 357 | |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 358 | {%- macro MACRO_CONFIGURE_RECLASS(FORMULA_SERVICES='') %} |
| 359 | {#######################################################} |
| 360 | - description: Configure reclass |
| 361 | cmd: | |
Dennis Dmitriev | 3e731a4 | 2017-08-30 17:12:59 +0300 | [diff] [blame] | 362 | set -e; |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 363 | FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas}; |
| 364 | FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt.mirantis.com/xenial {{ REPOSITORY_SUITE }} salt}; |
| 365 | FORMULA_GPG=${FORMULA_GPG:-http://apt.mirantis.com/public.gpg}; |
| 366 | which wget > /dev/null || (apt-get update; apt-get install -y wget); |
| 367 | echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/mcp_salt.list; |
| 368 | wget -O - "${FORMULA_GPG}" | apt-key add -; |
| 369 | apt-get clean; apt-get update; |
| 370 | [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service; |
| 371 | declare -a formula_services=({{ FORMULA_SERVICES }}); |
| 372 | echo -e "\nInstalling all required salt formulas\n"; |
| 373 | eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}"; |
| 374 | for formula_service in "${formula_services[@]}"; do |
| 375 | echo -e "\nLink service metadata for formula ${formula_service} ...\n"; |
| 376 | [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service}; |
| 377 | done; |
| 378 | [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env; |
| 379 | [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd; |
| 380 | [ ! -d /etc/reclass ] && mkdir /etc/reclass; |
| 381 | |
| 382 | cat << 'EOF' >> /etc/reclass/reclass-config.yml |
| 383 | storage_type: yaml_fs |
| 384 | pretty_print: True |
| 385 | output: yaml |
| 386 | inventory_base_uri: /srv/salt/reclass |
| 387 | EOF |
| 388 | node_name: {{ HOSTNAME_CFG01 }} |
| 389 | retry: {count: 1, delay: 1} |
| 390 | skip_fail: false |
| 391 | |
| 392 | - description: "*Workaround* remove all cfg01 nodes except {{ HOSTNAME_CFG01 }} to not depend on other clusters in 'reclass --top'" |
| 393 | cmd: | |
| 394 | # Remove all other nodes except {{ HOSTNAME_CFG01 }} to not rely on them for 'reclass --top' |
| 395 | find /srv/salt/reclass/nodes/ -type f -not -name {{ HOSTNAME_CFG01 }}.yml -delete |
| 396 | node_name: {{ HOSTNAME_CFG01 }} |
| 397 | retry: {count: 1, delay: 5} |
| 398 | skip_fail: false |
| 399 | |
| 400 | - description: Configure salt adoptors on cfg01 |
| 401 | cmd: | |
| 402 | ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt; |
| 403 | chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py |
| 404 | node_name: {{ HOSTNAME_CFG01 }} |
| 405 | retry: {count: 1, delay: 1} |
| 406 | skip_fail: false |
| 407 | |
| 408 | - description: Show reclass-salt --top for cfg01 node |
| 409 | cmd: reclass-salt --top |
| 410 | node_name: {{ HOSTNAME_CFG01 }} |
| 411 | retry: {count: 1, delay: 5} |
| 412 | skip_fail: false |
| 413 | |
| 414 | - description: Restart salt-master service |
| 415 | cmd: systemctl restart salt-master; |
| 416 | node_name: {{ HOSTNAME_CFG01 }} |
| 417 | retry: {count: 1, delay: 5} |
| 418 | skip_fail: false |
| 419 | {%- endmacro %} |
| 420 | |
| 421 | |
| 422 | {%- macro MACRO_INSTALL_SALT_MINIONS() %} |
| 423 | {#######################################} |
| 424 | {% for ssh in config.underlay.ssh %} |
| 425 | - description: Configure salt-minion on {{ ssh['node_name'] }} |
| 426 | cmd: | |
| 427 | [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d; |
| 428 | cat << "EOF" >> /etc/salt/minion.d/minion.conf |
| 429 | id: {{ ssh['node_name'] }} |
| 430 | master: {{ config.salt.salt_master_host }} |
| 431 | EOF |
| 432 | eatmydata apt-get install -y salt-minion; |
Dennis Dmitriev | 3e731a4 | 2017-08-30 17:12:59 +0300 | [diff] [blame] | 433 | service salt-minion restart; # For case if salt-minion was already installed |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 434 | node_name: {{ ssh['node_name'] }} |
| 435 | retry: {count: 1, delay: 1} |
| 436 | skip_fail: false |
| 437 | {% endfor %} |
| 438 | |
| 439 | |
| 440 | - description: Accept salt keys from all the nodes |
| 441 | cmd: salt-key -A -y |
| 442 | node_name: {{ HOSTNAME_CFG01 }} |
| 443 | retry: {count: 1, delay: 5} |
| 444 | skip_fail: true |
| 445 | {%- endmacro %} |
| 446 | |
| 447 | |
| 448 | {%- macro MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() %} |
| 449 | {##################################################} |
| 450 | |
| 451 | {# Prepare salt services and nodes settings #} |
| 452 | |
| 453 | - description: Run 'linux' formula on cfg01 |
| 454 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux; |
| 455 | node_name: {{ HOSTNAME_CFG01 }} |
| 456 | retry: {count: 3, delay: 5} |
| 457 | skip_fail: false |
| 458 | |
| 459 | - description: Run 'openssh' formula on cfg01 |
| 460 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
Dennis Dmitriev | 3e731a4 | 2017-08-30 17:12:59 +0300 | [diff] [blame] | 461 | -C 'I@salt:master' state.sls openssh && |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 462 | salt --hard-crash --state-output=mixed --state-verbose=False |
| 463 | -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication |
Dennis Dmitriev | 3e731a4 | 2017-08-30 17:12:59 +0300 | [diff] [blame] | 464 | yes/' /etc/ssh/sshd_config && service ssh reload" |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 465 | node_name: {{ HOSTNAME_CFG01 }} |
| 466 | retry: {count: 3, delay: 5} |
| 467 | skip_fail: false |
| 468 | |
| 469 | - description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962' |
| 470 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 471 | '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config" |
| 472 | node_name: {{ HOSTNAME_CFG01 }} |
| 473 | retry: {count: 1, delay: 1} |
| 474 | skip_fail: false |
| 475 | |
| 476 | - description: Run 'salt.master' formula on cfg01 |
Dennis Dmitriev | e575e98 | 2017-10-21 21:50:45 +0300 | [diff] [blame] | 477 | 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] | 478 | node_name: {{ HOSTNAME_CFG01 }} |
Dennis Dmitriev | e575e98 | 2017-10-21 21:50:45 +0300 | [diff] [blame] | 479 | retry: {count: 2, delay: 30} |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 480 | skip_fail: false |
| 481 | |
Victor Ryzhenkin | 4e077ad | 2017-08-10 13:42:11 +0400 | [diff] [blame] | 482 | {%- if SALT_FORMULAS_REFS != '' %} |
| 483 | - description: Replace needed formulas to desired version |
| 484 | cmd: | |
| 485 | set -e; |
Victor Ryzhenkin | c791368 | 2017-10-11 15:14:40 +0400 | [diff] [blame] | 486 | {%- for formula_set in SALT_FORMULAS_REFS.split(' ') %} |
| 487 | {% set formula = formula_set.split(':') %} |
| 488 | {% set formula_name = formula[0] %} |
| 489 | {% set formula_ref = formula[1] %} |
Dennis Dmitriev | bc57b80 | 2017-08-16 18:10:57 +0300 | [diff] [blame] | 490 | {% set formula_dir = '/tmp/salt-formula-' + formula_name %} |
Victor Ryzhenkin | 4e077ad | 2017-08-10 13:42:11 +0400 | [diff] [blame] | 491 | git clone {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_dir }} && |
| 492 | pushd {{ formula_dir }} && |
| 493 | git fetch {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_ref }} && |
| 494 | git checkout FETCH_HEAD && |
| 495 | popd && |
| 496 | if [ -d "{{ formula_dir }}" ]; then |
| 497 | echo "Going to replace packaged formula {{ formula_name }}" && |
| 498 | rm -rfv /usr/share/salt-formulas/{env,reclass/service}/{{ formula_name }} && |
Victor Ryzhenkin | c791368 | 2017-10-11 15:14:40 +0400 | [diff] [blame] | 499 | ln -v -s "{{ formula_dir }}/{{ formula_name }}" "/usr/share/salt-formulas/env/{{ formula_name }}" && |
| 500 | 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] | 501 | else |
| 502 | echo "Stopped, directory /root/salt-formula-{{ formula_name }} does not exist!"; |
| 503 | fi |
| 504 | {%- endfor %} |
| 505 | node_name: {{ HOSTNAME_CFG01 }} |
| 506 | retry: {count: 1, delay: 10} |
| 507 | skip_fail: false |
| 508 | {%- endif %} |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 509 | |
| 510 | - description: Refresh pillars on salt-master minion |
| 511 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' saltutil.refresh_pillar |
| 512 | node_name: {{ HOSTNAME_CFG01 }} |
| 513 | retry: {count: 1, delay: 5} |
| 514 | skip_fail: false |
| 515 | |
Dennis Dmitriev | 3e731a4 | 2017-08-30 17:12:59 +0300 | [diff] [blame] | 516 | - description: Show reclass-salt --top for salt-master node |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 517 | cmd: reclass-salt --top |
| 518 | node_name: {{ HOSTNAME_CFG01 }} |
| 519 | retry: {count: 1, delay: 5} |
| 520 | skip_fail: false |
| 521 | |
| 522 | - description: Sync all salt resources on salt-master minion |
Dennis Dmitriev | 9a6cacc | 2017-08-14 00:08:41 +0300 | [diff] [blame] | 523 | 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] | 524 | node_name: {{ HOSTNAME_CFG01 }} |
| 525 | retry: {count: 1, delay: 5} |
| 526 | skip_fail: false |
| 527 | |
| 528 | - description: Configure linux on master |
| 529 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system' |
| 530 | node_name: {{ HOSTNAME_CFG01 }} |
| 531 | retry: {count: 1, delay: 5} |
| 532 | skip_fail: false |
| 533 | |
| 534 | - description: Configure salt.minion on master |
| 535 | cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False |
| 536 | -C 'I@salt:master' state.sls salt.minion && sleep 10 |
| 537 | node_name: {{ HOSTNAME_CFG01 }} |
| 538 | retry: {count: 3, delay: 10} |
| 539 | skip_fail: false |
| 540 | |
| 541 | - description: Run state 'salt' on master (for salt.api, etc) |
| 542 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 543 | -C 'I@salt:master' state.sls salt |
| 544 | node_name: {{ HOSTNAME_CFG01 }} |
| 545 | retry: {count: 3, delay: 10} |
| 546 | skip_fail: false |
| 547 | {%- endmacro %} |
| 548 | |
| 549 | {%- macro MACRO_GENERATE_INVENTORY() %} |
| 550 | {#####################################} |
| 551 | - description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated |
| 552 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 553 | -C 'I@salt:master' state.sls reclass |
| 554 | node_name: {{ HOSTNAME_CFG01 }} |
| 555 | retry: {count: 1, delay: 5} |
| 556 | skip_fail: false |
| 557 | |
| 558 | - description: Refresh pillars on all minions |
| 559 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar |
| 560 | node_name: {{ HOSTNAME_CFG01 }} |
| 561 | retry: {count: 1, delay: 5} |
| 562 | skip_fail: false |
| 563 | |
Dennis Dmitriev | 3e731a4 | 2017-08-30 17:12:59 +0300 | [diff] [blame] | 564 | - description: Show reclass-salt --top for all generated nodes |
Dennis Dmitriev | 4386a07 | 2017-09-04 13:58:02 +0300 | [diff] [blame] | 565 | cmd: | |
| 566 | set -e |
| 567 | if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi |
| 568 | if salt-call sys.doc reclass.validate_pillar | grep -q reclass.validate_pillar ; then salt-call reclass.validate_pillar ; fi |
| 569 | reclass-salt --top |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 570 | node_name: {{ HOSTNAME_CFG01 }} |
| 571 | retry: {count: 1, delay: 5} |
| 572 | skip_fail: false |
| 573 | |
| 574 | - description: Sync all salt resources |
Dennis Dmitriev | 9a6cacc | 2017-08-14 00:08:41 +0300 | [diff] [blame] | 575 | 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] | 576 | node_name: {{ HOSTNAME_CFG01 }} |
| 577 | retry: {count: 1, delay: 5} |
| 578 | skip_fail: false |
| 579 | {%- endmacro %} |
| 580 | |
| 581 | |
| 582 | {%- macro MACRO_BOOTSTRAP_ALL_MINIONS() %} |
| 583 | {########################################} |
| 584 | # Bootstrap all nodes |
| 585 | - description: Configure linux on other nodes |
| 586 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux |
| 587 | node_name: {{ HOSTNAME_CFG01 }} |
| 588 | retry: {count: 5, delay: 10} |
| 589 | skip_fail: false |
| 590 | |
| 591 | - description: Configure openssh on all nodes |
Dennis Dmitriev | 3e731a4 | 2017-08-30 17:12:59 +0300 | [diff] [blame] | 592 | 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] | 593 | salt --hard-crash --state-output=mixed --state-verbose=False |
| 594 | -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication |
| 595 | yes/' /etc/ssh/sshd_config && service ssh reload" |
| 596 | node_name: {{ HOSTNAME_CFG01 }} |
| 597 | retry: {count: 1, delay: 5} |
| 598 | skip_fail: false |
| 599 | |
| 600 | - description: Configure salt.minion on other nodes |
| 601 | cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls salt.minion && |
| 602 | sleep 10 |
| 603 | node_name: {{ HOSTNAME_CFG01 }} |
| 604 | retry: {count: 3, delay: 15} |
| 605 | skip_fail: false |
| 606 | |
| 607 | - description: Check salt minion versions on slaves |
Victor Ryzhenkin | 42e2423 | 2017-11-15 08:01:20 -0400 | [diff] [blame] | 608 | cmd: salt --timeout=60 '*' test.version |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 609 | node_name: {{ HOSTNAME_CFG01 }} |
| 610 | retry: {count: 3, delay: 15} |
| 611 | skip_fail: false |
| 612 | |
| 613 | - description: Check salt top states on nodes |
Victor Ryzhenkin | 42e2423 | 2017-11-15 08:01:20 -0400 | [diff] [blame] | 614 | cmd: salt --timeout=60 '*' state.show_top |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 615 | node_name: {{ HOSTNAME_CFG01 }} |
Victor Ryzhenkin | 42e2423 | 2017-11-15 08:01:20 -0400 | [diff] [blame] | 616 | retry: {count: 3, delay: 15} |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 617 | skip_fail: false |
| 618 | |
| 619 | - description: Configure ntp and rsyslog on nodes |
| 620 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog |
| 621 | node_name: {{ HOSTNAME_CFG01 }} |
| 622 | retry: {count: 1, delay: 10} |
| 623 | skip_fail: false |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 624 | {%- endmacro %} |
Dennis Dmitriev | 9dada8a | 2017-08-30 17:38:55 +0300 | [diff] [blame] | 625 | |
| 626 | |
| 627 | {%- macro MACRO_NETWORKING_WORKAROUNDS() %} |
| 628 | {#########################################} |
| 629 | |
Oleksii Butenko | f72f9d1 | 2017-10-18 13:10:04 +0300 | [diff] [blame] | 630 | #- description: '*Workaround 1/2* of the bug PROD-9576 to get bond0-connectivity *without* rebooting nodes' |
| 631 | # cmd: salt-call --hard-crash --state-output=mixed --state-verbose=False cmd.run |
| 632 | # "mkdir -p /tmp/PROD-9576; cd /tmp/PROD-9576; git clone https://gerrit.mcp.mirantis.net/salt-formulas/linux; cd linux; |
| 633 | # git fetch https://gerrit.mcp.mirantis.net/salt-formulas/linux refs/changes/54/2354/16 && git checkout FETCH_HEAD; |
| 634 | # cp -f linux/network/interface.sls /srv/salt/env/prd/linux/network/; |
| 635 | # cp -f linux/map.jinja /srv/salt/env/prd/linux/;" |
| 636 | # node_name: {{ HOSTNAME_CFG01 }} |
| 637 | # retry: {count: 1, delay: 5} |
| 638 | # skip_fail: false |
Dennis Dmitriev | 9dada8a | 2017-08-30 17:38:55 +0300 | [diff] [blame] | 639 | |
| 640 | - description: '*Workaround: Load bonding module before call state.linux' |
| 641 | cmd: salt -C "I@linux:network:interface:*:type:bond" cmd.run 'modprobe bonding' |
| 642 | node_name: {{ HOSTNAME_CFG01 }} |
| 643 | retry: {count: 1, delay: 5} |
Dennis Dmitriev | 0496eb7 | 2017-09-05 21:42:10 +0300 | [diff] [blame] | 644 | skip_fail: true |
Dennis Dmitriev | 9dada8a | 2017-08-30 17:38:55 +0300 | [diff] [blame] | 645 | |
| 646 | - description: '*Workaround* install bridge-utils before running linux formula' |
| 647 | # The formula removes default route and then tries to install the package, fails. |
| 648 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not |
| 649 | cfg01*' cmd.run 'sudo apt-get install -y bridge-utils' |
| 650 | node_name: {{ HOSTNAME_CFG01 }} |
| 651 | retry: {count: 1, delay: 5} |
| 652 | skip_fail: false |
| 653 | |
| 654 | {%- endmacro %} |
Victor Ryzhenkin | 9cc824c | 2017-10-12 19:02:23 +0400 | [diff] [blame] | 655 | |
| 656 | {%- macro ADJUST_K8S_OPTS() %} |
| 657 | {#########################################} |
| 658 | |
| 659 | - description: Set k8s deploy parameters |
| 660 | cmd: | |
| 661 | {% for k8s_opt, value in config.k8s_deploy.items() %} |
| 662 | {% if value|string() %} |
| 663 | salt-call reclass.cluster_meta_set name={{ k8s_opt }} value={{ value }}; |
| 664 | {% endif %} |
| 665 | {% endfor %} |
| 666 | node_name: {{ HOSTNAME_CFG01 }} |
| 667 | retry: {count: 1, delay: 1} |
| 668 | skip_fail: false |
| 669 | |
| 670 | {%- endmacro %} |
Victor Ryzhenkin | 42e2423 | 2017-11-15 08:01:20 -0400 | [diff] [blame] | 671 | |
| 672 | {%- macro REGISTER_COMPUTE_NODES() %} |
| 673 | {#########################################} |
| 674 | |
| 675 | {% for ssh in config.underlay.ssh %} |
| 676 | {% if ssh["node_name"].startswith("cmp") %} |
| 677 | {% set node_hostname = ssh["node_name"].split('.')[0] %} |
| 678 | - description: Register compute {{ ssh['node_name'] }} |
| 679 | cmd: | |
| 680 | exec > >(tee -i /tmp/cloud-init-bootstrap.log) 2>&1 |
| 681 | export network01_prefix={{ IPV4_NET_ADMIN_PREFIX }} |
| 682 | export network02_prefix={{ IPV4_NET_CONTROL_PREFIX }} |
Victor Ryzhenkin | 66593e9 | 2017-11-28 19:38:33 +0400 | [diff] [blame] | 683 | export cluster_name={{ CLUSTER_NAME }} |
Victor Ryzhenkin | 42e2423 | 2017-11-15 08:01:20 -0400 | [diff] [blame] | 684 | export config_host={{ config.salt.salt_master_host }} |
| 685 | export node_domain={{ DOMAIN_NAME }} |
| 686 | export nodes_os="xenial" |
| 687 | export node_hostname={{ node_hostname }} |
| 688 | set -xe |
| 689 | export BOOTSTRAP_SCRIPT_URL=$bootstrap_script_url |
| 690 | export BOOTSTRAP_SCRIPT_URL=${BOOTSTRAP_SCRIPT_URL:-https://raw.githubusercontent.com/salt-formulas/salt-formulas-scripts/master/bootstrap.sh} |
| 691 | export DISTRIB_REVISION={{ REPOSITORY_SUITE }} |
| 692 | export DISTRIB_REVISION=${DISTRIB_REVISION:-nightly} |
| 693 | |
| 694 | # Add wrapper to apt-get to avoid race conditions |
| 695 | # with cron jobs running 'unattended-upgrades' script |
| 696 | aptget_wrapper() { |
| 697 | local apt_wrapper_timeout=300 |
| 698 | local start_time=$(date '+%s') |
| 699 | local fin_time=$((start_time + apt_wrapper_timeout)) |
| 700 | while true; do |
| 701 | if (( "$(date '+%s')" > fin_time )); then |
| 702 | msg="Timeout exceeded ${apt_wrapper_timeout} s. Lock files are still not released. Terminating..." |
| 703 | fi |
| 704 | if fuser /var/lib/apt/lists/lock >/dev/null 2>&1 || fuser /var/lib/dpkg/lock >/dev/null 2>&1; then |
| 705 | echo "Waiting while another apt/dpkg process releases locks ..." |
| 706 | sleep 30 |
| 707 | continue |
| 708 | else |
| 709 | apt-get $@ |
| 710 | break |
| 711 | fi |
| 712 | done |
| 713 | } |
| 714 | |
| 715 | # Set default salt version |
| 716 | if [ -z "$saltversion" ]; then |
| 717 | saltversion="2016.3" |
| 718 | fi |
| 719 | echo "Using Salt version $saltversion" |
| 720 | |
| 721 | echo "Preparing base OS ..." |
| 722 | |
| 723 | case "$node_os" in |
| 724 | trusty) |
| 725 | # workaround for old cloud-init only configuring the first iface |
| 726 | iface_config_dir="/etc/network/interfaces" |
| 727 | ifaces=$(ip a | awk '/^[1-9]:/ {print $2}' | grep -v "lo:" | rev | cut -c2- | rev) |
| 728 | |
| 729 | for iface in $ifaces; do |
| 730 | grep $iface $iface_config_dir &> /dev/null || (echo -e "\nauto $iface\niface $iface inet dhcp" >> $iface_config_dir && ifup $iface) |
| 731 | done |
| 732 | |
| 733 | which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget) |
| 734 | |
| 735 | # SUGGESTED UPDATE: |
| 736 | #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion |
| 737 | #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL}) |
| 738 | ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service |
| 739 | #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION " |
| 740 | #install_salt_minion_pkg |
| 741 | |
| 742 | # DEPRECATED: |
| 743 | echo "deb [arch=amd64] http://apt-mk.mirantis.com/trusty ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list |
| 744 | wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add - |
| 745 | |
| 746 | echo "deb http://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion trusty main" > /etc/apt/sources.list.d/saltstack.list |
| 747 | wget -O - "https://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add - |
| 748 | |
| 749 | aptget_wrapper clean |
| 750 | aptget_wrapper update |
| 751 | aptget_wrapper install -y salt-common |
| 752 | aptget_wrapper install -y salt-minion |
| 753 | ;; |
| 754 | xenial) |
| 755 | |
| 756 | # workaround for new cloud-init setting all interfaces statically |
| 757 | which resolvconf > /dev/null 2>&1 && systemctl restart resolvconf |
| 758 | |
| 759 | which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget) |
| 760 | |
| 761 | # SUGGESTED UPDATE: |
| 762 | #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion |
| 763 | #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL}) |
| 764 | ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service |
| 765 | #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION " |
| 766 | #install_salt_minion_pkg |
| 767 | |
| 768 | # DEPRECATED: |
| 769 | echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list |
| 770 | wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add - |
| 771 | |
| 772 | echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion xenial main" > /etc/apt/sources.list.d/saltstack.list |
| 773 | wget -O - "https://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add - |
| 774 | |
| 775 | aptget_wrapper clean |
| 776 | aptget_wrapper update |
| 777 | aptget_wrapper install -y salt-minion |
| 778 | ;; |
| 779 | rhel|centos|centos7|centos7|rhel6|rhel7) |
| 780 | yum install -y git |
| 781 | export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion |
| 782 | source <(curl -qL ${BOOTSTRAP_SCRIPT_URL}) |
| 783 | # Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service |
| 784 | BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION " |
| 785 | install_salt_minion_pkg |
| 786 | ;; |
| 787 | *) |
| 788 | msg="OS '$node_os' is not supported." |
| 789 | esac |
| 790 | |
| 791 | echo "Configuring Salt minion ..." |
| 792 | [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d |
| 793 | echo -e "id: $node_hostname.$node_domain\nmaster: $config_host" > /etc/salt/minion.d/minion.conf |
| 794 | |
| 795 | service salt-minion restart || wait_condition_send "FAILURE" "Failed to restart salt-minion service." |
| 796 | |
| 797 | sleep 1 |
| 798 | |
| 799 | echo "Classifying node ..." |
| 800 | os_codename=$(salt-call grains.item oscodename --out key | awk '/oscodename/ {print $2}') |
| 801 | node_network01_ip="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')" |
| 802 | node_network02_ip="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')" |
| 803 | node_network03_ip="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')" |
| 804 | node_network04_ip="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')" |
| 805 | node_network05_ip="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')" |
| 806 | |
| 807 | node_network01_iface="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')" |
| 808 | node_network02_iface="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')" |
| 809 | node_network03_iface="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')" |
| 810 | node_network04_iface="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')" |
| 811 | node_network05_iface="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')" |
| 812 | |
| 813 | if [ "$node_network05_iface" != "" ]; then |
| 814 | node_network05_hwaddress="$(cat /sys/class/net/$node_network05_iface/address)" |
| 815 | fi |
| 816 | |
| 817 | # find more parameters (every env starting param_) |
| 818 | more_params=$(env | grep "^param_" | sed -e 's/=/":"/g' -e 's/^/"/g' -e 's/$/",/g' | tr "\n" " " | sed 's/, $//g') |
| 819 | if [ "$more_params" != "" ]; then |
| 820 | echo "Additional params: $more_params" |
| 821 | more_params=", $more_params" |
| 822 | fi |
| 823 | |
| 824 | salt-call event.send "reclass/minion/classify" "{\"node_master_ip\": \"$config_host\", \"node_os\": \"${os_codename}\", \"node_deploy_ip\": \"${node_network01_ip}\", \"node_deploy_iface\": \"${node_network01_iface}\", \"node_control_ip\": \"${node_network02_ip}\", \"node_control_iface\": \"${node_network02_iface}\", \"node_tenant_ip\": \"${node_network03_ip}\", \"node_tenant_iface\": \"${node_network03_iface}\", \"node_external_ip\": \"${node_network04_ip}\", \"node_external_iface\": \"${node_network04_iface}\", \"node_baremetal_ip\": \"${node_network05_ip}\", \"node_baremetal_iface\": \"${node_network05_iface}\", \"node_baremetal_hwaddress\": \"${node_network05_hwaddress}\", \"node_domain\": \"$node_domain\", \"node_cluster\": \"$cluster_name\", \"node_hostname\": \"$node_hostname\"${more_params}}" |
| 825 | |
| 826 | sleep 5 |
| 827 | |
| 828 | salt-call saltutil.sync_all |
| 829 | salt-call mine.flush |
| 830 | salt-call mine.update |
| 831 | node_name: {{ ssh['node_name'] }} |
| 832 | retry: {count: 1, delay: 1} |
| 833 | skip_fail: false |
| 834 | {%- endif %} |
| 835 | {%- endfor %} |
| 836 | |
| 837 | - description: Refresh pillars on all minions |
| 838 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar |
| 839 | node_name: {{ HOSTNAME_CFG01 }} |
| 840 | retry: {count: 1, delay: 5} |
| 841 | skip_fail: false |
| 842 | |
| 843 | - description: Sync all salt resources |
| 844 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5 |
| 845 | node_name: {{ HOSTNAME_CFG01 }} |
| 846 | retry: {count: 1, delay: 5} |
| 847 | skip_fail: false |
| 848 | |
| 849 | {%- endmacro %} |