blob: 868c9eea2f4baf22a4c7e4f5c99fabc57814ba2e [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
6- description: Configure tcpcloud repository on the cfg01 node
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +03007 cmd: echo "deb [arch=amd64] http://apt-mk.mirantis.com/xenial nightly salt extra" > /etc/apt/sources.list.d/mcp_salt.list;
8 wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -;
Tatyana Leontovich055b5062017-04-03 13:17:25 +03009 echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3 xenial main" > /etc/apt/sources.list.d/saltstack.list;
10 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 +030011 node_name: {{ HOSTNAME_CFG01 }}
12 retry: {count: 1, delay: 1}
13 skip_fail: false
14
Tatyana Leontovich055b5062017-04-03 13:17:25 +030015- description: Update packages on cfg01
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030016 cmd: apt-get clean; apt-get update
Tatyana Leontovich055b5062017-04-03 13:17:25 +030017 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030018 retry: {count: 1, delay: 1}
Tatyana Leontovich055b5062017-04-03 13:17:25 +030019 skip_fail: false
20
21- description: Install common packages on cfg01
22 cmd: apt-get install -y python-pip wget curl tmux byobu iputils-ping traceroute htop tree
23 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030024 retry: {count: 1, delay: 1}
25 skip_fail: false
26
27- description: Install common packages on cfg01
28 cmd: apt-get install -y python-pip wget curl tmux byobu iputils-ping traceroute htop tree
29 node_name: {{ HOSTNAME_CFG01 }}
30 retry: {count: 1, delay: 1}
Tatyana Leontovich055b5062017-04-03 13:17:25 +030031 skip_fail: false
32
33- description: Install salt formulas, master and minion on cfg01
34 # cmd: apt-get install -y salt-formula-* salt-master salt-minion reclass
35 cmd: apt-get install -y
36 salt-master
37 salt-minion
38 reclass
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030039 git
Tatyana Leontovich055b5062017-04-03 13:17:25 +030040 salt-formula-linux
41 salt-formula-reclass
42 salt-formula-salt
43 salt-formula-openssh
44 salt-formula-ntp
45 salt-formula-git
46 salt-formula-nginx
47 salt-formula-collectd
48 salt-formula-sensu
49 salt-formula-heka
50 salt-formula-sphinx
51 salt-formula-keystone
52 salt-formula-mysql
53 salt-formula-grafana
54 salt-formula-haproxy
55 node_name: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030056 retry: {count: 1, delay: 1}
Tatyana Leontovich055b5062017-04-03 13:17:25 +030057 skip_fail: false
58
59- description: Configure salt-master on cfg01
60 cmd: |
61 cat << 'EOF' >> /etc/salt/master.d/master.conf
62 file_roots:
63 base:
64 - /usr/share/salt-formulas/env
65 pillar_opts: False
66 open_mode: True
67 reclass: &reclass
68 storage_type: yaml_fs
69 inventory_base_uri: /srv/salt/reclass
70 ext_pillar:
71 - reclass: *reclass
72 master_tops:
73 reclass: *reclass
74 EOF
75 node_name: {{ HOSTNAME_CFG01 }}
76 retry: {count: 1, delay: 1}
77 skip_fail: false
78
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030079- description: Clone reclass models with submodules
Tatyana Leontovich055b5062017-04-03 13:17:25 +030080 cmd: |
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030081 ssh-keyscan -H github.com >> ~/.ssh/known_hosts;
Tatyana Leontovich794e4152017-04-04 12:38:15 +030082 git clone --recurse-submodules https://gerrit.mcp.mirantis.net/salt-models/mcp-virtual-lab /srv/salt/reclass;
Tatyana Leontovich055b5062017-04-03 13:17:25 +030083 cd /srv/salt/reclass;
84 git checkout master;
Tatyana Leontovich055b5062017-04-03 13:17:25 +030085 node_name: {{ HOSTNAME_CFG01 }}
86 retry: {count: 1, delay: 1}
87 skip_fail: false
88
89- description: Configure reclass
90 cmd: |
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +030091 FORMULA_PATH=${FORMULA_PATH:-/usr/share/salt-formulas};
92 FORMULA_REPOSITORY=${FORMULA_REPOSITORY:-deb [arch=amd64] http://apt.tcpcloud.eu/nightly xenial tcp-salt};
93 FORMULA_GPG=${FORMULA_GPG:-http://apt.tcpcloud.eu/public.gpg};
94 which wget > /dev/null || (apt-get update; apt-get install -y wget);
95 echo "${FORMULA_REPOSITORY}" > /etc/apt/sources.list.d/tcpcloud_salt.list;
96 wget -O - "${FORMULA_GPG}" | apt-key add -;
97 apt-get clean; apt-get update;
98 [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service;
99 declare -a formula_services=("linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon");
100 echo -e "\nInstalling all required salt formulas\n";
101 apt-get install -y "${formula_services[@]/#/salt-formula-}";
Tatyana Leontovichf6ba0c02017-04-04 14:44:01 +0300102 for formula_service in in "${formula_services[@]}"; do
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300103 [ ! -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 +0300104 done;
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300105 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
106 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300107 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
108 cat << 'EOF' >> /etc/reclass/reclass-config.yml
109 storage_type: yaml_fs
110 pretty_print: True
111 output: yaml
112 inventory_base_uri: /srv/salt/reclass
113 EOF
114 node_name: {{ HOSTNAME_CFG01 }}
115 retry: {count: 1, delay: 1}
116 skip_fail: false
117
118- description: Configure salt-minion on cfg01
119 cmd: |
120 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
121 cat << "EOF" >> /etc/salt/minion.d/minion.conf
122 id: {{ HOSTNAME_CFG01 }}
123 master: localhost
124 EOF
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300125 apt-get install -y salt-minion;
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300126 node_name: {{ HOSTNAME_CFG01 }}
127 retry: {count: 1, delay: 1}
128 skip_fail: false
129
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300130- description: Restart services
131 cmd: |
132 systemctl restart salt-master;
133 systemctl restart salt-minion;
134 echo "Showing system info and metadata ...";
135 salt-call --no-color grains.items;
136 salt-call --no-color pillar.data;
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300137 node_name: {{ HOSTNAME_CFG01 }}
138 retry: {count: 3, delay: 5}
139 skip_fail: false
140
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300141# Prepare salt services and nodes settings
142- description: Run 'linux' and openssh formula on cfg01
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300143 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300144 -C 'I@salt:master' state.sls linux,openssh;
145 node_name: {{ HOSTNAME_CFG01 }}
146 retry: {count: 3, delay: 5}
147 skip_fail: false
148
149- description: Run 'reclass' formula on cfg01
150 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
151 -C 'I@salt:master' state.sls reclass;
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300152 salt --hard-crash --state-output=mixed --state-verbose=False
153 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
154 yes/' /etc/ssh/sshd_config && service ssh restart";
155 node_name: {{ HOSTNAME_CFG01 }}
156 retry: {count: 3, delay: 5}
157 skip_fail: false
158
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300159- description: Run 'salt' formula on cfg01
160 cmd: timeout 120 salt --hard-crash --state-output=mixed --state-verbose=False
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300161 -C 'I@salt:master' state.sls salt.master.service;
162 salt-call --no-color state.sls salt.master,salt.api,salt.minion.ca -l info;
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300163 node_name: {{ HOSTNAME_CFG01 }}
164 retry: {count: 3, delay: 5}
165 skip_fail: true
166
167- description: Accept salt keys from all the nodes
168 cmd: salt-key -A -y
169 node_name: {{ HOSTNAME_CFG01 }}
170 retry: {count: 1, delay: 5}
171 skip_fail: false
172
173- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
174 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
175 -C 'I@salt:master' state.sls reclass
176 node_name: {{ HOSTNAME_CFG01 }}
177 retry: {count: 3, delay: 5}
178 skip_fail: false
179
180- description: Refresh pillars on all minions
181 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
182 node_name: {{ HOSTNAME_CFG01 }}
183 retry: {count: 3, delay: 5}
184 skip_fail: false
185
186- description: Sync all salt resources
187 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
188 node_name: {{ HOSTNAME_CFG01 }}
189 retry: {count: 3, delay: 5}
190 skip_fail: false
191
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300192- description: Show reclass-salt --top
193 cmd: salt-call --no-color state.sls salt.minion.cert -l info
194 node_name: {{ HOSTNAME_CFG01 }}
195 retry: {count: 3, delay: 5}
196 skip_fail: false
197
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300198
199# Bootstrap all nodes
200
201- description: Workaround for missing kernel modules
202 cmd: salt '*' cmd.run "for module in nf_conntrack_ipv4 ip_tables
203 x_tables nf_defrag_ipv4 nf_nat_ipv4 nf_nat
204 iptable_filter iptable_mangle iptable_nat;
205 do
206 modprobe \$module;
207 echo \$module >> /etc/modules;
208 done"
209 node_name: {{ HOSTNAME_CFG01 }}
210 retry: {count: 1, delay: 1}
211 skip_fail: false
212
213
214- description: Configure linux on all nodes
215 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls
216 linux
217 node_name: {{ HOSTNAME_CFG01 }}
218 retry: {count: 5, delay: 5}
219 skip_fail: false
220
221- description: Configure openssh on all nodes
222 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
223 cfg*' state.sls openssh;salt --hard-crash --state-output=mixed --state-verbose=False
224 -C '* and not cfg*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
225 yes/' /etc/ssh/sshd_config && service ssh restart"
226 node_name: {{ HOSTNAME_CFG01 }}
227 retry: {count: 3, delay: 5}
228 skip_fail: false
229
230- description: '*Workaround* for the bug https://mirantis.jira.com/browse/PROD-8021'
231 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' cmd.run 'apt-get
232 -y install linux-image-extra-$(uname -r)'
233 node_name: {{ HOSTNAME_CFG01 }}
234 retry: {count: 3, delay: 5}
235 skip_fail: false
236
237- description: Configure salt.minion on controllers
238 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls salt.minion
239 node_name: {{ HOSTNAME_CFG01 }}
240 retry: {count: 3, delay: 5}
241 skip_fail: false
242
243- description: Check salt minion versions on slaves
244 cmd: salt '*' test.version
245 node_name: {{ HOSTNAME_CFG01 }}
246 retry: {count: 3, delay: 5}
247 skip_fail: false
248
249- description: Check salt minion versions on slaves
250 cmd: salt '*' state.show_top
251 node_name: {{ HOSTNAME_CFG01 }}
252 retry: {count: 3, delay: 5}
253 skip_fail: false
254
255- description: Configure ntp on controllers
256 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls ntp
257 node_name: {{ HOSTNAME_CFG01 }}
258 retry: {count: 5, delay: 10}
259 skip_fail: false
260