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