blob: 3705053388a0bda824d25193dfad6517529dadd3 [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
Dennis Dmitriev0f272312018-10-01 13:29:40 +03008{% set SALT_MODELS_REPOSITORY = os_env('SALT_MODELS_REPOSITORY','https://gerrit.mcp.mirantis.com/salt-models/mcp-virtual-lab') %}
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +03009# 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
24{{ SHARED.MACRO_GENERATE_COOKIECUTTER_MODEL(CONTROL_VLAN=CONTROL_VLAN, TENANT_VLAN=TENANT_VLAN) }}
25
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
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +030053- description: Temporary WR for correct bridge name according to envoronment templates
54 cmd: |
55 sed -i 's/br\-ctl/br\_ctl/g' /srv/salt/reclass/classes/cluster/{{ LAB_CONFIG_NAME }}/infra/kvm.yml;
56 sed -i 's/br\-mgm/br\_mgm/g' /srv/salt/reclass/classes/cluster/{{ LAB_CONFIG_NAME }}/infra/kvm.yml;
57 node_name: {{ HOSTNAME_CFG01 }}
58 retry: {count: 1, delay: 10}
59 skip_fail: false
60
Dmitry Tyzhnenko7c7b7d82018-07-20 15:35:07 +030061- description: Rerun openssh after env model is generated
62 cmd: |
63 salt-call state.sls openssh
64 node_name: {{ HOSTNAME_CFG01 }}
65 retry: {count: 1, delay: 10}
66 skip_fail: false
67
68{{ SHARED.MACRO_GENERATE_INVENTORY() }}
69
70{{ SHARED.MACRO_NETWORKING_WORKAROUNDS() }}
71
72- description: "Disable kubelet_fail_on_swap"
73 cmd: |
74 set -e;
75 . /root/venv-reclass-tools/bin/activate;
76 reclass-tools add-key parameters._param.kubelet_fail_on_swap false /srv/salt/reclass/classes/system/kubernetes/common.yml;
77 node_name: {{ HOSTNAME_CFG01 }}
78 retry: {count: 1, delay: 10}
79 skip_fail: false
80
81- description: Update minion information
82 cmd: |
83 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_grains &&
84 salt --hard-crash --state-output=mixed --state-verbose=False '*' mine.update &&
85 salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar && sleep 10
86 node_name: {{ HOSTNAME_CFG01 }}
87 retry: {count: 1, delay: 10}
88 skip_fail: false
89
90- description: Rerun openssh after env model is generated
91 cmd: |
92 salt-call state.sls openssh
93 node_name: {{ HOSTNAME_CFG01 }}
94 retry: {count: 1, delay: 10}
95 skip_fail: false
96
97- description: Execute linux.network.host one more time after salt.minion to apply dynamically registered hosts on the cluster nodes
98 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C 'I@linux:system' state.sls linux.network.host
99 node_name: {{ HOSTNAME_CFG01 }}
100 retry: {count: 2, delay: 10}
101 skip_fail: false
102
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +0300103{{ SHARED.MACRO_BOOTSTRAP_ALL_MINIONS() }}
104
105########################################
106# Spin up Control Plane VMs on KVM nodes
107########################################
108
109- description: Execute 'libvirt' states to create necessary libvirt networks
110 cmd: salt --hard-crash --state-output=mixed --state-verbose=False 'kvm*' state.sls libvirt
111 node_name: {{ HOSTNAME_CFG01 }}
112 retry: {count: 2, delay: 10}
113 skip_fail: false
114
115- description: Create VMs for control plane
116 cmd: salt --hard-crash --state-output=mixed --state-verbose=False 'kvm*' state.sls salt.control
117 node_name: {{ HOSTNAME_CFG01 }}
118 retry: {count: 3, delay: 10}
119 skip_fail: false
120
121- description: '*Workaround* for waiting the control-plane VMs in the salt-key (instead of sleep)'
122 cmd: |
123 salt-key -l acc| sort > /tmp/current_keys.txt &&
124 salt 'kvm*' cmd.run 'virsh list --name' | grep -v 'kvm'|sort|xargs -I {} fgrep {} /tmp/current_keys.txt
125 node_name: {{ HOSTNAME_CFG01 }}
126 retry: {count: 20, delay: 30}
127 skip_fail: false
128
Dmitry Tyzhnenko7c7b7d82018-07-20 15:35:07 +0300129{{ SHARED.MACRO_BOOTSTRAP_ALL_MINIONS() }}
130
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +0300131#########################################
132# Configure all running salt minion nodes
133#########################################
134
135- description: Hack resolv.conf on VCP nodes for internal services access
136 cmd: |
Dmitry Tyzhnenko7c7b7d82018-07-20 15:35:07 +0300137 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 +0300138 node_name: {{ HOSTNAME_CFG01 }}
139 retry: {count: 1, delay: 5}
140 skip_fail: false
141
142- description: Refresh pillars on all minions
143 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
144 node_name: {{ HOSTNAME_CFG01 }}
145 retry: {count: 1, delay: 5}
146 skip_fail: false
147
148- description: Sync all salt resources
149 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all && sleep 5
150 node_name: {{ HOSTNAME_CFG01 }}
151 retry: {count: 1, delay: 5}
152 skip_fail: false
153
154- description: Show reclass-salt --top for generated nodes
155 cmd: reclass-salt --top -u /srv/salt/reclass/nodes/_generated/
156 node_name: {{ HOSTNAME_CFG01 }}
157 retry: {count: 1, delay: 5}
158 skip_fail: false
159
Dmitry Tyzhnenko7c7b7d82018-07-20 15:35:07 +0300160{{SHARED.MACRO_CHECK_SALT_VERSION_SERVICES_ON_CFG()}}
161
162{{SHARED.MACRO_CHECK_SALT_VERSION_ON_NODES()}}
163
164- description: "Lab04 workaround: Give each node root acces with key from cfg01"
165 cmd: |
166 set -e;
167 set -x;
168 key=$(ssh-keygen -y -f /root/.ssh/id_rsa);
169 salt '*' cmd.run "echo $key >> /root/.ssh/authorized_keys";
170 salt '*' cmd.run "service sshd restart"
171 node_name: {{ HOSTNAME_CFG01 }}
172 retry: {count: 1, delay: 5}
173 skip_fail: true
174
175- description: "Lab04 workaround: Control network access from cfg01 node using sshuttle via kvm01"
176 cmd: |
177 set -e;
178 set -x;
179 KVM01_DEPLOY_ADDRESS=$(salt-call --out=newline_values_only pillar.get _param:infra_kvm_node01_deploy_address);
180 apt-get install -y sshuttle;
181 sshuttle -r ${KVM01_DEPLOY_ADDRESS} 10.167.8.0/24 -D >/dev/null;
182 node_name: {{ HOSTNAME_CFG01 }}
183 retry: {count: 1, delay: 5}
184 skip_fail: true