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