blob: 4e5e3db15ac881c8c9af4f368e1053195e4fb02b [file] [log] [blame]
Tatyana Leontovich055b5062017-04-03 13:17:25 +03001{% from 'virtual_mcp10_ovs.jinja' import HOSTNAME_CFG01 with context %}
2
3# Install salt to the config node
4
5
Tatyana Leontovich5fd6ed62017-04-04 15:08:29 +03006- description: Configure repository on the cfg01 node
7 cmd:
8 echo "172.18.248.114 jenkins.mcp.mirantis.net gerrit.mcp.mirantis.net" >> /etc/hosts;
9 echo "185.135.196.10 apt-mk.mirantis.com" >> /etc/hosts;
10 echo "nameserver 172.18.208.44 >> /etc/resolv.conf;
11 echo "nameserver 8.8.8.8 >> /etc/resolv.conf;
12 which wget >/dev/null || (apt-get update; apt-get install -y wget);
13 echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial nightly salt extra" > /etc/apt/sources.list.d/mcp_salt.list;
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030014 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -;
Tatyana Leontovich055b5062017-04-03 13:17:25 +030015 echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3 xenial main" > /etc/apt/sources.list.d/saltstack.list;
16 wget -O - https://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3/SALTSTACK-GPG-KEY.pub | apt-key add -;
Tatyana Leontovich055b5062017-04-03 13:17:25 +030017 node_name: {{ HOSTNAME_CFG01 }}
18 retry: {count: 1, delay: 1}
19 skip_fail: false
20
Tatyana Leontovich055b5062017-04-03 13:17:25 +030021- description: Update packages on cfg01
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030022 cmd: apt-get clean; apt-get update
Tatyana Leontovich055b5062017-04-03 13:17:25 +030023 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030024 retry: {count: 1, delay: 1}
Tatyana Leontovich055b5062017-04-03 13:17:25 +030025 skip_fail: false
26
Tatyana Leontovich5fd6ed62017-04-04 15:08:29 +030027- description: Installing salt master on cfg01
28 cmd: apt-get install -y reclass git; apt-get install -y salt-master
Tatyana Leontovich055b5062017-04-03 13:17:25 +030029 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030030 retry: {count: 1, delay: 1}
31 skip_fail: false
32
33- description: Install common packages on cfg01
34 cmd: apt-get install -y python-pip wget curl tmux byobu iputils-ping traceroute htop tree
35 node_name: {{ HOSTNAME_CFG01 }}
36 retry: {count: 1, delay: 1}
Tatyana Leontovich055b5062017-04-03 13:17:25 +030037 skip_fail: false
38
Tatyana Leontovich055b5062017-04-03 13:17:25 +030039- description: Configure salt-master on cfg01
40 cmd: |
41 cat << 'EOF' >> /etc/salt/master.d/master.conf
42 file_roots:
43 base:
44 - /usr/share/salt-formulas/env
45 pillar_opts: False
46 open_mode: True
47 reclass: &reclass
48 storage_type: yaml_fs
49 inventory_base_uri: /srv/salt/reclass
50 ext_pillar:
51 - reclass: *reclass
52 master_tops:
53 reclass: *reclass
54 EOF
55 node_name: {{ HOSTNAME_CFG01 }}
56 retry: {count: 1, delay: 1}
57 skip_fail: false
58
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030059- description: Clone reclass models with submodules
Tatyana Leontovich055b5062017-04-03 13:17:25 +030060 cmd: |
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030061 ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Tatyana Leontovich5fd6ed62017-04-04 15:08:29 +030062 git clone -b master --recurse-submodules https://gerrit.mcp.mirantis.net/salt-models/mcp-virtual-lab /srv/salt/reclass;
63 mkdir -p /srv/salt/reclass/classes/service;
Tatyana Leontovich055b5062017-04-03 13:17:25 +030064 node_name: {{ HOSTNAME_CFG01 }}
65 retry: {count: 1, delay: 1}
66 skip_fail: false
67
68- description: Configure reclass
69 cmd: |
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030070 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
71 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt.tcpcloud.eu/nightly xenial tcp-salt};
72 FORMULA_GPG=${FORMULA_GPG:-http://apt.tcpcloud.eu/public.gpg};
73 which wget > /dev/null || (apt-get update; apt-get install -y wget);
74 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/tcpcloud_salt.list;
75 wget -O - "${FORMULA_GPG}" | apt-key add -;
76 apt-get clean; apt-get update;
77 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
78 declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon");
79 echo -e "\nInstalling all required salt formulas\n";
80 apt-get install -y "${formula_services[@]/#/salt-formula-}";
Tatyana Leontovichf6ba0c02017-04-04 14:44:01 +030081 for formula_service in in "${formula_services[@]}"; do
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030082 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
83 [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && ln -s ${FORMULA_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service};
Tatyana Leontovich055b5062017-04-03 13:17:25 +030084 done;
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030085 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
86 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
Tatyana Leontovich055b5062017-04-03 13:17:25 +030087 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
Tatyana Leontovich193554a2017-04-04 17:19:13 +030088
Tatyana Leontovich055b5062017-04-03 13:17:25 +030089 cat << 'EOF' >> /etc/reclass/reclass-config.yml
90 storage_type: yaml_fs
91 pretty_print: True
92 output: yaml
93 inventory_base_uri: /srv/salt/reclass
94 EOF
95 node_name: {{ HOSTNAME_CFG01 }}
96 retry: {count: 1, delay: 1}
97 skip_fail: false
98
99- description: Configure salt-minion on cfg01
100 cmd: |
101 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
102 cat << "EOF" >> /etc/salt/minion.d/minion.conf
103 id: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich5fd6ed62017-04-04 15:08:29 +0300104 master: 127.0.0.1
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300105 EOF
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300106 apt-get install -y salt-minion;
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300107 node_name: {{ HOSTNAME_CFG01 }}
108 retry: {count: 1, delay: 1}
109 skip_fail: false
110
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300111- description: Restart services
112 cmd: |
113 systemctl restart salt-master;
114 systemctl restart salt-minion;
115 echo "Showing system info and metadata ...";
116 salt-call --no-color grains.items;
117 salt-call --no-color pillar.data;
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300118 node_name: {{ HOSTNAME_CFG01 }}
119 retry: {count: 3, delay: 5}
120 skip_fail: false
121
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300122# Prepare salt services and nodes settings
123- description: Run 'linux' and openssh formula on cfg01
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300124 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300125 -C 'I@salt:master' state.sls linux,openssh;
126 node_name: {{ HOSTNAME_CFG01 }}
127 retry: {count: 3, delay: 5}
128 skip_fail: false
129
130- description: Run 'reclass' formula on cfg01
131 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
132 -C 'I@salt:master' state.sls reclass;
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300133 salt --hard-crash --state-output=mixed --state-verbose=False
134 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
135 yes/' /etc/ssh/sshd_config && service ssh restart";
136 node_name: {{ HOSTNAME_CFG01 }}
137 retry: {count: 3, delay: 5}
138 skip_fail: false
139
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300140- description: Run 'salt' formula on cfg01
141 cmd: timeout 120 salt --hard-crash --state-output=mixed --state-verbose=False
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300142 -C 'I@salt:master' state.sls salt.master.service;
143 salt-call --no-color state.sls salt.master,salt.api,salt.minion.ca -l info;
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300144 node_name: {{ HOSTNAME_CFG01 }}
145 retry: {count: 3, delay: 5}
146 skip_fail: true
147
148- description: Accept salt keys from all the nodes
149 cmd: salt-key -A -y
150 node_name: {{ HOSTNAME_CFG01 }}
151 retry: {count: 1, delay: 5}
152 skip_fail: false
153
154- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
155 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
156 -C 'I@salt:master' state.sls reclass
157 node_name: {{ HOSTNAME_CFG01 }}
158 retry: {count: 3, delay: 5}
159 skip_fail: false
160
161- description: Refresh pillars on all minions
162 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
163 node_name: {{ HOSTNAME_CFG01 }}
164 retry: {count: 3, delay: 5}
165 skip_fail: false
166
167- description: Sync all salt resources
168 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
169 node_name: {{ HOSTNAME_CFG01 }}
170 retry: {count: 3, delay: 5}
171 skip_fail: false
172
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300173- description: Show reclass-salt --top
174 cmd: salt-call --no-color state.sls salt.minion.cert -l info
175 node_name: {{ HOSTNAME_CFG01 }}
176 retry: {count: 3, delay: 5}
177 skip_fail: false
178
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300179
180# Bootstrap all nodes
181
182- description: Workaround for missing kernel modules
183 cmd: salt '*' cmd.run "for module in nf_conntrack_ipv4 ip_tables
184 x_tables nf_defrag_ipv4 nf_nat_ipv4 nf_nat
185 iptable_filter iptable_mangle iptable_nat;
186 do
187 modprobe \$module;
188 echo \$module >> /etc/modules;
189 done"
190 node_name: {{ HOSTNAME_CFG01 }}
191 retry: {count: 1, delay: 1}
192 skip_fail: false
193
194
195- description: Configure linux on all nodes
196 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls
197 linux
198 node_name: {{ HOSTNAME_CFG01 }}
199 retry: {count: 5, delay: 5}
200 skip_fail: false
201
202- description: Configure openssh on all nodes
203 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
204 cfg*' state.sls openssh;salt --hard-crash --state-output=mixed --state-verbose=False
205 -C '* and not cfg*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
206 yes/' /etc/ssh/sshd_config && service ssh restart"
207 node_name: {{ HOSTNAME_CFG01 }}
208 retry: {count: 3, delay: 5}
209 skip_fail: false
210
211- description: '*Workaround* for the bug https://mirantis.jira.com/browse/PROD-8021'
212 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' cmd.run 'apt-get
213 -y install linux-image-extra-$(uname -r)'
214 node_name: {{ HOSTNAME_CFG01 }}
215 retry: {count: 3, delay: 5}
216 skip_fail: false
217
218- description: Configure salt.minion on controllers
219 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls salt.minion
220 node_name: {{ HOSTNAME_CFG01 }}
221 retry: {count: 3, delay: 5}
222 skip_fail: false
223
224- description: Check salt minion versions on slaves
225 cmd: salt '*' test.version
226 node_name: {{ HOSTNAME_CFG01 }}
227 retry: {count: 3, delay: 5}
228 skip_fail: false
229
230- description: Check salt minion versions on slaves
231 cmd: salt '*' state.show_top
232 node_name: {{ HOSTNAME_CFG01 }}
233 retry: {count: 3, delay: 5}
234 skip_fail: false
235
236- description: Configure ntp on controllers
237 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls ntp
238 node_name: {{ HOSTNAME_CFG01 }}
239 retry: {count: 5, delay: 10}
240 skip_fail: false
241