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