blob: 8b1b7ef20798c6f46bdd7bc2806037257acc2b1d [file] [log] [blame]
Dennis Dmitriev411dd102017-09-15 16:04:47 +03001{% from 'cookied-mcp-ocata-dop-sl2/underlay.yaml' import HOSTNAME_CFG01 with context %}
2{% from 'cookied-mcp-ocata-dop-sl2/underlay.yaml' import LAB_CONFIG_NAME with context %}
3{% from 'cookied-mcp-ocata-dop-sl2/underlay.yaml' import DOMAIN_NAME with context %}
4
5{% set SALT_MODELS_REPOSITORY = os_env('SALT_MODELS_REPOSITORY','https://gerrit.mcp.mirantis.net/salt-models/mcp-virtual-lab') %}
6# Other salt model repository parameters see in shared-salt.yaml
7
8# Name of the context file (without extension, that is fixed .yaml) used to render the Environment model
9{% set ENVIRONMENT_MODEL_INVENTORY_NAME = os_env('ENVIRONMENT_MODEL_INVENTORY_NAME','virtual-mcp-ocata-dop-sl2') %}
10# Path to the context files used to render Cluster and Environment models
11{%- set CLUSTER_CONTEXT_PATH = '/tmp/environment/salt-context-cicd_oss.yaml' %}
12{%- set ENVIRONMENT_CONTEXT_PATH = '/tmp/environment/salt-context-environment.yaml' %}
13
14{% import 'shared-salt.yaml' as SHARED with context %}
15
16{{ SHARED.MACRO_INSTALL_SALT_MASTER() }}
17
18- description: "[EXPERIMENTAL] Upload 'environment' to {{ HOSTNAME_CFG01 }}"
19 upload:
20 local_path: {{ config.salt_deploy.environment_template_dir }}
21 remote_path: /tmp/environment/
22 node_name: {{ HOSTNAME_CFG01 }}
23 skip_fail: false
24
25- description: "[EXPERIMENTAL] Upload cookiecutter-templates context to {{ HOSTNAME_CFG01 }}"
26 upload:
27 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
28 local_filename: salt-context-cicd_oss.yaml
29 remote_path: /tmp/environment/
30 node_name: {{ HOSTNAME_CFG01 }}
31
32- description: "[EXPERIMENTAL] Upload environment inventory to {{ HOSTNAME_CFG01 }}"
33 upload:
34 local_path: {{ config.salt_deploy.templates_dir }}{{ LAB_CONFIG_NAME }}/
35 local_filename: salt-context-environment.yaml
36 remote_path: /tmp/environment/
37 node_name: {{ HOSTNAME_CFG01 }}
38
39{#{ SHARED.MACRO_CLONE_RECLASS_MODELS() }#}
40- description: Create cluster model from cookiecutter templates
41 cmd: |
42 set -e;
43 pip install cookiecutter
44 export GIT_SSL_NO_VERIFY=true; git clone https://gerrit.mcp.mirantis.net/mk/cookiecutter-templates /tmp/cookiecutter-templates
45 mkdir -p /srv/salt/reclass/classes/cluster/
46 mkdir -p /srv/salt/reclass/classes/system/
47 mkdir -p /srv/salt/reclass/classes/service/
48 mkdir -p /srv/salt/reclass/nodes/_generated
49
50 # Override some context parameters
51 sed -i 's/cluster_name:.*/cluster_name: {{ LAB_CONFIG_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
52 sed -i 's/cluster_domain:.*/cluster_domain: {{ DOMAIN_NAME }}/g' {{ CLUSTER_CONTEXT_PATH }}
53 sed -i 's/control_vlan:.*/control_vlan: \"2416\"/g' {{ CLUSTER_CONTEXT_PATH }}
54 sed -i 's/tenant_vlan:.*/tenant_vlan: \"2417\"/g' {{ CLUSTER_CONTEXT_PATH }}
55
56 # Temporary workaround (with hardcoded address .90 -> .15) of bug https://mirantis.jira.com/browse/PROD-14377
57 sed -i 's/salt_master_address:.*/salt_master_address: {{ SHARED.IPV4_NET_CONTROL_PREFIX }}.15/g' {{ CLUSTER_CONTEXT_PATH }}
58 sed -i 's/salt_master_management_address:.*/salt_master_management_address: {{ SHARED.IPV4_NET_ADMIN_PREFIX }}.15/g' {{ CLUSTER_CONTEXT_PATH }}
59
60 # Replace firstly to an intermediate value to avoid intersection between
61 # already replaced and replacing networks.
62 # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice:
63 # 192.168.10 -> 10.16.0 (generated network for admin)
64 # 10.16.0 -> <external network>
65 # So let's replace constant networks to the keywords, and then keywords to the desired networks.
66 sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
67 sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
68 sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
69 sed -i 's/172\.17\.16\./==IPV4_NET_EXTERNAL_PREFIX==/g' {{ CLUSTER_CONTEXT_PATH }}
70
71 sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ SHARED.IPV4_NET_ADMIN_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
72 sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ SHARED.IPV4_NET_CONTROL_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
73 sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ SHARED.IPV4_NET_TENANT_PREFIX }}/g' {{ CLUSTER_CONTEXT_PATH }}
74 sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ SHARED.IPV4_NET_EXTERNAL_PREFIX }}./g' {{ CLUSTER_CONTEXT_PATH }}
75
76 for i in $(ls /tmp/cookiecutter-templates/cluster_product/); do
77 python /tmp/cookiecutter-templates/generate.py \
78 --template /tmp/cookiecutter-templates/cluster_product/$i \
79 --config-file {{ CLUSTER_CONTEXT_PATH }} \
80 --output-dir /srv/salt/reclass/classes/cluster/;
81 done
82
83 export GIT_SSL_NO_VERIFY=true; git clone https://gerrit.mcp.mirantis.net/salt-models/reclass-system /srv/salt/reclass/classes/system/
84
85 # Create the cfg01 node and disable checkouting the model from remote repository
86 cat << 'EOF' >> /srv/salt/reclass/nodes/_generated/{{ HOSTNAME_CFG01 }}.yml
87 classes:
88 - system.openssh.server.team.all
89 - cluster.{{ LAB_CONFIG_NAME }}.infra.config
90 - environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}.reclass_datasource_local
91 - environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}
92
93 node_name: {{ HOSTNAME_CFG01 }}
94 retry: {count: 1, delay: 1}
95 skip_fail: false
96
97- description: "[EXPERIMENTAL] Remove linux.network.interface object from the cluster/system models and use fixed 'environment' model instead"
98 cmd: |
99 set -e;
100 apt-get -y install python-virtualenv python-pip build-essential python-dev libssl-dev;
101 pip install git+https://github.com/dis-xcom/reclass-tools;
102 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/cluster/;
103 reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/system/;
104 reclass-tools del-key parameters.linux.network.interface /usr/share/salt-formulas/reclass/;
105
106 #if ! reclass-tools get-key 'classes' /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml | grep -q "environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}$"; then
107 # reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}' /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml --merge ;
108 #fi;
109
110 node_name: {{ HOSTNAME_CFG01 }}
111 retry: {count: 1, delay: 5}
112 skip_fail: false
113
114- description: "Workaround for PROD-14756: all roles must use service.keepalived.cluster.single with the default 'VIP' instance"
115 cmd: |
116 set -e;
117 find /srv/salt/reclass/classes/cluster/ -type f -exec sed -i 's/system.keepalived.*/service.keepalived.cluster.single/g' {} +
118 find /srv/salt/reclass/classes/system/ -type f -exec sed -i 's/system.keepalived.*/service.keepalived.cluster.single/g' {} +
119
120 node_name: {{ HOSTNAME_CFG01 }}
121 retry: {count: 1, delay: 5}
122 skip_fail: false
123
124- description: "[EXPERIMENTAL] Create environment model for virtual environment"
125 cmd: |
126 set -e;
127 ln -s '/tmp/environment/environment_template/{{ '{# interfaces #}' }}' '/tmp/environment/environment_template/{{ '{{ cookiecutter._env_name }}' }}/';
128 ln -s '/tmp/environment/environment_template/{{ '{# roles #}' }}' '/tmp/environment/environment_template/{{ '{{ cookiecutter._env_name }}' }}/';
129 reclass-tools render --template-dir /tmp/environment/environment_template/ \
130 --output-dir /srv/salt/reclass/classes/environment/ \
131 --context {{ ENVIRONMENT_CONTEXT_PATH }} \
132 --env-name {{ ENVIRONMENT_MODEL_INVENTORY_NAME }}
133 node_name: {{ HOSTNAME_CFG01 }}
134 retry: {count: 1, delay: 5}
135 skip_fail: false
136
137{{ SHARED.MACRO_CONFIGURE_RECLASS(FORMULA_SERVICES='"linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon" "prometheus" "telegraf" "elasticsearch" "powerdns" "glusterfs" "xtrabackup"') }}
138
139{{ SHARED.MACRO_INSTALL_SALT_MINIONS() }}
140
141{{ SHARED.MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() }}
142
143{{ SHARED.MACRO_GENERATE_INVENTORY() }}
144
145{{ SHARED.MACRO_NETWORKING_WORKAROUNDS() }}
146
147{{ SHARED.MACRO_BOOTSTRAP_ALL_MINIONS() }}
148
149#- description: Hack gtw node
150# cmd: salt 'gtw*' cmd.run "ip addr del {{ SHARED.IPV4_NET_CONTROL_PREFIX }}.110/24 dev ens4; ip addr flush dev ens4";
151# node_name: {{ HOSTNAME_CFG01 }}
152# retry: {count: 1, delay: 10}
153# skip_fail: false
154
155#- description: Hack cmp01 node
156# cmd: salt 'cmp01*' cmd.run "ip addr del {{ SHARED.IPV4_NET_CONTROL_PREFIX }}.105/24 dev ens4; ip addr flush dev ens4";
157# node_name: {{ HOSTNAME_CFG01 }}
158# retry: {count: 1, delay: 10}
159# skip_fail: false
160
161#- description: Hack cmp02 node
162# cmd: salt 'cmp02*' cmd.run "ip addr del {{ SHARED.IPV4_NET_CONTROL_PREFIX }}.106/24 dev ens4; ip addr flush dev ens4";
163# node_name: {{ HOSTNAME_CFG01 }}
164# retry: {count: 1, delay: 10}
165# skip_fail: false