blob: 0d6bd52e83f8019ec3c7059c8084dfdc86fe0e7e [file] [log] [blame]
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +03001{% from 'cookied-bm-mcp-pike-k8s-contrail/underlay.yaml' import HOSTNAME_CFG01 with context %}
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +03002{% from 'cookied-bm-mcp-pike-k8s-contrail/underlay.yaml' import LAB_CONFIG_NAME with context %}
3{% from 'cookied-bm-mcp-pike-k8s-contrail/underlay.yaml' import DOMAIN_NAME with context %}
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +03004{% from 'cookied-bm-mcp-pike-k8s-contrail/underlay.yaml' import HOSTNAME_KVM01 with context %}
5{% from 'cookied-bm-mcp-pike-k8s-contrail/underlay.yaml' import HOSTNAME_KVM02 with context %}
6{% from 'cookied-bm-mcp-pike-k8s-contrail/underlay.yaml' import HOSTNAME_KVM03 with context %}
7
8{% set SALT_MODELS_REPOSITORY = os_env('SALT_MODELS_REPOSITORY','https://gerrit.mcp.mirantis.net/salt-models/mcp-virtual-lab') %}
9# Other salt model repository parameters see in shared-salt.yaml
10
11# Name of the context file (without extension, that is fixed .yaml) used to render the Environment model
12{% set ENVIRONMENT_MODEL_INVENTORY_NAME = os_env('ENVIRONMENT_MODEL_INVENTORY_NAME','bm-mcp-pike-k8s-contrail') %}
13# Path to the context files used to render Cluster and Environment models
14{%- set CLUSTER_CONTEXT_NAME = 'salt-context-cookiecutter-k8s-contrail.yaml' %}
15{%- set ENVIRONMENT_CONTEXT_NAMES = ['salt-context-environment.yaml','lab04-upgrade-physical-inventory.yaml'] %}
16{%- set CONTROL_VLAN = os_env('CONTROL_VLAN', '2410') %}
17{%- set TENANT_VLAN = os_env('TENANT_VLAN', '2411') %}
18
19
20{% import 'shared-salt.yaml' as SHARED with context %}
21
22{{ SHARED.MACRO_INSTALL_SALT_MASTER() }}
23
sgudzfc5b22f2018-08-23 17:45:04 +030024{{ SHARED.MACRO_GENERATE_COOKIECUTTER_MODEL(CONTROL_VLAN=CONTROL_VLAN, TENANT_VLAN=TENANT_VLAN, CLUSTER_PRODUCT_MODELS='cicd infra kubernetes opencontrail stacklight2') }}
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +030025
26{{ SHARED.MACRO_GENERATE_AND_ENABLE_ENVIRONMENT_MODEL() }}
27
Oleksii Butenkoa2fa0612018-09-20 12:01:44 +030028{{ SHARED.MACRO_CONFIGURE_RECLASS(FORMULA_SERVICES='\*') }}
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +030029{{ SHARED.MACRO_INSTALL_SALT_MINIONS() }}
30
31{{ SHARED.MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() }}
32
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +030033- description: "Workaround for rack01 compute generator"
34 cmd: |
35 set -e;
36 # Remove rack01 key
37 . /root/venv-reclass-tools/bin/activate;
38 reclass-tools del-key parameters.reclass.storage.node.kubernetes_compute_rack01 /srv/salt/reclass/classes/cluster/{{ LAB_CONFIG_NAME }}/infra/config.yml;
39 node_name: {{ HOSTNAME_CFG01 }}
40 retry: {count: 1, delay: 10}
41 skip_fail: false
42
Dmitry Tyzhnenko7c7b7d82018-07-20 15:35:07 +030043- description: "Change path to internal storage for salt.control images"
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +030044 cmd: |
45 set -e;
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +030046 . /root/venv-reclass-tools/bin/activate;
Dmitry Tyzhnenko7c7b7d82018-07-20 15:35:07 +030047 reclass-tools add-key parameters._param.salt_control_xenial_image 'https://apt.mcp.mirantis.net/images/ubuntu-16-04-x64-mcp{{ SHARED.REPOSITORY_SUITE }}.qcow2' /srv/salt/reclass/classes/cluster/{{ LAB_CONFIG_NAME }}/infra/init.yml;
48 reclass-tools add-key parameters._param.salt_control_trusty_image 'https://apt.mcp.mirantis.net/images/ubuntu-14-04-x64-mcp{{ SHARED.REPOSITORY_SUITE }}.qcow2' /srv/salt/reclass/classes/cluster/{{ LAB_CONFIG_NAME }}/infra/init.yml;
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +030049 node_name: {{ HOSTNAME_CFG01 }}
50 retry: {count: 1, delay: 10}
51 skip_fail: false
52
sgudzfc5b22f2018-08-23 17:45:04 +030053- description: Delete proxy inclusion from kvm
54 cmd: |
55 sed -i 's/- system.salt.control.cluster.kubernetes_proxy_cluster//g' /srv/salt/reclass/classes/cluster/{{ LAB_CONFIG_NAME }}/infra/kvm.yml;
56 node_name: {{ HOSTNAME_CFG01 }}
57 retry: {count: 1, delay: 10}
58 skip_fail: false
59
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +030060- description: Temporary WR for correct bridge name according to envoronment templates
61 cmd: |
62 sed -i 's/br\-ctl/br\_ctl/g' /srv/salt/reclass/classes/cluster/{{ LAB_CONFIG_NAME }}/infra/kvm.yml;
63 sed -i 's/br\-mgm/br\_mgm/g' /srv/salt/reclass/classes/cluster/{{ LAB_CONFIG_NAME }}/infra/kvm.yml;
64 node_name: {{ HOSTNAME_CFG01 }}
65 retry: {count: 1, delay: 10}
66 skip_fail: false
67
sgudzfc5b22f2018-08-23 17:45:04 +030068- description: "Excluding tenant network from cluster"
69 cmd: |
70 set -e;
71 . /root/venv-reclass-tools/bin/activate;
72 reclass-tools add-key parameters._param.opencontrail_compute_address '${_param:single_address}' /srv/salt/reclass/classes/cluster/{{ LAB_CONFIG_NAME }}/opencontrail/compute.yml;
73 node_name: {{ HOSTNAME_CFG01 }}
74 retry: {count: 1, delay: 10}
75 skip_fail: false
76
77- description: "Use correct compute interface"
78 cmd: |
79 set -e;
80 . /root/venv-reclass-tools/bin/activate;
81 reclass-tools add-key parameters._param.opencontrail_compute_iface 'ens11f1.${_param:control_vlan}' /srv/salt/reclass/classes/cluster/{{ LAB_CONFIG_NAME }}/opencontrail/init.yml;
82 node_name: {{ HOSTNAME_CFG01 }}
83 retry: {count: 1, delay: 10}
84 skip_fail: false
85
Dmitry Tyzhnenko7c7b7d82018-07-20 15:35:07 +030086- description: Rerun openssh after env model is generated
87 cmd: |
88 salt-call state.sls openssh
89 node_name: {{ HOSTNAME_CFG01 }}
90 retry: {count: 1, delay: 10}
91 skip_fail: false
92
93{{ SHARED.MACRO_GENERATE_INVENTORY() }}
94
95{{ SHARED.MACRO_NETWORKING_WORKAROUNDS() }}
96
97- description: "Disable kubelet_fail_on_swap"
98 cmd: |
99 set -e;
100 . /root/venv-reclass-tools/bin/activate;
101 reclass-tools add-key parameters._param.kubelet_fail_on_swap false /srv/salt/reclass/classes/system/kubernetes/common.yml;
102 node_name: {{ HOSTNAME_CFG01 }}
103 retry: {count: 1, delay: 10}
104 skip_fail: false
105
106- description: Update minion information
107 cmd: |
sgudzfc5b22f2018-08-23 17:45:04 +0300108 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all &&
Dmitry Tyzhnenko7c7b7d82018-07-20 15:35:07 +0300109 salt --hard-crash --state-output=mixed --state-verbose=False '*' mine.update &&
110 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar && sleep 10
111 node_name: {{ HOSTNAME_CFG01 }}
112 retry: {count: 1, delay: 10}
113 skip_fail: false
114
115- description: Rerun openssh after env model is generated
116 cmd: |
117 salt-call state.sls openssh
118 node_name: {{ HOSTNAME_CFG01 }}
119 retry: {count: 1, delay: 10}
120 skip_fail: false
121
122- description: Execute linux.network.host one more time after salt.minion to apply dynamically registered hosts on the cluster nodes
123 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux.network.host
124 node_name: {{ HOSTNAME_CFG01 }}
125 retry: {count: 2, delay: 10}
126 skip_fail: false
127
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +0300128{{ SHARED.MACRO_BOOTSTRAP_ALL_MINIONS() }}
129
130########################################
131# Spin up Control Plane VMs on KVM nodes
132########################################
133
134- description: Execute 'libvirt' states to create necessary libvirt networks
135 cmd: salt --hard-crash --state-output=mixed --state-verbose=False 'kvm*' state.sls libvirt
136 node_name: {{ HOSTNAME_CFG01 }}
137 retry: {count: 2, delay: 10}
138 skip_fail: false
139
140- description: Create VMs for control plane
141 cmd: salt --hard-crash --state-output=mixed --state-verbose=False 'kvm*' state.sls salt.control
142 node_name: {{ HOSTNAME_CFG01 }}
143 retry: {count: 3, delay: 10}
144 skip_fail: false
145
146- description: '*Workaround* for waiting the control-plane VMs in the salt-key (instead of sleep)'
147 cmd: |
148 salt-key -l acc| sort > /tmp/current_keys.txt &&
149 salt 'kvm*' cmd.run 'virsh list --name' | grep -v 'kvm'|sort|xargs -I {} fgrep {} /tmp/current_keys.txt
150 node_name: {{ HOSTNAME_CFG01 }}
151 retry: {count: 20, delay: 30}
152 skip_fail: false
153
Dmitry Tyzhnenko7c7b7d82018-07-20 15:35:07 +0300154{{ SHARED.MACRO_BOOTSTRAP_ALL_MINIONS() }}
155
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +0300156#########################################
157# Configure all running salt minion nodes
158#########################################
159
160- description: Hack resolv.conf on VCP nodes for internal services access
161 cmd: |
Dmitry Tyzhnenko7c7b7d82018-07-20 15:35:07 +0300162 salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not cfg*' cmd.run "echo 'nameserver 172.17.41.2' > /etc/resolv.conf;"
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +0300163 node_name: {{ HOSTNAME_CFG01 }}
164 retry: {count: 1, delay: 5}
165 skip_fail: false
166
167- description: Refresh pillars on all minions
168 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
169 node_name: {{ HOSTNAME_CFG01 }}
170 retry: {count: 1, delay: 5}
171 skip_fail: false
172
173- description: Sync all salt resources
174 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
175 node_name: {{ HOSTNAME_CFG01 }}
176 retry: {count: 1, delay: 5}
177 skip_fail: false
178
179- description: Show reclass-salt --top for generated nodes
180 cmd: reclass-salt --top -u /srv/salt/reclass/nodes/_generated/
181 node_name: {{ HOSTNAME_CFG01 }}
182 retry: {count: 1, delay: 5}
183 skip_fail: false
184
Dmitry Tyzhnenko7c7b7d82018-07-20 15:35:07 +0300185{{SHARED.MACRO_CHECK_SALT_VERSION_SERVICES_ON_CFG()}}
186
187{{SHARED.MACRO_CHECK_SALT_VERSION_ON_NODES()}}
188
189- description: "Lab04 workaround: Give each node root acces with key from cfg01"
190 cmd: |
191 set -e;
192 set -x;
193 key=$(ssh-keygen -y -f /root/.ssh/id_rsa);
194 salt '*' cmd.run "echo $key >> /root/.ssh/authorized_keys";
195 salt '*' cmd.run "service sshd restart"
196 node_name: {{ HOSTNAME_CFG01 }}
197 retry: {count: 1, delay: 5}
198 skip_fail: true
199
200- description: "Lab04 workaround: Control network access from cfg01 node using sshuttle via kvm01"
201 cmd: |
202 set -e;
203 set -x;
204 KVM01_DEPLOY_ADDRESS=$(salt-call --out=newline_values_only pillar.get _param:infra_kvm_node01_deploy_address);
205 apt-get install -y sshuttle;
206 sshuttle -r ${KVM01_DEPLOY_ADDRESS} 10.167.8.0/24 -D >/dev/null;
207 node_name: {{ HOSTNAME_CFG01 }}
208 retry: {count: 1, delay: 5}
209 skip_fail: true