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