blob: de72542c49a89a0768122703fb886b97041ac795 [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-}";
102 for formula_service in in "${formula_services[@]}"; do;
103 echo -e "\nLink service metadata for formula ${formula_service} ...\n";
104 [ ! -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 +0300105 done;
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300106 [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env;
107 [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULA_PATH}/env /srv/salt/env/prd;
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300108 [ ! -d /etc/reclass ] && mkdir /etc/reclass;
109 cat << 'EOF' >> /etc/reclass/reclass-config.yml
110 storage_type: yaml_fs
111 pretty_print: True
112 output: yaml
113 inventory_base_uri: /srv/salt/reclass
114 EOF
115 node_name: {{ HOSTNAME_CFG01 }}
116 retry: {count: 1, delay: 1}
117 skip_fail: false
118
119- description: Configure salt-minion on cfg01
120 cmd: |
121 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
122 cat << "EOF" >> /etc/salt/minion.d/minion.conf
123 id: {{ HOSTNAME_CFG01 }}
124 master: localhost
125 EOF
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300126 apt-get install -y salt-minion;
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300127 node_name: {{ HOSTNAME_CFG01 }}
128 retry: {count: 1, delay: 1}
129 skip_fail: false
130
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300131- description: Restart services
132 cmd: |
133 systemctl restart salt-master;
134 systemctl restart salt-minion;
135 echo "Showing system info and metadata ...";
136 salt-call --no-color grains.items;
137 salt-call --no-color pillar.data;
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300138 node_name: {{ HOSTNAME_CFG01 }}
139 retry: {count: 3, delay: 5}
140 skip_fail: false
141
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300142# Prepare salt services and nodes settings
143- description: Run 'linux' and openssh formula on cfg01
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300144 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300145 -C 'I@salt:master' state.sls linux,openssh;
146 node_name: {{ HOSTNAME_CFG01 }}
147 retry: {count: 3, delay: 5}
148 skip_fail: false
149
150- description: Run 'reclass' formula on cfg01
151 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
152 -C 'I@salt:master' state.sls reclass;
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300153 salt --hard-crash --state-output=mixed --state-verbose=False
154 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
155 yes/' /etc/ssh/sshd_config && service ssh restart";
156 node_name: {{ HOSTNAME_CFG01 }}
157 retry: {count: 3, delay: 5}
158 skip_fail: false
159
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300160- description: Run 'salt' formula on cfg01
161 cmd: timeout 120 salt --hard-crash --state-output=mixed --state-verbose=False
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300162 -C 'I@salt:master' state.sls salt.master.service;
163 salt-call --no-color state.sls salt.master,salt.api,salt.minion.ca -l info;
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300164 node_name: {{ HOSTNAME_CFG01 }}
165 retry: {count: 3, delay: 5}
166 skip_fail: true
167
168- description: Accept salt keys from all the nodes
169 cmd: salt-key -A -y
170 node_name: {{ HOSTNAME_CFG01 }}
171 retry: {count: 1, delay: 5}
172 skip_fail: false
173
174- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
175 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
176 -C 'I@salt:master' state.sls reclass
177 node_name: {{ HOSTNAME_CFG01 }}
178 retry: {count: 3, delay: 5}
179 skip_fail: false
180
181- description: Refresh pillars on all minions
182 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
183 node_name: {{ HOSTNAME_CFG01 }}
184 retry: {count: 3, delay: 5}
185 skip_fail: false
186
187- description: Sync all salt resources
188 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
189 node_name: {{ HOSTNAME_CFG01 }}
190 retry: {count: 3, delay: 5}
191 skip_fail: false
192
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300193- description: Show reclass-salt --top
194 cmd: salt-call --no-color state.sls salt.minion.cert -l info
195 node_name: {{ HOSTNAME_CFG01 }}
196 retry: {count: 3, delay: 5}
197 skip_fail: false
198
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300199
200# Bootstrap all nodes
201
202- description: Workaround for missing kernel modules
203 cmd: salt '*' cmd.run "for module in nf_conntrack_ipv4 ip_tables
204 x_tables nf_defrag_ipv4 nf_nat_ipv4 nf_nat
205 iptable_filter iptable_mangle iptable_nat;
206 do
207 modprobe \$module;
208 echo \$module >> /etc/modules;
209 done"
210 node_name: {{ HOSTNAME_CFG01 }}
211 retry: {count: 1, delay: 1}
212 skip_fail: false
213
214
215- description: Configure linux on all nodes
216 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls
217 linux
218 node_name: {{ HOSTNAME_CFG01 }}
219 retry: {count: 5, delay: 5}
220 skip_fail: false
221
222- description: Configure openssh on all nodes
223 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
224 cfg*' state.sls openssh;salt --hard-crash --state-output=mixed --state-verbose=False
225 -C '* and not cfg*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
226 yes/' /etc/ssh/sshd_config && service ssh restart"
227 node_name: {{ HOSTNAME_CFG01 }}
228 retry: {count: 3, delay: 5}
229 skip_fail: false
230
231- description: '*Workaround* for the bug https://mirantis.jira.com/browse/PROD-8021'
232 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' cmd.run 'apt-get
233 -y install linux-image-extra-$(uname -r)'
234 node_name: {{ HOSTNAME_CFG01 }}
235 retry: {count: 3, delay: 5}
236 skip_fail: false
237
238- description: Configure salt.minion on controllers
239 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls salt.minion
240 node_name: {{ HOSTNAME_CFG01 }}
241 retry: {count: 3, delay: 5}
242 skip_fail: false
243
244- description: Check salt minion versions on slaves
245 cmd: salt '*' test.version
246 node_name: {{ HOSTNAME_CFG01 }}
247 retry: {count: 3, delay: 5}
248 skip_fail: false
249
250- description: Check salt minion versions on slaves
251 cmd: salt '*' state.show_top
252 node_name: {{ HOSTNAME_CFG01 }}
253 retry: {count: 3, delay: 5}
254 skip_fail: false
255
256- description: Configure ntp on controllers
257 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls ntp
258 node_name: {{ HOSTNAME_CFG01 }}
259 retry: {count: 5, delay: 10}
260 skip_fail: false
261