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','') %} |
Tatyana Leontovich | 819a6c8 | 2018-06-04 12:05:16 +0300 | [diff] [blame] | 11 | {% set SALT_MODELS_SYSTEM_TAG = os_env('SALT_MODELS_SYSTEM_TAG','') %} |
sgudz | 4d816eb | 2017-11-13 11:58:05 +0200 | [diff] [blame] | 12 | {% set COOKIECUTTER_REF_CHANGE = os_env('COOKIECUTTER_REF_CHANGE','') %} |
Tatyana Leontovich | 819a6c8 | 2018-06-04 12:05:16 +0300 | [diff] [blame] | 13 | {% set COOKIECUTTER_TAG = os_env('COOKIECUTTER_TAG','') %} |
sgudz | a399dc7 | 2018-01-18 17:13:48 +0200 | [diff] [blame] | 14 | {% set COOKIECUTTER_TEMPLATE_COMMIT = os_env('COOKIECUTTER_TEMPLATE_COMMIT','') %} |
sgudz | cced67d | 2017-10-11 15:56:09 +0300 | [diff] [blame] | 15 | {% set ENVIRONMENT_TEMPLATE_REF_CHANGE = os_env('ENVIRONMENT_TEMPLATE_REF_CHANGE','') %} |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 16 | |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 17 | {% set REPOSITORY_SUITE = os_env('REPOSITORY_SUITE', 'testing') %} |
Dennis Dmitriev | cf77780 | 2018-02-14 18:09:55 +0200 | [diff] [blame] | 18 | {% 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] | 19 | {% set FORMULA_GPG = os_env('FORMULA_GPG', 'http://apt.mirantis.com/public.gpg') %} |
Tatyana Leontovich | 908ab93 | 2018-04-27 01:25:09 +0300 | [diff] [blame] | 20 | #{% set SALT_REPOSITORY = os_env('SALT_REPOSITORY', "deb [arch=amd64] http://apt.mirantis.com/${DISTRIB_CODENAME}/salt/2016.3 " + REPOSITORY_SUITE + " main") %} |
| 21 | {% set SALT_REPOSITORY = os_env('SALT_REPOSITORY', "deb [arch=amd64] http://mirror.mirantis.com/" + REPOSITORY_SUITE+ "/saltstack-2016.3/${DISTRIB_CODENAME} ${DISTRIB_CODENAME} main") %} |
Dennis Dmitriev | cf77780 | 2018-02-14 18:09:55 +0200 | [diff] [blame] | 22 | {% set SALT_GPG = os_env('SALT_GPG', 'http://apt.mirantis.com/public.gpg') %} |
| 23 | {% set UBUNTU_REPOSITORY = os_env('UBUNTU_REPOSITORY', "deb [arch=amd64] http://mirror.mirantis.com/" + REPOSITORY_SUITE + "/ubuntu/ ${DISTRIB_CODENAME} main restricted universe") %} |
| 24 | {% 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") %} |
| 25 | {% 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 | 9a532a5 | 2018-05-07 13:55:27 +0300 | [diff] [blame] | 26 | {% set UBUNTU_KEY_SERVER = os_env('UBUNTU_KEY_SERVER', 'keyserver.ubuntu.com') %} |
Tatyana Leontovich | 908ab93 | 2018-04-27 01:25:09 +0300 | [diff] [blame] | 27 | {% set UBUNTU_KEY_ID = os_env('UBUNTU_KEY_ID', '0E08A149DE57BFBE') %} |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 28 | |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 29 | {# Address pools for reclass cluster model are taken in the following order: |
| 30 | # 1. environment variables, |
| 31 | # 2. config.underlay.address_pools based on fuel-devops address pools |
| 32 | # (see generated '.ini' file after underlay is created), |
| 33 | # 3. defaults #} |
| 34 | {% set address_pools = config.underlay.address_pools %} |
| 35 | {% set IPV4_NET_ADMIN = os_env('IPV4_NET_ADMIN', address_pools.get('admin-pool01', '192.168.10.0/24')) %} |
| 36 | {% set IPV4_NET_CONTROL = os_env('IPV4_NET_CONTROL', address_pools.get('private-pool01', '172.16.10.0/24')) %} |
| 37 | {% set IPV4_NET_TENANT = os_env('IPV4_NET_TENANT', address_pools.get('tenant-pool01', '10.1.0.0/24')) %} |
| 38 | {% set IPV4_NET_EXTERNAL = os_env('IPV4_NET_EXTERNAL', address_pools.get('external-pool01', '10.16.0.0/24')) %} |
| 39 | {% set IPV4_NET_ADMIN_PREFIX = '.'.join(IPV4_NET_ADMIN.split('.')[0:3]) %} |
| 40 | {% set IPV4_NET_CONTROL_PREFIX = '.'.join(IPV4_NET_CONTROL.split('.')[0:3]) %} |
| 41 | {% set IPV4_NET_TENANT_PREFIX = '.'.join(IPV4_NET_TENANT.split('.')[0:3]) %} |
| 42 | {% set IPV4_NET_EXTERNAL_PREFIX = '.'.join(IPV4_NET_EXTERNAL.split('.')[0:3]) %} |
| 43 | |
Victor Ryzhenkin | 4e077ad | 2017-08-10 13:42:11 +0400 | [diff] [blame] | 44 | {# Format for formula replacement: |
| 45 | # space separated string: |
| 46 | # export SALT_FORMULAS_REFS='apache:refs/changes/xxxx kubernetes:refs/changes/xxxx' #} |
| 47 | |
| 48 | {% set SALT_FORMULAS_REFS = os_env('SALT_FORMULAS_REFS', '') %} |
Tatyana Leontovich | 1c10131 | 2018-04-18 20:33:08 +0300 | [diff] [blame] | 49 | {% set TEMPEST_PATTERN = os_env('TEMPEST_PATTERN', 'tempest') %} |
Tatyana Leontovich | 6970071 | 2018-04-23 12:26:57 +0300 | [diff] [blame] | 50 | {% set EXCLUDE_TEST_ARGS = os_env('EXCLUDE_TEST_ARGS', '') %} |
Victor Ryzhenkin | 4e077ad | 2017-08-10 13:42:11 +0400 | [diff] [blame] | 51 | {% set SALT_FORMULAS_REPO = os_env('SALT_FORMULAS_REPO', 'https://gerrit.mcp.mirantis.net/salt-formulas') %} |
| 52 | |
Victor Ryzhenkin | 66593e9 | 2017-11-28 19:38:33 +0400 | [diff] [blame] | 53 | # Needed for using different models in different templates |
Dennis Dmitriev | bdb2b9b | 2017-12-22 18:00:18 +0200 | [diff] [blame] | 54 | {% set CLUSTER_NAME = os_env('CLUSTER_NAME', LAB_CONFIG_NAME) %} |
Victor Ryzhenkin | 66593e9 | 2017-11-28 19:38:33 +0400 | [diff] [blame] | 55 | |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 56 | |
Dennis Dmitriev | 3fbbc7f | 2017-12-21 15:42:14 +0200 | [diff] [blame] | 57 | {%- macro MACRO_INSTALL_PACKAGES_ON_NODES(NODE_NAME) %} |
| 58 | {#####################################################} |
| 59 | |
| 60 | - description: 'Configure key on nodes and install packages' |
| 61 | cmd: | |
| 62 | rm -rf trusted* ; |
| 63 | rm -rf /etc/apt/sources.list ; |
Dennis Dmitriev | cf77780 | 2018-02-14 18:09:55 +0200 | [diff] [blame] | 64 | . /etc/lsb-release; # Get DISTRIB_CODENAME variable |
Dennis Dmitriev | 3fbbc7f | 2017-12-21 15:42:14 +0200 | [diff] [blame] | 65 | echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list; |
| 66 | wget -O - "{{ FORMULA_GPG }}" | apt-key add -; |
| 67 | echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list; |
Tatyana Leontovich | 908ab93 | 2018-04-27 01:25:09 +0300 | [diff] [blame] | 68 | apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}" |
Dennis Dmitriev | 3fbbc7f | 2017-12-21 15:42:14 +0200 | [diff] [blame] | 69 | echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu.list |
| 70 | echo "{{ UBUNTU_UPDATES_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_updates.list |
| 71 | echo "{{ UBUNTU_SECURITY_REPOSITORY }}" > /etc/apt/sources.list.d/ubuntu_security.list |
Dennis Dmitriev | f4e6efc | 2018-03-26 06:15:10 -0500 | [diff] [blame] | 72 | eatmydata apt-get clean; |
| 73 | apt-get update; |
Dennis Dmitriev | 01d5e37 | 2018-03-15 23:29:29 +0200 | [diff] [blame] | 74 | sync; |
Dennis Dmitriev | 3fbbc7f | 2017-12-21 15:42:14 +0200 | [diff] [blame] | 75 | node_name: {{ NODE_NAME }} |
| 76 | retry: {count: 1, delay: 5} |
| 77 | skip_fail: false |
| 78 | |
| 79 | {%- endmacro %} |
| 80 | |
| 81 | |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 82 | {%- macro MACRO_INSTALL_SALT_MASTER() %} |
| 83 | {######################################} |
| 84 | - description: Installing salt master on cfg01 |
Dennis Dmitriev | cf77780 | 2018-02-14 18:09:55 +0200 | [diff] [blame] | 85 | cmd: | |
| 86 | which wget >/dev/null || (apt-get update; apt-get install -y wget); |
| 87 | # Configure ubuntu and salt repositories |
| 88 | . /etc/lsb-release; # Get DISTRIB_CODENAME variable |
| 89 | echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list |
| 90 | echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list |
| 91 | echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list |
| 92 | |
| 93 | echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list; |
| 94 | wget -O - {{ FORMULA_GPG }} | apt-key add -; |
| 95 | echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list; |
Tatyana Leontovich | 908ab93 | 2018-04-27 01:25:09 +0300 | [diff] [blame] | 96 | apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}" |
| 97 | |
Dennis Dmitriev | cf77780 | 2018-02-14 18:09:55 +0200 | [diff] [blame] | 98 | |
| 99 | apt-get clean |
| 100 | apt-get update |
| 101 | |
| 102 | # Install salt-master and reclass |
| 103 | eatmydata apt-get install -y --allow-unauthenticated reclass salt-master |
| 104 | # Install common packages |
Dennis Dmitriev | f88fc7d | 2018-02-20 15:40:08 +0200 | [diff] [blame] | 105 | eatmydata apt-get install -y python-pip git curl at tmux byobu iputils-ping traceroute htop tree mc |
Dennis Dmitriev | 01d5e37 | 2018-03-15 23:29:29 +0200 | [diff] [blame] | 106 | sync; |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 107 | node_name: {{ HOSTNAME_CFG01 }} |
| 108 | retry: {count: 1, delay: 1} |
| 109 | skip_fail: false |
| 110 | |
Dennis Dmitriev | da9be46 | 2018-01-24 21:20:09 +0200 | [diff] [blame] | 111 | - description: Remove any existing minion keys |
| 112 | cmd: salt-key -y -D || true |
| 113 | node_name: {{ HOSTNAME_CFG01 }} |
| 114 | retry: {count: 1, delay: 1} |
| 115 | skip_fail: false |
| 116 | |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 117 | - description: Configure salt-master on cfg01 |
| 118 | cmd: | |
Dennis Dmitriev | a578c77 | 2018-01-24 21:02:15 +0200 | [diff] [blame] | 119 | cat << 'EOF' > /etc/salt/master.d/master.conf |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 120 | file_roots: |
| 121 | base: |
| 122 | - /usr/share/salt-formulas/env |
| 123 | pillar_opts: False |
| 124 | open_mode: True |
| 125 | reclass: &reclass |
| 126 | storage_type: yaml_fs |
| 127 | inventory_base_uri: /srv/salt/reclass |
| 128 | ext_pillar: |
| 129 | - reclass: *reclass |
| 130 | master_tops: |
| 131 | reclass: *reclass |
| 132 | EOF |
| 133 | node_name: {{ HOSTNAME_CFG01 }} |
| 134 | retry: {count: 1, delay: 1} |
| 135 | skip_fail: false |
| 136 | |
| 137 | - description: Configure GIT settings and certificates |
Dennis Dmitriev | 3e731a4 | 2017-08-30 17:12:59 +0300 | [diff] [blame] | 138 | cmd: | |
| 139 | set -e; |
Dennis Dmitriev | 3fbbc7f | 2017-12-21 15:42:14 +0200 | [diff] [blame] | 140 | #touch /root/.git_trusted_certs.pem; |
| 141 | #for server in github.com; do \ |
| 142 | # openssl s_client -showcerts -connect $server:443 </dev/null \ |
| 143 | # | openssl x509 -outform PEM \ |
| 144 | # >> /root/.git_trusted_certs.pem; |
| 145 | #done; |
| 146 | #HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem; |
| 147 | HOME=/root git config --global user.email "mcp-integration-qa@example.com"; |
| 148 | HOME=/root git config --global user.name "MCP Integration QA"; |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 149 | node_name: {{ HOSTNAME_CFG01 }} |
| 150 | retry: {count: 1, delay: 1} |
| 151 | skip_fail: false |
| 152 | {%- endmacro %} |
| 153 | |
Dmitry Tyzhnenko | 35413c0 | 2018-03-05 14:12:37 +0200 | [diff] [blame] | 154 | |
| 155 | {%- macro MACRO_CONFIG_DAY01_SALT_MASTER() %} |
| 156 | {######################################} |
| 157 | |
| 158 | - description: Remove /etc/update-motd.d/52-info |
| 159 | cmd: rm -vf /etc/update-motd.d/52-info |
| 160 | node_name: {{ HOSTNAME_CFG01 }} |
| 161 | retry: {count: 1, delay: 10} |
| 162 | skip_fail: false |
| 163 | |
| 164 | - description: Set up static interface config |
| 165 | cmd: | |
| 166 | kill $(pidof /sbin/dhclient) || /bin/true |
| 167 | cat << 'EOF' > /etc/network/interfaces |
| 168 | # This file describes the network interfaces available on your system |
| 169 | # and how to activate them. For more information, see interfaces(5). |
| 170 | |
| 171 | # The loopback network interface |
| 172 | auto lo |
| 173 | iface lo inet loopback |
| 174 | |
| 175 | # The primary network interface |
| 176 | auto ens3 |
| 177 | iface ens3 inet static |
| 178 | address {{ IPV4_NET_ADMIN_PREFIX }}.90 |
| 179 | netmask 255.255.255.0 |
| 180 | gateway {{ IPV4_NET_ADMIN_PREFIX }}.1 |
| 181 | EOF |
| 182 | node_name: {{ HOSTNAME_CFG01 }} |
| 183 | retry: {count: 1, delay: 10} |
| 184 | skip_fail: false |
| 185 | |
| 186 | - description: Install common packages on cfg01 |
| 187 | cmd: eatmydata apt-get update && apt-get install -y python-pip git curl at tmux byobu iputils-ping traceroute htop tree wget jq ntpdate |
| 188 | node_name: {{ HOSTNAME_CFG01 }} |
| 189 | retry: {count: 1, delay: 1} |
| 190 | skip_fail: false |
| 191 | |
| 192 | - description: Remove any existing minion keys |
| 193 | cmd: salt-key -y -D || true |
| 194 | node_name: {{ HOSTNAME_CFG01 }} |
| 195 | retry: {count: 1, delay: 1} |
| 196 | skip_fail: false |
| 197 | |
| 198 | - description: Configure GIT settings and certificates |
| 199 | cmd: | |
| 200 | set -e; |
| 201 | #touch /root/.git_trusted_certs.pem; |
| 202 | #for server in github.com; do \ |
| 203 | # openssl s_client -showcerts -connect $server:443 </dev/null \ |
| 204 | # | openssl x509 -outform PEM \ |
| 205 | # >> /root/.git_trusted_certs.pem; |
| 206 | #done; |
| 207 | #HOME=/root git config --global http.sslCAInfo /root/.git_trusted_certs.pem; |
| 208 | HOME=/root git config --global user.email "mcp-integration-qa@example.com"; |
| 209 | HOME=/root git config --global user.name "MCP Integration QA"; |
| 210 | node_name: {{ HOSTNAME_CFG01 }} |
| 211 | retry: {count: 1, delay: 1} |
| 212 | skip_fail: false |
| 213 | {%- endmacro %} |
| 214 | |
| 215 | |
Dmitry Tyzhnenko | 1fe62a8 | 2018-06-01 12:54:26 +0300 | [diff] [blame] | 216 | {%- macro MACRO_CLONE_RECLASS_MODELS(IS_CONTRAIL_LAB=false, WITH_MAAS=false) %} |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 217 | {############################################################} |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 218 | {# Creates a 'cluster' model from cookiecutter-templates and 'environment' model from uploaded template #} |
| 219 | |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 220 | - description: Clone reclass models with submodules |
| 221 | cmd: | |
Dennis Dmitriev | 3e731a4 | 2017-08-30 17:12:59 +0300 | [diff] [blame] | 222 | set -e; |
Dennis Dmitriev | 75776c5 | 2017-12-26 18:22:53 +0200 | [diff] [blame] | 223 | set -x; |
Dennis Dmitriev | 3fbbc7f | 2017-12-21 15:42:14 +0200 | [diff] [blame] | 224 | #ssh-keyscan -H github.com >> ~/.ssh/known_hosts; |
Dennis Dmitriev | f00a384 | 2018-01-24 16:44:26 +0200 | [diff] [blame] | 225 | |
| 226 | # In the day01 image, /srv/salt/reclass directory is already exists, so clone the model into the reclass.tmp directory |
| 227 | 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] | 228 | rsync -a /srv/salt/reclass.tmp/ /srv/salt/reclass; |
Dennis Dmitriev | f00a384 | 2018-01-24 16:44:26 +0200 | [diff] [blame] | 229 | |
Dennis Dmitriev | 55ddd79 | 2017-12-22 16:35:57 +0200 | [diff] [blame] | 230 | pushd /srv/salt/reclass; |
| 231 | git config submodule."classes/system".url "{{ SALT_MODELS_SYSTEM_REPOSITORY }}"; |
| 232 | git submodule update --init --recursive; |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 233 | {%- if SALT_MODELS_REF_CHANGE != '' %} |
| 234 | {%- for item in SALT_MODELS_REF_CHANGE.split(" ") %} |
Dennis Dmitriev | 55ddd79 | 2017-12-22 16:35:57 +0200 | [diff] [blame] | 235 | git fetch {{ SALT_MODELS_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD; |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 236 | {%- endfor %} |
| 237 | {%- elif SALT_MODELS_COMMIT != 'master' %} |
Dennis Dmitriev | 55ddd79 | 2017-12-22 16:35:57 +0200 | [diff] [blame] | 238 | git checkout {{ SALT_MODELS_COMMIT }}; |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 239 | {%- endif %} |
| 240 | {%- if SALT_MODELS_SYSTEM_COMMIT != '' %} |
Dennis Dmitriev | 55ddd79 | 2017-12-22 16:35:57 +0200 | [diff] [blame] | 241 | pushd classes/system/; |
| 242 | git checkout {{ SALT_MODELS_SYSTEM_COMMIT }}; |
| 243 | popd; |
Tatyana Leontovich | 819a6c8 | 2018-06-04 12:05:16 +0300 | [diff] [blame] | 244 | {%- if SALT_MODELS_SYSTEM_TAG != '' %} |
| 245 | pushd classes/system/; |
| 246 | git fetch --all --tags --prune |
| 247 | git checkout tags/{{ SALT_MODELS_SYSTEM_TAG }}; |
| 248 | popd; |
| 249 | {%- endif %} |
sgudz | 4d816eb | 2017-11-13 11:58:05 +0200 | [diff] [blame] | 250 | {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %} |
Dmitry Tyzhnenko | 778515f | 2017-08-25 14:52:54 +0300 | [diff] [blame] | 251 | pushd classes/system/ && \ |
| 252 | {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %} |
Dennis Dmitriev | 55ddd79 | 2017-12-22 16:35:57 +0200 | [diff] [blame] | 253 | git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD; |
Dmitry Tyzhnenko | 778515f | 2017-08-25 14:52:54 +0300 | [diff] [blame] | 254 | {%- endfor %} |
Dennis Dmitriev | 55ddd79 | 2017-12-22 16:35:57 +0200 | [diff] [blame] | 255 | popd; |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 256 | {%- endif %} |
| 257 | popd; |
| 258 | mkdir -p /srv/salt/reclass/classes/service; |
Dennis Dmitriev | b2e78be | 2017-09-26 23:25:24 +0300 | [diff] [blame] | 259 | mkdir -p /srv/salt/reclass/nodes/_generated/; |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 260 | |
| 261 | # Replace firstly to an intermediate value to avoid intersection between |
| 262 | # already replaced and replacing networks. |
| 263 | # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice: |
| 264 | # 192.168.10 -> 10.16.0 (generated network for admin) |
| 265 | # 10.16.0 -> <external network> |
| 266 | # 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] | 267 | export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/" |
Dennis Dmitriev | 806f3b5 | 2018-02-26 18:04:24 +0200 | [diff] [blame] | 268 | find ${REPLACE_DIRS} -type f -exec sed -i 's/192\.168\.10/==IPV4_NET_ADMIN_PREFIX==/g' {} + |
| 269 | find ${REPLACE_DIRS} -type f -exec sed -i 's/172\.16\.10/==IPV4_NET_CONTROL_PREFIX==/g' {} + |
| 270 | find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.1\.0/==IPV4_NET_TENANT_PREFIX==/g' {} + |
| 271 | find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.16\.0/==IPV4_NET_EXTERNAL_PREFIX==/g' {} + |
Tatyana Leontovich | 2675691 | 2018-06-06 20:11:05 +0300 | [diff] [blame] | 272 | find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.60\.0/==IPV4_NET_CONTROL_PREFIX==/g' {} + |
| 273 | find ${REPLACE_DIRS} -type f -exec sed -i 's/10\.70\.0/==IPV4_NET_ADMIN_PREFIX==/g' {} + |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 274 | |
Dennis Dmitriev | 806f3b5 | 2018-02-26 18:04:24 +0200 | [diff] [blame] | 275 | find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {} + |
| 276 | find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {} + |
| 277 | find ${REPLACE_DIRS} -type f -exec sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {} + |
| 278 | 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] | 279 | |
Dennis Dmitriev | 9d9ba9f | 2017-09-13 17:34:03 +0300 | [diff] [blame] | 280 | 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] | 281 | |
Tatyana Leontovich | a4a96b2 | 2018-04-25 14:30:24 +0300 | [diff] [blame] | 282 | {%- if IS_CONTRAIL_LAB %} |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 283 | # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded |
Dennis Dmitriev | 9d9ba9f | 2017-09-13 17:34:03 +0300 | [diff] [blame] | 284 | 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] | 285 | 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] | 286 | {%- endif %} |
| 287 | |
Dennis Dmitriev | f5bef57 | 2017-12-24 17:52:41 +0200 | [diff] [blame] | 288 | # Override some context parameters |
| 289 | {%- set CLUSTER_PATH = '/srv/salt/reclass/classes/cluster/' + CLUSTER_NAME %} |
| 290 | find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {} + |
| 291 | find {{ CLUSTER_PATH }} -type f -exec sed -i 's/cluster_domain: .*/cluster_domain: {{ DOMAIN_NAME }}/g' {} + |
| 292 | |
Dennis Dmitriev | 97e78e2 | 2018-02-23 21:51:49 +0200 | [diff] [blame] | 293 | # Create the cfg01 inventory file or use existing |
| 294 | export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml" |
| 295 | [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE} |
Dennis Dmitriev | b2e78be | 2017-09-26 23:25:24 +0300 | [diff] [blame] | 296 | classes: |
Victor Ryzhenkin | 66593e9 | 2017-11-28 19:38:33 +0400 | [diff] [blame] | 297 | - cluster.{{ CLUSTER_NAME }}.infra.config |
Dmitry Tyzhnenko | 1fe62a8 | 2018-06-01 12:54:26 +0300 | [diff] [blame] | 298 | {%- if WITH_MAAS %} |
Dmitry Tyzhnenko | 35413c0 | 2018-03-05 14:12:37 +0200 | [diff] [blame] | 299 | - cluster.{{ CLUSTER_NAME }}.infra.maas |
| 300 | - cluster.{{ CLUSTER_NAME }}.infra.maas-machines |
Dmitry Tyzhnenko | 1fe62a8 | 2018-06-01 12:54:26 +0300 | [diff] [blame] | 301 | {%- endif %} |
Dennis Dmitriev | b2e78be | 2017-09-26 23:25:24 +0300 | [diff] [blame] | 302 | parameters: |
| 303 | _param: |
| 304 | linux_system_codename: xenial |
| 305 | reclass_data_revision: master |
| 306 | linux: |
| 307 | system: |
| 308 | name: cfg01 |
| 309 | domain: {{ DOMAIN_NAME }} |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 310 | reclass: |
| 311 | storage: |
| 312 | data_source: |
| 313 | engine: local |
| 314 | EOF |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 315 | |
| 316 | # Show the changes to the console |
| 317 | cd /srv/salt/reclass/; git diff |
| 318 | node_name: {{ HOSTNAME_CFG01 }} |
| 319 | retry: {count: 1, delay: 1} |
| 320 | skip_fail: false |
| 321 | {%- endmacro %} |
| 322 | |
| 323 | |
sgudz | 160b730 | 2017-12-22 17:01:10 +0200 | [diff] [blame] | 324 | {%- 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] | 325 | {###################################################################} |
Dennis Dmitriev | 1c1352a | 2017-09-28 21:45:27 +0300 | [diff] [blame] | 326 | {%- set CLUSTER_CONTEXT_PATH = '/tmp/' + CLUSTER_CONTEXT_NAME %} |
Dennis Dmitriev | 92295c0 | 2018-02-02 13:18:25 +0200 | [diff] [blame] | 327 | - description: "[EXPERIMENTAL] Upload cookiecutter-templates context to cfg01.{{ DOMAIN_NAME }}" |
Dennis Dmitriev | ccdc87a | 2017-09-28 17:43:54 +0300 | [diff] [blame] | 328 | upload: |
| 329 | local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/ |
| 330 | local_filename: {{ CLUSTER_CONTEXT_NAME }} |
Dennis Dmitriev | 1c1352a | 2017-09-28 21:45:27 +0300 | [diff] [blame] | 331 | remote_path: /tmp/ |
Dennis Dmitriev | ccdc87a | 2017-09-28 17:43:54 +0300 | [diff] [blame] | 332 | node_name: {{ HOSTNAME_CFG01 }} |
| 333 | |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 334 | - description: Create cluster model from cookiecutter templates |
| 335 | cmd: | |
| 336 | set -e; |
Dmitry Tyzhnenko | 1fe62a8 | 2018-06-01 12:54:26 +0300 | [diff] [blame] | 337 | sudo apt-get install python-setuptools -y |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 338 | pip install cookiecutter |
| 339 | 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] | 340 | |
sgudz | a399dc7 | 2018-01-18 17:13:48 +0200 | [diff] [blame] | 341 | {%- if COOKIECUTTER_TEMPLATE_COMMIT != '' %} |
| 342 | pushd /tmp/cookiecutter-templates |
| 343 | git checkout {{ COOKIECUTTER_TEMPLATE_COMMIT }} |
| 344 | popd |
| 345 | {%- endif %} |
| 346 | |
sgudz | 4d816eb | 2017-11-13 11:58:05 +0200 | [diff] [blame] | 347 | {%- if COOKIECUTTER_REF_CHANGE != '' %} |
| 348 | pushd /tmp/cookiecutter-templates |
| 349 | git fetch https://gerrit.mcp.mirantis.net/mk/cookiecutter-templates {{ COOKIECUTTER_REF_CHANGE }} && git checkout FETCH_HEAD |
| 350 | popd |
| 351 | {%- endif %} |
| 352 | |
Tatyana Leontovich | 819a6c8 | 2018-06-04 12:05:16 +0300 | [diff] [blame] | 353 | {%- if COOKIECUTTER_TAG != '' %} |
| 354 | pushd /tmp/cookiecutter-templates |
| 355 | git fetch --all --tags --prune |
| 356 | git checkout tags/{{ COOKIECUTTER_TAG }} |
| 357 | popd |
| 358 | {%- endif %} |
| 359 | |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 360 | mkdir -p /srv/salt/reclass/classes/cluster/ |
| 361 | mkdir -p /srv/salt/reclass/classes/system/ |
| 362 | mkdir -p /srv/salt/reclass/classes/service/ |
| 363 | mkdir -p /srv/salt/reclass/nodes/_generated |
| 364 | |
| 365 | # Override some context parameters |
Dennis Dmitriev | f5bef57 | 2017-12-24 17:52:41 +0200 | [diff] [blame] | 366 | sed -i 's/cluster_name: .*/cluster_name: {{ CLUSTER_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }} |
| 367 | 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] | 368 | sed -i 's/mcp_version:.*/mcp_version: {{ REPOSITORY_SUITE }}/g' {{ CLUSTER_CONTEXT_PATH }} |
sgudz | 8c888ec | 2017-10-02 15:29:23 +0300 | [diff] [blame] | 369 | {%- if CONTROL_VLAN %} |
Dennis Dmitriev | f5bef57 | 2017-12-24 17:52:41 +0200 | [diff] [blame] | 370 | sed -i 's/control_vlan: .*/control_vlan: {{ CONTROL_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }} |
sgudz | 8c888ec | 2017-10-02 15:29:23 +0300 | [diff] [blame] | 371 | {%- endif %} |
| 372 | {%- if TENANT_VLAN %} |
Dennis Dmitriev | f5bef57 | 2017-12-24 17:52:41 +0200 | [diff] [blame] | 373 | sed -i 's/tenant_vlan: .*/tenant_vlan: {{ TENANT_VLAN }}/g' {{ CLUSTER_CONTEXT_PATH }} |
sgudz | 8c888ec | 2017-10-02 15:29:23 +0300 | [diff] [blame] | 374 | {%- endif %} |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 375 | |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 376 | # Replace firstly to an intermediate value to avoid intersection between |
| 377 | # already replaced and replacing networks. |
| 378 | # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice: |
| 379 | # 192.168.10 -> 10.16.0 (generated network for admin) |
| 380 | # 10.16.0 -> <external network> |
| 381 | # So let's replace constant networks to the keywords, and then keywords to the desired networks. |
| 382 | sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }} |
| 383 | sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }} |
| 384 | sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }} |
Dennis Dmitriev | 806f3b5 | 2018-02-26 18:04:24 +0200 | [diff] [blame] | 385 | sed -i 's/172\.17\.16/==IPV4_NET_EXTERNAL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }} |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 386 | |
Dennis Dmitriev | 39e64bd | 2017-09-21 22:37:40 +0300 | [diff] [blame] | 387 | sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ IPV4_NET_ADMIN_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }} |
| 388 | sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ IPV4_NET_CONTROL_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }} |
| 389 | sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ IPV4_NET_TENANT_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }} |
Dennis Dmitriev | 806f3b5 | 2018-02-26 18:04:24 +0200 | [diff] [blame] | 390 | 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] | 391 | |
sgudz | 160b730 | 2017-12-22 17:01:10 +0200 | [diff] [blame] | 392 | {% set items = CLUSTER_PRODUCT_MODELS or '$(ls /tmp/cookiecutter-templates/cluster_product/)' %} |
| 393 | for item in {{ items }}; do |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 394 | python /tmp/cookiecutter-templates/generate.py \ |
sgudz | 160b730 | 2017-12-22 17:01:10 +0200 | [diff] [blame] | 395 | --template /tmp/cookiecutter-templates/cluster_product/$item \ |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 396 | --config-file {{ CLUSTER_CONTEXT_PATH }} \ |
| 397 | --output-dir /srv/salt/reclass/classes/cluster/; |
| 398 | done |
| 399 | |
| 400 | export GIT_SSL_NO_VERIFY=true; git clone https://gerrit.mcp.mirantis.net/salt-models/reclass-system /srv/salt/reclass/classes/system/ |
| 401 | |
Dennis Dmitriev | 97e78e2 | 2018-02-23 21:51:49 +0200 | [diff] [blame] | 402 | # Create the cfg01 inventory file or use existing |
| 403 | export CFG01_INVENTORY_FILE="/srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml" |
| 404 | [ -f ${CFG01_INVENTORY_FILE} ] || cat << 'EOF' > ${CFG01_INVENTORY_FILE} |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 405 | classes: |
| 406 | - system.openssh.server.team.all |
Dennis Dmitriev | bdb2b9b | 2017-12-22 18:00:18 +0200 | [diff] [blame] | 407 | - cluster.{{ CLUSTER_NAME }}.infra.config |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 408 | EOF |
| 409 | |
| 410 | node_name: {{ HOSTNAME_CFG01 }} |
| 411 | retry: {count: 1, delay: 1} |
| 412 | skip_fail: false |
| 413 | |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 414 | - description: Modify generated model and reclass-system if necessary |
| 415 | cmd: | |
| 416 | set -e; |
| 417 | {%- if SALT_MODELS_SYSTEM_COMMIT != '' %} |
| 418 | pushd /srv/salt/reclass/classes/system/ |
| 419 | git checkout {{ SALT_MODELS_SYSTEM_COMMIT }} && \ |
| 420 | popd |
sgudz | 4d816eb | 2017-11-13 11:58:05 +0200 | [diff] [blame] | 421 | {%- elif SALT_MODELS_SYSTEM_REF_CHANGE != '' %} |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 422 | pushd /srv/salt/reclass/classes/system/ |
| 423 | {%- for item in SALT_MODELS_SYSTEM_REF_CHANGE.split(" ") %} |
| 424 | git fetch {{ SALT_MODELS_SYSTEM_REPOSITORY }} {{ item }} && git cherry-pick FETCH_HEAD |
| 425 | {%- endfor %} |
| 426 | popd |
| 427 | {%- endif %} |
| 428 | |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 429 | {%- if IS_CONTRAIL_LAB %} |
Dennis Dmitriev | 862f775 | 2018-01-19 17:12:11 +0200 | [diff] [blame] | 430 | export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/" |
Dennis Dmitriev | a5f38e4 | 2017-09-21 21:52:25 +0300 | [diff] [blame] | 431 | # vSRX IPs for tcp-qa images have 172.16.10.90 hardcoded |
| 432 | find ${REPLACE_DIRS} -type f -exec sed -i 's/opencontrail_router01_address:.*/opencontrail_router01_address: 172.16.10.90/g' {} + |
| 433 | find ${REPLACE_DIRS} -type f -exec sed -i 's/infra_config_deploy_address: 1.*/infra_config_deploy_address: {{ IPV4_NET_ADMIN_PREFIX }}.15/g' {} + |
| 434 | {%- endif %} |
| 435 | |
| 436 | node_name: {{ HOSTNAME_CFG01 }} |
| 437 | retry: {count: 1, delay: 1} |
| 438 | skip_fail: false |
| 439 | {%- endmacro %} |
| 440 | |
| 441 | |
Dennis Dmitriev | 9f141af | 2017-09-28 17:21:01 +0300 | [diff] [blame] | 442 | {%- macro MACRO_GENERATE_AND_ENABLE_ENVIRONMENT_MODEL() %} |
| 443 | {########################################################} |
Dennis Dmitriev | ccdc87a | 2017-09-28 17:43:54 +0300 | [diff] [blame] | 444 | |
Dennis Dmitriev | 92295c0 | 2018-02-02 13:18:25 +0200 | [diff] [blame] | 445 | - description: "[EXPERIMENTAL] Clone 'environment-template' repository to cfg01.{{ DOMAIN_NAME }}" |
Dennis Dmitriev | 9e18de7 | 2017-10-11 18:14:36 +0300 | [diff] [blame] | 446 | cmd: | |
| 447 | set -e; |
| 448 | mkdir -p /tmp/environment/; |
| 449 | 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] | 450 | node_name: {{ HOSTNAME_CFG01 }} |
| 451 | skip_fail: false |
| 452 | |
sgudz | cced67d | 2017-10-11 15:56:09 +0300 | [diff] [blame] | 453 | {%- if ENVIRONMENT_TEMPLATE_REF_CHANGE != '' %} |
| 454 | - description: Fetch changes for environment templates |
| 455 | cmd: | |
| 456 | set -e; |
| 457 | pushd /tmp/environment/environment_template && |
| 458 | git fetch https://github.com/Mirantis/environment-template {{ ENVIRONMENT_TEMPLATE_REF_CHANGE }} && |
| 459 | git checkout FETCH_HEAD && |
| 460 | popd |
| 461 | node_name: {{ HOSTNAME_CFG01 }} |
| 462 | skip_fail: false |
| 463 | {%- endif %} |
| 464 | |
Dennis Dmitriev | ccdc87a | 2017-09-28 17:43:54 +0300 | [diff] [blame] | 465 | {%- for ENVIRONMENT_CONTEXT_NAME in ENVIRONMENT_CONTEXT_NAMES %} |
Dennis Dmitriev | 92295c0 | 2018-02-02 13:18:25 +0200 | [diff] [blame] | 466 | - description: "[EXPERIMENTAL] Upload environment inventory to cfg01.{{ DOMAIN_NAME }}" |
Dennis Dmitriev | 9f141af | 2017-09-28 17:21:01 +0300 | [diff] [blame] | 467 | upload: |
| 468 | local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/ |
| 469 | local_filename: {{ ENVIRONMENT_CONTEXT_NAME }} |
| 470 | remote_path: /tmp/environment/ |
| 471 | node_name: {{ HOSTNAME_CFG01 }} |
Dennis Dmitriev | ccdc87a | 2017-09-28 17:43:54 +0300 | [diff] [blame] | 472 | {%- endfor %} |
Dennis Dmitriev | 9f141af | 2017-09-28 17:21:01 +0300 | [diff] [blame] | 473 | |
| 474 | - description: "[EXPERIMENTAL] Remove linux.network.interface object from the cluster/system models and use fixed 'environment' model instead" |
| 475 | cmd: | |
| 476 | set -e; |
| 477 | 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] | 478 | [[ -d /root/venv-reclass-tools ]] || virtualenv /root/venv-reclass-tools; |
| 479 | . /root/venv-reclass-tools/bin/activate; |
Dennis Dmitriev | 9f141af | 2017-09-28 17:21:01 +0300 | [diff] [blame] | 480 | pip install git+https://github.com/dis-xcom/reclass-tools; |
| 481 | reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/cluster/; |
| 482 | reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/system/; |
| 483 | reclass-tools del-key parameters.linux.network.interface /usr/share/salt-formulas/reclass/; |
| 484 | |
Dennis Dmitriev | 6368f08 | 2018-02-23 13:30:30 -0500 | [diff] [blame] | 485 | if ! reclass-tools get-key 'classes' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml | grep -q "environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}$"; then |
| 486 | reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}.reclass_datasource_local' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml --merge ; |
| 487 | 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] | 488 | fi; |
| 489 | |
| 490 | node_name: {{ HOSTNAME_CFG01 }} |
| 491 | retry: {count: 1, delay: 5} |
| 492 | skip_fail: false |
| 493 | |
Dennis Dmitriev | 222ba8e | 2017-11-11 00:06:02 +0200 | [diff] [blame] | 494 | - description: "Workaround for PROD-15923: all keepalive instances must be named 'VIP'" |
Dennis Dmitriev | 9f141af | 2017-09-28 17:21:01 +0300 | [diff] [blame] | 495 | cmd: | |
| 496 | set -e; |
Dennis Dmitriev | 222ba8e | 2017-11-11 00:06:02 +0200 | [diff] [blame] | 497 | 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] | 498 | |
| 499 | node_name: {{ HOSTNAME_CFG01 }} |
| 500 | retry: {count: 1, delay: 5} |
| 501 | skip_fail: false |
| 502 | |
| 503 | - description: "[EXPERIMENTAL] Create environment model for virtual environment" |
| 504 | cmd: | |
| 505 | set -e; |
Dennis Dmitriev | d96ace1 | 2018-01-26 14:46:21 +0200 | [diff] [blame] | 506 | . /root/venv-reclass-tools/bin/activate; |
Dennis Dmitriev | 9f141af | 2017-09-28 17:21:01 +0300 | [diff] [blame] | 507 | reclass-tools render --template-dir /tmp/environment/environment_template/ \ |
| 508 | --output-dir /srv/salt/reclass/classes/environment/ \ |
Dennis Dmitriev | d55a856 | 2017-09-28 22:12:09 +0300 | [diff] [blame] | 509 | {% 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] | 510 | --env-name {{ ENVIRONMENT_MODEL_INVENTORY_NAME }} |
| 511 | node_name: {{ HOSTNAME_CFG01 }} |
| 512 | retry: {count: 1, delay: 5} |
| 513 | skip_fail: false |
sgudz | 8c888ec | 2017-10-02 15:29:23 +0300 | [diff] [blame] | 514 | |
| 515 | - description: Modify generated model and reclass-system |
| 516 | cmd: | |
| 517 | export REPLACE_DIRS="/srv/salt/reclass/classes/ /srv/salt/reclass/nodes/" |
| 518 | find ${REPLACE_DIRS} -type f -exec sed -i 's/apt_mk_version:.*/apt_mk_version: {{ REPOSITORY_SUITE }}/g' {} + |
| 519 | node_name: {{ HOSTNAME_CFG01 }} |
| 520 | retry: {count: 1, delay: 1} |
| 521 | skip_fail: false |
| 522 | |
Dennis Dmitriev | 9f141af | 2017-09-28 17:21:01 +0300 | [diff] [blame] | 523 | {%- endmacro %} |
| 524 | |
| 525 | |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 526 | {%- macro MACRO_CONFIGURE_RECLASS(FORMULA_SERVICES='') %} |
| 527 | {#######################################################} |
| 528 | - description: Configure reclass |
| 529 | cmd: | |
Dennis Dmitriev | 3e731a4 | 2017-08-30 17:12:59 +0300 | [diff] [blame] | 530 | set -e; |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 531 | FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas}; |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 532 | which wget > /dev/null || (apt-get update; apt-get install -y wget); |
Dennis Dmitriev | cf77780 | 2018-02-14 18:09:55 +0200 | [diff] [blame] | 533 | . /etc/lsb-release; # Get DISTRIB_CODENAME variable |
Dennis Dmitriev | 3fbbc7f | 2017-12-21 15:42:14 +0200 | [diff] [blame] | 534 | echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list; |
| 535 | wget -O - "{{ FORMULA_GPG }}" | apt-key add -; |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 536 | apt-get clean; apt-get update; |
| 537 | [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service; |
| 538 | declare -a formula_services=({{ FORMULA_SERVICES }}); |
| 539 | echo -e "\nInstalling all required salt formulas\n"; |
Dennis Dmitriev | 01d5e37 | 2018-03-15 23:29:29 +0200 | [diff] [blame] | 540 | apt-get install -y "${formula_services[@]/#/salt-formula-}"; |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 541 | for formula_service in "${formula_services[@]}"; do |
| 542 | echo -e "\nLink service metadata for formula ${formula_service} ...\n"; |
| 543 | [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service}; |
| 544 | done; |
| 545 | [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env; |
| 546 | [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd; |
| 547 | [ ! -d /etc/reclass ] && mkdir /etc/reclass; |
| 548 | |
Dennis Dmitriev | a578c77 | 2018-01-24 21:02:15 +0200 | [diff] [blame] | 549 | cat << 'EOF' > /etc/reclass/reclass-config.yml |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 550 | storage_type: yaml_fs |
| 551 | pretty_print: True |
| 552 | output: yaml |
| 553 | inventory_base_uri: /srv/salt/reclass |
| 554 | EOF |
| 555 | node_name: {{ HOSTNAME_CFG01 }} |
| 556 | retry: {count: 1, delay: 1} |
| 557 | skip_fail: false |
| 558 | |
Dennis Dmitriev | 92295c0 | 2018-02-02 13:18:25 +0200 | [diff] [blame] | 559 | - 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] | 560 | cmd: | |
Dennis Dmitriev | 92295c0 | 2018-02-02 13:18:25 +0200 | [diff] [blame] | 561 | # Remove all other nodes except cfg01.{{ DOMAIN_NAME }} to not rely on them for 'reclass --top' |
| 562 | 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] | 563 | node_name: {{ HOSTNAME_CFG01 }} |
| 564 | retry: {count: 1, delay: 5} |
| 565 | skip_fail: false |
| 566 | |
| 567 | - description: Configure salt adoptors on cfg01 |
| 568 | cmd: | |
| 569 | ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/reclass-salt; |
| 570 | chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py |
| 571 | node_name: {{ HOSTNAME_CFG01 }} |
| 572 | retry: {count: 1, delay: 1} |
| 573 | skip_fail: false |
| 574 | |
| 575 | - description: Show reclass-salt --top for cfg01 node |
| 576 | cmd: reclass-salt --top |
| 577 | node_name: {{ HOSTNAME_CFG01 }} |
| 578 | retry: {count: 1, delay: 5} |
| 579 | skip_fail: false |
| 580 | |
| 581 | - description: Restart salt-master service |
ibumarskov | 712a687 | 2018-04-25 09:22:15 +0400 | [diff] [blame] | 582 | cmd: service salt-master restart; |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 583 | node_name: {{ HOSTNAME_CFG01 }} |
| 584 | retry: {count: 1, delay: 5} |
| 585 | skip_fail: false |
| 586 | {%- endmacro %} |
| 587 | |
| 588 | |
| 589 | {%- macro MACRO_INSTALL_SALT_MINIONS() %} |
| 590 | {#######################################} |
Dennis Dmitriev | 5bcbdc5 | 2018-03-23 18:05:10 +0200 | [diff] [blame] | 591 | {%- for ssh in config.underlay.ssh %} |
| 592 | {%- set salt_roles = [] %} |
| 593 | {%- for role in ssh['roles'] %} |
| 594 | {%- if role in config.salt_deploy.salt_roles %} |
| 595 | {%- set _ = salt_roles.append(role) %} |
| 596 | {%- endif %} |
| 597 | {%- endfor %} |
| 598 | |
| 599 | {%- if salt_roles %} |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 600 | - description: Configure salt-minion on {{ ssh['node_name'] }} |
| 601 | cmd: | |
| 602 | [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d; |
Dennis Dmitriev | a578c77 | 2018-01-24 21:02:15 +0200 | [diff] [blame] | 603 | cat << "EOF" > /etc/salt/minion.d/minion.conf |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 604 | id: {{ ssh['node_name'] }} |
| 605 | master: {{ config.salt.salt_master_host }} |
| 606 | EOF |
Dennis Dmitriev | cf77780 | 2018-02-14 18:09:55 +0200 | [diff] [blame] | 607 | |
| 608 | # Configure ubuntu and salt repositories |
| 609 | which wget >/dev/null || (apt-get update; apt-get install -y wget); |
| 610 | |
| 611 | . /etc/lsb-release; # Get DISTRIB_CODENAME variable |
| 612 | echo "{{ UBUNTU_REPOSITORY }}" > /etc/apt/sources.list |
| 613 | echo "{{ UBUNTU_UPDATES_REPOSITORY }}" >> /etc/apt/sources.list |
| 614 | echo "{{ UBUNTU_SECURITY_REPOSITORY }}" >> /etc/apt/sources.list |
| 615 | |
| 616 | echo "{{ SALT_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_saltstack.list; |
Tatyana Leontovich | 908ab93 | 2018-04-27 01:25:09 +0300 | [diff] [blame] | 617 | apt-key adv --keyserver "{{UBUNTU_KEY_SERVER}}" --recv-keys "{{ UBUNTU_KEY_ID}}" |
| 618 | |
Dennis Dmitriev | cf77780 | 2018-02-14 18:09:55 +0200 | [diff] [blame] | 619 | |
| 620 | apt-get clean |
| 621 | apt-get update |
| 622 | |
| 623 | # Install salt-minion |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 624 | eatmydata apt-get install -y salt-minion; |
Dennis Dmitriev | cf77780 | 2018-02-14 18:09:55 +0200 | [diff] [blame] | 625 | # Install common packages |
| 626 | eatmydata apt-get install -y python-pip git curl tmux byobu iputils-ping traceroute htop tree mc |
Dennis Dmitriev | 01d5e37 | 2018-03-15 23:29:29 +0200 | [diff] [blame] | 627 | sync |
Dennis Dmitriev | cf77780 | 2018-02-14 18:09:55 +0200 | [diff] [blame] | 628 | # Restart salt-minion if it was already installed |
| 629 | service salt-minion restart |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 630 | node_name: {{ ssh['node_name'] }} |
| 631 | retry: {count: 1, delay: 1} |
| 632 | skip_fail: false |
Dennis Dmitriev | 5bcbdc5 | 2018-03-23 18:05:10 +0200 | [diff] [blame] | 633 | {%- else %} |
| 634 | - description: Check SSH connectivity to non-salt-minion node {{ ssh['node_name'] }} |
| 635 | cmd: echo "SSH to $(hostname -f) passed" |
| 636 | node_name: {{ ssh['node_name'] }} |
| 637 | retry: {count: 1, delay: 1} |
| 638 | skip_fail: false |
| 639 | {%- endif %} |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 640 | |
Dennis Dmitriev | 5bcbdc5 | 2018-03-23 18:05:10 +0200 | [diff] [blame] | 641 | {%- endfor %} |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 642 | |
| 643 | - description: Accept salt keys from all the nodes |
| 644 | cmd: salt-key -A -y |
| 645 | node_name: {{ HOSTNAME_CFG01 }} |
| 646 | retry: {count: 1, delay: 5} |
| 647 | skip_fail: true |
| 648 | {%- endmacro %} |
| 649 | |
| 650 | |
Dmitry Tyzhnenko | 35413c0 | 2018-03-05 14:12:37 +0200 | [diff] [blame] | 651 | {%- macro MACRO_INSTALL_FORMULAS(FORMULA_SERVICES='') %} |
| 652 | {#######################################################} |
| 653 | - description: Configure reclass |
| 654 | cmd: | |
| 655 | set -e; |
| 656 | FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas}; |
| 657 | which wget > /dev/null || (apt-get update; apt-get install -y wget); |
| 658 | . /etc/lsb-release; # Get DISTRIB_CODENAME variable |
| 659 | # echo "{{ FORMULA_REPOSITORY }}" > /etc/apt/sources.list.d/mcp_salt.list; |
| 660 | # wget -O - "{{ FORMULA_GPG }}" | apt-key add -; |
| 661 | apt-get clean; apt-get update; |
| 662 | [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service; |
| 663 | declare -a formula_services=({{ FORMULA_SERVICES }}); |
| 664 | echo -e "\nInstalling all required salt formulas\n"; |
| 665 | eatmydata apt-get install -y "${formula_services[@]/#/salt-formula-}"; |
| 666 | for formula_service in "${formula_services[@]}"; do |
| 667 | echo -e "\nLink service metadata for formula ${formula_service} ...\n"; |
| 668 | [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service}; |
| 669 | done; |
| 670 | node_name: {{ HOSTNAME_CFG01 }} |
| 671 | retry: {count: 1, delay: 1} |
| 672 | skip_fail: false |
| 673 | |
| 674 | - description: Show reclass-salt --top for cfg01 node |
| 675 | cmd: reclass-salt --top |
| 676 | node_name: {{ HOSTNAME_CFG01 }} |
| 677 | retry: {count: 1, delay: 5} |
| 678 | skip_fail: false |
| 679 | |
| 680 | - description: Restart salt-master service |
| 681 | cmd: systemctl restart salt-master; |
| 682 | node_name: {{ HOSTNAME_CFG01 }} |
| 683 | retry: {count: 1, delay: 5} |
| 684 | skip_fail: false |
| 685 | {%- endmacro %} |
| 686 | |
| 687 | {%- macro MACRO_CONFIG_DAY01_SALT_MINION() %} |
| 688 | {#######################################} |
| 689 | - description: Configure salt-minion on {{ HOSTNAME_CFG01 }} |
| 690 | cmd: | |
| 691 | export SALT_MASTER_MINION_ID={{ HOSTNAME_CFG01 }} |
| 692 | envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf |
| 693 | service salt-minion restart |
| 694 | |
| 695 | while true; do |
| 696 | salt-key | grep "$SALT_MASTER_MINION_ID" && break |
| 697 | sleep 5 |
| 698 | done |
| 699 | |
| 700 | sleep 5 |
| 701 | |
| 702 | for i in `salt-key -l accepted | grep -v Accepted | grep -v "$SALT_MASTER_MINION_ID"`; do |
| 703 | salt-key -d $i -y |
| 704 | done |
| 705 | node_name: {{ HOSTNAME_CFG01 }} |
| 706 | retry: {count: 1, delay: 1} |
| 707 | skip_fail: false |
| 708 | {%- endmacro %} |
| 709 | |
| 710 | |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 711 | {%- macro MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() %} |
| 712 | {##################################################} |
| 713 | |
| 714 | {# Prepare salt services and nodes settings #} |
| 715 | |
| 716 | - description: Run 'linux' formula on cfg01 |
| 717 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls linux; |
| 718 | node_name: {{ HOSTNAME_CFG01 }} |
| 719 | retry: {count: 3, delay: 5} |
| 720 | skip_fail: false |
| 721 | |
| 722 | - description: Run 'openssh' formula on cfg01 |
| 723 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
Dennis Dmitriev | 3e731a4 | 2017-08-30 17:12:59 +0300 | [diff] [blame] | 724 | -C 'I@salt:master' state.sls openssh && |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 725 | salt --hard-crash --state-output=mixed --state-verbose=False |
| 726 | -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication |
Dennis Dmitriev | d260451 | 2018-06-04 05:34:44 +0300 | [diff] [blame] | 727 | yes/' /etc/ssh/sshd_config && service ssh reload" |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 728 | node_name: {{ HOSTNAME_CFG01 }} |
| 729 | retry: {count: 3, delay: 5} |
| 730 | skip_fail: false |
| 731 | |
Tatyana Leontovich | 907757f | 2018-04-17 12:29:33 +0300 | [diff] [blame] | 732 | - description: '*Workaround* of harcoded host from day01 grains' |
| 733 | cmd: salt-key -d cfg01.mcp-day01.local -y |
| 734 | node_name: {{ HOSTNAME_CFG01 }} |
| 735 | retry: {count: 1, delay: 1} |
Victor Ryzhenkin | 0104094 | 2018-04-17 15:45:58 +0400 | [diff] [blame] | 736 | skip_fail: true |
Tatyana Leontovich | 907757f | 2018-04-17 12:29:33 +0300 | [diff] [blame] | 737 | |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 738 | - description: '*Workaround* of the bug https://mirantis.jira.com/browse/PROD-7962' |
| 739 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 740 | '*' cmd.run "echo ' StrictHostKeyChecking no' >> /root/.ssh/config" |
| 741 | node_name: {{ HOSTNAME_CFG01 }} |
| 742 | retry: {count: 1, delay: 1} |
| 743 | skip_fail: false |
| 744 | |
| 745 | - description: Run 'salt.master' formula on cfg01 |
Dennis Dmitriev | e575e98 | 2017-10-21 21:50:45 +0300 | [diff] [blame] | 746 | 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] | 747 | node_name: {{ HOSTNAME_CFG01 }} |
Dennis Dmitriev | e575e98 | 2017-10-21 21:50:45 +0300 | [diff] [blame] | 748 | retry: {count: 2, delay: 30} |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 749 | skip_fail: false |
| 750 | |
Victor Ryzhenkin | 4e077ad | 2017-08-10 13:42:11 +0400 | [diff] [blame] | 751 | {%- if SALT_FORMULAS_REFS != '' %} |
| 752 | - description: Replace needed formulas to desired version |
| 753 | cmd: | |
| 754 | set -e; |
Victor Ryzhenkin | c791368 | 2017-10-11 15:14:40 +0400 | [diff] [blame] | 755 | {%- for formula_set in SALT_FORMULAS_REFS.split(' ') %} |
| 756 | {% set formula = formula_set.split(':') %} |
| 757 | {% set formula_name = formula[0] %} |
| 758 | {% set formula_ref = formula[1] %} |
Dennis Dmitriev | bc57b80 | 2017-08-16 18:10:57 +0300 | [diff] [blame] | 759 | {% set formula_dir = '/tmp/salt-formula-' + formula_name %} |
Victor Ryzhenkin | 4e077ad | 2017-08-10 13:42:11 +0400 | [diff] [blame] | 760 | git clone {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_dir }} && |
| 761 | pushd {{ formula_dir }} && |
| 762 | git fetch {{ SALT_FORMULAS_REPO }}/{{ formula_name }} {{ formula_ref }} && |
| 763 | git checkout FETCH_HEAD && |
| 764 | popd && |
| 765 | if [ -d "{{ formula_dir }}" ]; then |
| 766 | echo "Going to replace packaged formula {{ formula_name }}" && |
| 767 | rm -rfv /usr/share/salt-formulas/{env,reclass/service}/{{ formula_name }} && |
Victor Ryzhenkin | c791368 | 2017-10-11 15:14:40 +0400 | [diff] [blame] | 768 | ln -v -s "{{ formula_dir }}/{{ formula_name }}" "/usr/share/salt-formulas/env/{{ formula_name }}" && |
| 769 | 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] | 770 | else |
| 771 | echo "Stopped, directory /root/salt-formula-{{ formula_name }} does not exist!"; |
| 772 | fi |
| 773 | {%- endfor %} |
| 774 | node_name: {{ HOSTNAME_CFG01 }} |
| 775 | retry: {count: 1, delay: 10} |
| 776 | skip_fail: false |
| 777 | {%- endif %} |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 778 | |
| 779 | - description: Refresh pillars on salt-master minion |
| 780 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' saltutil.refresh_pillar |
| 781 | node_name: {{ HOSTNAME_CFG01 }} |
| 782 | retry: {count: 1, delay: 5} |
| 783 | skip_fail: false |
| 784 | |
Dennis Dmitriev | 3e731a4 | 2017-08-30 17:12:59 +0300 | [diff] [blame] | 785 | - description: Show reclass-salt --top for salt-master node |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 786 | cmd: reclass-salt --top |
| 787 | node_name: {{ HOSTNAME_CFG01 }} |
| 788 | retry: {count: 1, delay: 5} |
| 789 | skip_fail: false |
| 790 | |
| 791 | - description: Sync all salt resources on salt-master minion |
Dennis Dmitriev | 9a6cacc | 2017-08-14 00:08:41 +0300 | [diff] [blame] | 792 | 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] | 793 | node_name: {{ HOSTNAME_CFG01 }} |
| 794 | retry: {count: 1, delay: 5} |
| 795 | skip_fail: false |
| 796 | |
| 797 | - description: Configure linux on master |
| 798 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls 'linux.system' |
| 799 | node_name: {{ HOSTNAME_CFG01 }} |
| 800 | retry: {count: 1, delay: 5} |
| 801 | skip_fail: false |
| 802 | |
| 803 | - description: Configure salt.minion on master |
| 804 | cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False |
| 805 | -C 'I@salt:master' state.sls salt.minion && sleep 10 |
| 806 | node_name: {{ HOSTNAME_CFG01 }} |
| 807 | retry: {count: 3, delay: 10} |
| 808 | skip_fail: false |
| 809 | |
| 810 | - description: Run state 'salt' on master (for salt.api, etc) |
| 811 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 812 | -C 'I@salt:master' state.sls salt |
| 813 | node_name: {{ HOSTNAME_CFG01 }} |
| 814 | retry: {count: 3, delay: 10} |
| 815 | skip_fail: false |
| 816 | {%- endmacro %} |
| 817 | |
Dennis Dmitriev | 8555996 | 2018-01-30 15:35:51 +0200 | [diff] [blame] | 818 | {%- macro MACRO_GENERATE_INVENTORY(RERUN_SALTMASTER_STATE=false) %} |
| 819 | {#################################################################} |
| 820 | |
| 821 | - description: Refresh pillars before generating nodes |
| 822 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar |
| 823 | node_name: {{ HOSTNAME_CFG01 }} |
| 824 | retry: {count: 1, delay: 5} |
| 825 | skip_fail: false |
| 826 | |
Dennis Dmitriev | e1160fe | 2018-03-01 01:20:27 +0200 | [diff] [blame] | 827 | - description: Validate pillar on salt master node |
Dennis Dmitriev | 54a1300 | 2018-03-01 11:37:04 +0200 | [diff] [blame] | 828 | cmd: | |
| 829 | set -e |
| 830 | if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi |
| 831 | if salt-call sys.doc reclass.validate_pillar | grep -q reclass.validate_pillar ; then salt-call reclass.validate_pillar ; fi |
Dennis Dmitriev | e1160fe | 2018-03-01 01:20:27 +0200 | [diff] [blame] | 832 | node_name: {{ HOSTNAME_CFG01 }} |
| 833 | retry: {count: 1, delay: 5} |
| 834 | skip_fail: false |
| 835 | |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 836 | - description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated |
| 837 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 838 | -C 'I@salt:master' state.sls reclass |
| 839 | node_name: {{ HOSTNAME_CFG01 }} |
| 840 | retry: {count: 1, delay: 5} |
| 841 | skip_fail: false |
| 842 | |
Dennis Dmitriev | 8555996 | 2018-01-30 15:35:51 +0200 | [diff] [blame] | 843 | {%- if RERUN_SALTMASTER_STATE %} |
| 844 | - description: Regenerate salt.master states for the newly uploaded/created model |
| 845 | cmd: | |
| 846 | # Need to refresh installed formulas that are required in the model |
| 847 | salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar; sleep 5; |
| 848 | salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@salt:master' state.sls salt.master; |
| 849 | node_name: {{ HOSTNAME_CFG01 }} |
| 850 | retry: {count: 1, delay: 5} |
| 851 | skip_fail: false |
| 852 | {%- endif %} |
| 853 | |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 854 | - description: Refresh pillars on all minions |
Dennis Dmitriev | 8555996 | 2018-01-30 15:35:51 +0200 | [diff] [blame] | 855 | 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] | 856 | node_name: {{ HOSTNAME_CFG01 }} |
| 857 | retry: {count: 1, delay: 5} |
| 858 | skip_fail: false |
| 859 | |
Dennis Dmitriev | 3e731a4 | 2017-08-30 17:12:59 +0300 | [diff] [blame] | 860 | - description: Show reclass-salt --top for all generated nodes |
Dennis Dmitriev | 4386a07 | 2017-09-04 13:58:02 +0300 | [diff] [blame] | 861 | cmd: | |
| 862 | set -e |
| 863 | if salt-call sys.doc reclass.validate_node_params | grep -q reclass.validate_node_params ; then salt-call reclass.validate_nodes_params ; fi |
| 864 | if salt-call sys.doc reclass.validate_pillar | grep -q reclass.validate_pillar ; then salt-call reclass.validate_pillar ; fi |
| 865 | reclass-salt --top |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 866 | node_name: {{ HOSTNAME_CFG01 }} |
| 867 | retry: {count: 1, delay: 5} |
| 868 | skip_fail: false |
| 869 | |
| 870 | - description: Sync all salt resources |
Dennis Dmitriev | 9a6cacc | 2017-08-14 00:08:41 +0300 | [diff] [blame] | 871 | 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] | 872 | node_name: {{ HOSTNAME_CFG01 }} |
| 873 | retry: {count: 1, delay: 5} |
| 874 | skip_fail: false |
| 875 | {%- endmacro %} |
| 876 | |
| 877 | |
| 878 | {%- macro MACRO_BOOTSTRAP_ALL_MINIONS() %} |
| 879 | {########################################} |
| 880 | # Bootstrap all nodes |
Dennis Dmitriev | 8ed2788 | 2018-01-31 23:23:19 +0200 | [diff] [blame] | 881 | |
| 882 | - description: Get linux kernel version from all minions |
| 883 | cmd: | |
| 884 | salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'uname -r' | sort |
| 885 | salt --hard-crash --state-output=mixed --state-verbose=False --out=txt '*' cmd.run 'dpkg -l|grep "linux-image-.*-generic"' | sort |
| 886 | node_name: {{ HOSTNAME_CFG01 }} |
| 887 | retry: {count: 5, delay: 10} |
| 888 | skip_fail: false |
| 889 | |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 890 | - description: Configure linux on other nodes |
| 891 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux |
| 892 | node_name: {{ HOSTNAME_CFG01 }} |
| 893 | retry: {count: 5, delay: 10} |
| 894 | skip_fail: false |
| 895 | |
| 896 | - description: Configure openssh on all nodes |
Dennis Dmitriev | 3e731a4 | 2017-08-30 17:12:59 +0300 | [diff] [blame] | 897 | 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] | 898 | salt --hard-crash --state-output=mixed --state-verbose=False |
| 899 | -C 'I@linux:system and not cfg01*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication |
Dennis Dmitriev | d260451 | 2018-06-04 05:34:44 +0300 | [diff] [blame] | 900 | yes/' /etc/ssh/sshd_config && service ssh reload" |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 901 | node_name: {{ HOSTNAME_CFG01 }} |
| 902 | retry: {count: 1, delay: 5} |
| 903 | skip_fail: false |
| 904 | |
| 905 | - description: Configure salt.minion on other nodes |
| 906 | cmd: salt --timeout=120 --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system and not cfg01*' state.sls salt.minion && |
Victor Ryzhenkin | 93b49ff | 2018-03-06 15:59:51 +0400 | [diff] [blame] | 907 | sleep 30 |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 908 | node_name: {{ HOSTNAME_CFG01 }} |
| 909 | retry: {count: 3, delay: 15} |
| 910 | skip_fail: false |
| 911 | |
Victor Ryzhenkin | 93b49ff | 2018-03-06 15:59:51 +0400 | [diff] [blame] | 912 | - description: Wait for salt-minions wake up after restart |
Victor Ryzhenkin | 21bae99 | 2018-03-06 17:28:41 +0400 | [diff] [blame] | 913 | cmd: salt --timeout=30 --hard-crash --state-output=mixed --state-verbose=False '*' test.ping |
Victor Ryzhenkin | 93b49ff | 2018-03-06 15:59:51 +0400 | [diff] [blame] | 914 | node_name: {{ HOSTNAME_CFG01 }} |
Victor Ryzhenkin | 21bae99 | 2018-03-06 17:28:41 +0400 | [diff] [blame] | 915 | retry: {count: 25, delay: 30} |
Victor Ryzhenkin | 93b49ff | 2018-03-06 15:59:51 +0400 | [diff] [blame] | 916 | skip_fail: false |
| 917 | |
Victor Ryzhenkin | a06443e | 2018-03-15 17:25:19 +0400 | [diff] [blame] | 918 | - description: Update minion information |
Dennis Dmitriev | ea291ee | 2018-03-16 12:27:43 +0200 | [diff] [blame] | 919 | cmd: | |
| 920 | salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_grains && |
| 921 | salt --hard-crash --state-output=mixed --state-verbose=False '*' mine.update && sleep 15 |
Victor Ryzhenkin | a06443e | 2018-03-15 17:25:19 +0400 | [diff] [blame] | 922 | node_name: {{ HOSTNAME_CFG01 }} |
| 923 | retry: {count: 1, delay: 10} |
| 924 | skip_fail: false |
| 925 | |
Dennis Dmitriev | 14183db | 2018-03-01 15:14:12 +0200 | [diff] [blame] | 926 | - description: Execute linux.network.host one more time after salt.minion to apply dynamically registered hosts on the cluster nodes |
| 927 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux.network.host |
| 928 | node_name: {{ HOSTNAME_CFG01 }} |
| 929 | retry: {count: 1, delay: 10} |
| 930 | skip_fail: false |
| 931 | |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 932 | - description: Check salt minion versions on slaves |
Victor Ryzhenkin | 42e2423 | 2017-11-15 08:01:20 -0400 | [diff] [blame] | 933 | cmd: salt --timeout=60 '*' test.version |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 934 | node_name: {{ HOSTNAME_CFG01 }} |
| 935 | retry: {count: 3, delay: 15} |
| 936 | skip_fail: false |
| 937 | |
| 938 | - description: Check salt top states on nodes |
Victor Ryzhenkin | 42e2423 | 2017-11-15 08:01:20 -0400 | [diff] [blame] | 939 | cmd: salt --timeout=60 '*' state.show_top |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 940 | node_name: {{ HOSTNAME_CFG01 }} |
Victor Ryzhenkin | 42e2423 | 2017-11-15 08:01:20 -0400 | [diff] [blame] | 941 | retry: {count: 3, delay: 15} |
Dennis Dmitriev | 492813e | 2017-08-09 15:08:58 +0300 | [diff] [blame] | 942 | skip_fail: false |
| 943 | |
| 944 | - description: Configure ntp and rsyslog on nodes |
| 945 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls ntp,rsyslog |
| 946 | node_name: {{ HOSTNAME_CFG01 }} |
| 947 | retry: {count: 1, delay: 10} |
| 948 | skip_fail: false |
Sergii Golovatiuk | 50f9189 | 2017-08-04 18:11:06 +0200 | [diff] [blame] | 949 | {%- endmacro %} |
Dennis Dmitriev | 9dada8a | 2017-08-30 17:38:55 +0300 | [diff] [blame] | 950 | |
| 951 | |
| 952 | {%- macro MACRO_NETWORKING_WORKAROUNDS() %} |
| 953 | {#########################################} |
| 954 | |
Dennis Dmitriev | 9dada8a | 2017-08-30 17:38:55 +0300 | [diff] [blame] | 955 | - description: '*Workaround: Load bonding module before call state.linux' |
| 956 | cmd: salt -C "I@linux:network:interface:*:type:bond" cmd.run 'modprobe bonding' |
| 957 | node_name: {{ HOSTNAME_CFG01 }} |
| 958 | retry: {count: 1, delay: 5} |
Dennis Dmitriev | 0496eb7 | 2017-09-05 21:42:10 +0300 | [diff] [blame] | 959 | skip_fail: true |
Dennis Dmitriev | 9dada8a | 2017-08-30 17:38:55 +0300 | [diff] [blame] | 960 | |
| 961 | - description: '*Workaround* install bridge-utils before running linux formula' |
| 962 | # The formula removes default route and then tries to install the package, fails. |
| 963 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not |
| 964 | cfg01*' cmd.run 'sudo apt-get install -y bridge-utils' |
| 965 | node_name: {{ HOSTNAME_CFG01 }} |
| 966 | retry: {count: 1, delay: 5} |
| 967 | skip_fail: false |
| 968 | |
| 969 | {%- endmacro %} |
Victor Ryzhenkin | 9cc824c | 2017-10-12 19:02:23 +0400 | [diff] [blame] | 970 | |
Dennis Dmitriev | 257a938 | 2018-02-15 04:00:46 +0200 | [diff] [blame] | 971 | |
Victor Ryzhenkin | 9cc824c | 2017-10-12 19:02:23 +0400 | [diff] [blame] | 972 | {%- macro ADJUST_K8S_OPTS() %} |
Dennis Dmitriev | 257a938 | 2018-02-15 04:00:46 +0200 | [diff] [blame] | 973 | {############################} |
Victor Ryzhenkin | 9cc824c | 2017-10-12 19:02:23 +0400 | [diff] [blame] | 974 | |
| 975 | - description: Set k8s deploy parameters |
| 976 | cmd: | |
| 977 | {% for k8s_opt, value in config.k8s_deploy.items() %} |
| 978 | {% if value|string() %} |
| 979 | salt-call reclass.cluster_meta_set name={{ k8s_opt }} value={{ value }}; |
| 980 | {% endif %} |
| 981 | {% endfor %} |
| 982 | node_name: {{ HOSTNAME_CFG01 }} |
| 983 | retry: {count: 1, delay: 1} |
| 984 | skip_fail: false |
| 985 | |
| 986 | {%- endmacro %} |
Victor Ryzhenkin | 42e2423 | 2017-11-15 08:01:20 -0400 | [diff] [blame] | 987 | |
Dennis Dmitriev | 257a938 | 2018-02-15 04:00:46 +0200 | [diff] [blame] | 988 | |
| 989 | {%- macro ADJUST_SL_OPTS(OVERRIDES_FILENAME='') %} |
| 990 | {#############################################} |
| 991 | - description: Set SL docker images deploy parameters |
| 992 | cmd: | |
| 993 | {#- For cookiecutter-generated model, use overrides.yml from environment model instead of cluster model #} |
| 994 | {%- for sl_opt, value in config.sl_deploy.items() %} |
| 995 | {%- if value|string() %} |
| 996 | {%- if OVERRIDES_FILENAME %} |
| 997 | salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }} file_name={{ OVERRIDES_FILENAME }}; |
| 998 | {%- else %} |
| 999 | salt-call reclass.cluster_meta_set name={{ sl_opt }} value={{ value }}; |
| 1000 | {%- endif %} |
| 1001 | {%- endif %} |
| 1002 | {%- endfor %} |
| 1003 | salt '*' saltutil.refresh_pillar; |
| 1004 | sleep 10 |
| 1005 | node_name: {{ HOSTNAME_CFG01 }} |
| 1006 | retry: {count: 1, delay: 1} |
| 1007 | skip_fail: false |
| 1008 | {%- endmacro %} |
| 1009 | |
| 1010 | |
Victor Ryzhenkin | 42e2423 | 2017-11-15 08:01:20 -0400 | [diff] [blame] | 1011 | {%- macro REGISTER_COMPUTE_NODES() %} |
Dennis Dmitriev | 257a938 | 2018-02-15 04:00:46 +0200 | [diff] [blame] | 1012 | {###################################} |
Victor Ryzhenkin | 42e2423 | 2017-11-15 08:01:20 -0400 | [diff] [blame] | 1013 | |
| 1014 | {% for ssh in config.underlay.ssh %} |
| 1015 | {% if ssh["node_name"].startswith("cmp") %} |
| 1016 | {% set node_hostname = ssh["node_name"].split('.')[0] %} |
| 1017 | - description: Register compute {{ ssh['node_name'] }} |
| 1018 | cmd: | |
| 1019 | exec > >(tee -i /tmp/cloud-init-bootstrap.log) 2>&1 |
| 1020 | export network01_prefix={{ IPV4_NET_ADMIN_PREFIX }} |
| 1021 | export network02_prefix={{ IPV4_NET_CONTROL_PREFIX }} |
Victor Ryzhenkin | 66593e9 | 2017-11-28 19:38:33 +0400 | [diff] [blame] | 1022 | export cluster_name={{ CLUSTER_NAME }} |
Victor Ryzhenkin | 42e2423 | 2017-11-15 08:01:20 -0400 | [diff] [blame] | 1023 | export config_host={{ config.salt.salt_master_host }} |
| 1024 | export node_domain={{ DOMAIN_NAME }} |
| 1025 | export nodes_os="xenial" |
| 1026 | export node_hostname={{ node_hostname }} |
| 1027 | set -xe |
| 1028 | export BOOTSTRAP_SCRIPT_URL=$bootstrap_script_url |
| 1029 | export BOOTSTRAP_SCRIPT_URL=${BOOTSTRAP_SCRIPT_URL:-https://raw.githubusercontent.com/salt-formulas/salt-formulas-scripts/master/bootstrap.sh} |
| 1030 | export DISTRIB_REVISION={{ REPOSITORY_SUITE }} |
| 1031 | export DISTRIB_REVISION=${DISTRIB_REVISION:-nightly} |
| 1032 | |
| 1033 | # Add wrapper to apt-get to avoid race conditions |
| 1034 | # with cron jobs running 'unattended-upgrades' script |
| 1035 | aptget_wrapper() { |
| 1036 | local apt_wrapper_timeout=300 |
| 1037 | local start_time=$(date '+%s') |
| 1038 | local fin_time=$((start_time + apt_wrapper_timeout)) |
| 1039 | while true; do |
| 1040 | if (( "$(date '+%s')" > fin_time )); then |
| 1041 | msg="Timeout exceeded ${apt_wrapper_timeout} s. Lock files are still not released. Terminating..." |
| 1042 | fi |
| 1043 | if fuser /var/lib/apt/lists/lock >/dev/null 2>&1 || fuser /var/lib/dpkg/lock >/dev/null 2>&1; then |
| 1044 | echo "Waiting while another apt/dpkg process releases locks ..." |
| 1045 | sleep 30 |
| 1046 | continue |
| 1047 | else |
| 1048 | apt-get $@ |
| 1049 | break |
| 1050 | fi |
| 1051 | done |
| 1052 | } |
| 1053 | |
| 1054 | # Set default salt version |
| 1055 | if [ -z "$saltversion" ]; then |
| 1056 | saltversion="2016.3" |
| 1057 | fi |
| 1058 | echo "Using Salt version $saltversion" |
| 1059 | |
| 1060 | echo "Preparing base OS ..." |
| 1061 | |
| 1062 | case "$node_os" in |
| 1063 | trusty) |
| 1064 | # workaround for old cloud-init only configuring the first iface |
| 1065 | iface_config_dir="/etc/network/interfaces" |
| 1066 | ifaces=$(ip a | awk '/^[1-9]:/ {print $2}' | grep -v "lo:" | rev | cut -c2- | rev) |
| 1067 | |
| 1068 | for iface in $ifaces; do |
| 1069 | grep $iface $iface_config_dir &> /dev/null || (echo -e "\nauto $iface\niface $iface inet dhcp" >> $iface_config_dir && ifup $iface) |
| 1070 | done |
| 1071 | |
| 1072 | which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget) |
| 1073 | |
| 1074 | # SUGGESTED UPDATE: |
| 1075 | #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion |
| 1076 | #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL}) |
| 1077 | ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service |
| 1078 | #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION " |
| 1079 | #install_salt_minion_pkg |
| 1080 | |
| 1081 | # DEPRECATED: |
| 1082 | echo "deb [arch=amd64] http://apt-mk.mirantis.com/trusty ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list |
| 1083 | wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add - |
| 1084 | |
| 1085 | echo "deb http://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion trusty main" > /etc/apt/sources.list.d/saltstack.list |
| 1086 | wget -O - "https://repo.saltstack.com/apt/ubuntu/14.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add - |
| 1087 | |
| 1088 | aptget_wrapper clean |
| 1089 | aptget_wrapper update |
| 1090 | aptget_wrapper install -y salt-common |
| 1091 | aptget_wrapper install -y salt-minion |
| 1092 | ;; |
| 1093 | xenial) |
| 1094 | |
| 1095 | # workaround for new cloud-init setting all interfaces statically |
| 1096 | which resolvconf > /dev/null 2>&1 && systemctl restart resolvconf |
| 1097 | |
| 1098 | which wget > /dev/null || (aptget_wrapper update; aptget_wrapper install -y wget) |
| 1099 | |
| 1100 | # SUGGESTED UPDATE: |
| 1101 | #export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion |
| 1102 | #source <(curl -qL ${BOOTSTRAP_SCRIPT_URL}) |
| 1103 | ## Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service |
| 1104 | #BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION " |
| 1105 | #install_salt_minion_pkg |
| 1106 | |
| 1107 | # DEPRECATED: |
| 1108 | echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial ${DISTRIB_REVISION} salt extra" > /etc/apt/sources.list.d/mcp_salt.list |
| 1109 | wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add - |
| 1110 | |
| 1111 | echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion xenial main" > /etc/apt/sources.list.d/saltstack.list |
| 1112 | wget -O - "https://repo.saltstack.com/apt/ubuntu/16.04/amd64/$saltversion/SALTSTACK-GPG-KEY.pub" | apt-key add - |
| 1113 | |
| 1114 | aptget_wrapper clean |
| 1115 | aptget_wrapper update |
| 1116 | aptget_wrapper install -y salt-minion |
| 1117 | ;; |
| 1118 | rhel|centos|centos7|centos7|rhel6|rhel7) |
| 1119 | yum install -y git |
| 1120 | export MASTER_IP="$config_host" MINION_ID="$node_hostname.$node_domain" SALT_VERSION=$saltversion |
| 1121 | source <(curl -qL ${BOOTSTRAP_SCRIPT_URL}) |
| 1122 | # Update BOOTSTRAP_SALTSTACK_OPTS, as by default they contain "-dX" not to start service |
| 1123 | BOOTSTRAP_SALTSTACK_OPTS=" stable $SALT_VERSION " |
| 1124 | install_salt_minion_pkg |
| 1125 | ;; |
| 1126 | *) |
| 1127 | msg="OS '$node_os' is not supported." |
| 1128 | esac |
| 1129 | |
| 1130 | echo "Configuring Salt minion ..." |
| 1131 | [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d |
| 1132 | echo -e "id: $node_hostname.$node_domain\nmaster: $config_host" > /etc/salt/minion.d/minion.conf |
| 1133 | |
| 1134 | service salt-minion restart || wait_condition_send "FAILURE" "Failed to restart salt-minion service." |
| 1135 | |
| 1136 | sleep 1 |
| 1137 | |
| 1138 | echo "Classifying node ..." |
| 1139 | os_codename=$(salt-call grains.item oscodename --out key | awk '/oscodename/ {print $2}') |
| 1140 | node_network01_ip="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')" |
| 1141 | node_network02_ip="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')" |
| 1142 | node_network03_ip="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')" |
| 1143 | node_network04_ip="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')" |
| 1144 | node_network05_ip="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($2, a, "/"); print a[1]}')" |
| 1145 | |
| 1146 | node_network01_iface="$(ip a | awk -v prefix="^ inet $network01_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')" |
| 1147 | node_network02_iface="$(ip a | awk -v prefix="^ inet $network02_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')" |
| 1148 | node_network03_iface="$(ip a | awk -v prefix="^ inet $network03_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')" |
| 1149 | node_network04_iface="$(ip a | awk -v prefix="^ inet $network04_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')" |
| 1150 | node_network05_iface="$(ip a | awk -v prefix="^ inet $network05_prefix[.]" '$0 ~ prefix {split($7, a, "/"); print a[1]}')" |
| 1151 | |
| 1152 | if [ "$node_network05_iface" != "" ]; then |
| 1153 | node_network05_hwaddress="$(cat /sys/class/net/$node_network05_iface/address)" |
| 1154 | fi |
| 1155 | |
| 1156 | # find more parameters (every env starting param_) |
| 1157 | more_params=$(env | grep "^param_" | sed -e 's/=/":"/g' -e 's/^/"/g' -e 's/$/",/g' | tr "\n" " " | sed 's/, $//g') |
| 1158 | if [ "$more_params" != "" ]; then |
| 1159 | echo "Additional params: $more_params" |
| 1160 | more_params=", $more_params" |
| 1161 | fi |
| 1162 | |
| 1163 | 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}}" |
| 1164 | |
| 1165 | sleep 5 |
| 1166 | |
| 1167 | salt-call saltutil.sync_all |
| 1168 | salt-call mine.flush |
| 1169 | salt-call mine.update |
| 1170 | node_name: {{ ssh['node_name'] }} |
| 1171 | retry: {count: 1, delay: 1} |
| 1172 | skip_fail: false |
| 1173 | {%- endif %} |
| 1174 | {%- endfor %} |
| 1175 | |
| 1176 | - description: Refresh pillars on all minions |
| 1177 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar |
| 1178 | node_name: {{ HOSTNAME_CFG01 }} |
| 1179 | retry: {count: 1, delay: 5} |
| 1180 | skip_fail: false |
| 1181 | |
| 1182 | - description: Sync all salt resources |
| 1183 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5 |
| 1184 | node_name: {{ HOSTNAME_CFG01 }} |
| 1185 | retry: {count: 1, delay: 5} |
| 1186 | skip_fail: false |
| 1187 | |
sgudz | 160b730 | 2017-12-22 17:01:10 +0200 | [diff] [blame] | 1188 | {%- endmacro %} |
sgudz | 09e9aa9 | 2018-04-12 12:31:53 +0300 | [diff] [blame] | 1189 | |
| 1190 | {%- macro RUN_NEW_TEMPEST() %} |
| 1191 | {###################################} |
| 1192 | |
| 1193 | - description: Upload tempest template |
| 1194 | upload: |
| 1195 | local_path: {{ config.salt_deploy.templates_dir }} |
| 1196 | local_filename: runtest.yml |
| 1197 | remote_path: /srv/salt/reclass/classes/cluster/{{ CLUSTER_NAME }}/infra/ |
| 1198 | node_name: {{ HOSTNAME_CFG01 }} |
| 1199 | skip_fail: False |
| 1200 | |
| 1201 | - description: Include class with tempest template into cfg node |
| 1202 | cmd: | |
| 1203 | sed -i 's/classes\:/classes\:\n- cluster.{{ CLUSTER_NAME }}.infra.runtest/g' /srv/salt/reclass/nodes/_generated/cfg01.{{ DOMAIN_NAME }}.yml; |
| 1204 | salt 'cfg01*' saltutil.refresh_pillar; |
| 1205 | salt 'cfg01*' saltutil.sync_all; |
| 1206 | node_name: {{ HOSTNAME_CFG01 }} |
| 1207 | retry: {count: 1, delay: 10} |
| 1208 | skip_fail: false |
| 1209 | |
| 1210 | - description: Create flavors for tests |
| 1211 | cmd: | |
| 1212 | salt 'cfg01*' state.sls nova.client; |
| 1213 | node_name: {{ HOSTNAME_CFG01 }} |
| 1214 | retry: {count: 1, delay: 5} |
| 1215 | skip_fail: false |
| 1216 | |
| 1217 | - description: Create networks for tests |
| 1218 | cmd: | |
| 1219 | salt 'cfg01*' state.sls neutron.client; |
| 1220 | node_name: {{ HOSTNAME_CFG01 }} |
| 1221 | retry: {count: 1, delay: 5} |
| 1222 | skip_fail: false |
| 1223 | |
| 1224 | - description: Upload cirros image |
| 1225 | cmd: | |
| 1226 | salt 'cfg01*' state.sls glance.client; |
| 1227 | node_name: {{ HOSTNAME_CFG01 }} |
| 1228 | retry: {count: 1, delay: 5} |
| 1229 | skip_fail: false |
| 1230 | |
| 1231 | - description: Generate tempest config |
| 1232 | cmd: | |
| 1233 | salt 'cfg01*' state.sls runtest; |
| 1234 | node_name: {{ HOSTNAME_CFG01 }} |
| 1235 | retry: {count: 1, delay: 5} |
| 1236 | skip_fail: false |
| 1237 | |
| 1238 | - description: Run tempest from new docker image |
| 1239 | cmd: | |
Oleksii Butenko | 71d76f3 | 2018-06-05 17:46:34 +0300 | [diff] [blame] | 1240 | docker run -e ARGS="-r {{TEMPEST_PATTERN }} -w 2 {{ EXCLUDE_TEST_ARGS }}" -v /root/test/tempest.conf:/etc/tempest/tempest.conf -v /tmp/:/tmp/ -v /root/test:/root/tempest -v /etc/ssl/certs/:/etc/ssl/certs/ --rm docker-prod-virtual.docker.mirantis.net/mirantis/cicd/ci-tempest:pike /bin/bash -c "run-tempest" |
sgudz | 09e9aa9 | 2018-04-12 12:31:53 +0300 | [diff] [blame] | 1241 | node_name: {{ HOSTNAME_GTW01 }} |
| 1242 | retry: {count: 1, delay: 30} |
| 1243 | skip_fail: true |
| 1244 | |
| 1245 | - description: Download xml results |
| 1246 | download: |
| 1247 | remote_path: /root/test/ |
| 1248 | remote_filename: "report_*.xml" |
| 1249 | local_path: {{ os_env('PWD') }} |
| 1250 | node_name: {{ HOSTNAME_GTW01 }} |
| 1251 | skip_fail: true |
| 1252 | |
| 1253 | {%- endmacro %} |