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