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