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