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