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