blob: ae3b19e7e37a34bd8728b19d90766c265f5f817a [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
Tatyana Leontovich5fd6ed62017-04-04 15:08:29 +030069 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;
88 cat << 'EOF' >> /etc/reclass/reclass-config.yml
89 storage_type: yaml_fs
90 pretty_print: True
91 output: yaml
92 inventory_base_uri: /srv/salt/reclass
93 EOF
94 node_name: {{ HOSTNAME_CFG01 }}
95 retry: {count: 1, delay: 1}
96 skip_fail: false
97
98- description: Configure salt-minion on cfg01
99 cmd: |
100 [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d;
101 cat << "EOF" >> /etc/salt/minion.d/minion.conf
102 id: {{ HOSTNAME_CFG01 }}
Tatyana Leontovich5fd6ed62017-04-04 15:08:29 +0300103 master: 127.0.0.1
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300104 EOF
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300105 apt-get install -y salt-minion;
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300106 node_name: {{ HOSTNAME_CFG01 }}
107 retry: {count: 1, delay: 1}
108 skip_fail: false
109
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300110- description: Restart services
111 cmd: |
112 systemctl restart salt-master;
113 systemctl restart salt-minion;
114 echo "Showing system info and metadata ...";
115 salt-call --no-color grains.items;
116 salt-call --no-color pillar.data;
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300117 node_name: {{ HOSTNAME_CFG01 }}
118 retry: {count: 3, delay: 5}
119 skip_fail: false
120
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300121# Prepare salt services and nodes settings
122- description: Run 'linux' and openssh formula on cfg01
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300123 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300124 -C 'I@salt:master' state.sls linux,openssh;
125 node_name: {{ HOSTNAME_CFG01 }}
126 retry: {count: 3, delay: 5}
127 skip_fail: false
128
129- description: Run 'reclass' formula on cfg01
130 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
131 -C 'I@salt:master' state.sls reclass;
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300132 salt --hard-crash --state-output=mixed --state-verbose=False
133 -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
134 yes/' /etc/ssh/sshd_config && service ssh restart";
135 node_name: {{ HOSTNAME_CFG01 }}
136 retry: {count: 3, delay: 5}
137 skip_fail: false
138
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300139- description: Run 'salt' formula on cfg01
140 cmd: timeout 120 salt --hard-crash --state-output=mixed --state-verbose=False
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300141 -C 'I@salt:master' state.sls salt.master.service;
142 salt-call --no-color state.sls salt.master,salt.api,salt.minion.ca -l info;
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300143 node_name: {{ HOSTNAME_CFG01 }}
144 retry: {count: 3, delay: 5}
145 skip_fail: true
146
147- description: Accept salt keys from all the nodes
148 cmd: salt-key -A -y
149 node_name: {{ HOSTNAME_CFG01 }}
150 retry: {count: 1, delay: 5}
151 skip_fail: false
152
153- description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated
154 cmd: salt --hard-crash --state-output=mixed --state-verbose=False
155 -C 'I@salt:master' state.sls reclass
156 node_name: {{ HOSTNAME_CFG01 }}
157 retry: {count: 3, delay: 5}
158 skip_fail: false
159
160- description: Refresh pillars on all minions
161 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar
162 node_name: {{ HOSTNAME_CFG01 }}
163 retry: {count: 3, delay: 5}
164 skip_fail: false
165
166- description: Sync all salt resources
167 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all
168 node_name: {{ HOSTNAME_CFG01 }}
169 retry: {count: 3, delay: 5}
170 skip_fail: false
171
Tatyana Leontovich2dde4aa2017-04-04 13:06:10 +0300172- description: Show reclass-salt --top
173 cmd: salt-call --no-color state.sls salt.minion.cert -l info
174 node_name: {{ HOSTNAME_CFG01 }}
175 retry: {count: 3, delay: 5}
176 skip_fail: false
177
Tatyana Leontovich055b5062017-04-03 13:17:25 +0300178
179# Bootstrap all nodes
180
181- description: Workaround for missing kernel modules
182 cmd: salt '*' cmd.run "for module in nf_conntrack_ipv4 ip_tables
183 x_tables nf_defrag_ipv4 nf_nat_ipv4 nf_nat
184 iptable_filter iptable_mangle iptable_nat;
185 do
186 modprobe \$module;
187 echo \$module >> /etc/modules;
188 done"
189 node_name: {{ HOSTNAME_CFG01 }}
190 retry: {count: 1, delay: 1}
191 skip_fail: false
192
193
194- description: Configure linux on all nodes
195 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls
196 linux
197 node_name: {{ HOSTNAME_CFG01 }}
198 retry: {count: 5, delay: 5}
199 skip_fail: false
200
201- description: Configure openssh on all nodes
202 cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not
203 cfg*' state.sls openssh;salt --hard-crash --state-output=mixed --state-verbose=False
204 -C '* and not cfg*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication
205 yes/' /etc/ssh/sshd_config && service ssh restart"
206 node_name: {{ HOSTNAME_CFG01 }}
207 retry: {count: 3, delay: 5}
208 skip_fail: false
209
210- description: '*Workaround* for the bug https://mirantis.jira.com/browse/PROD-8021'
211 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' cmd.run 'apt-get
212 -y install linux-image-extra-$(uname -r)'
213 node_name: {{ HOSTNAME_CFG01 }}
214 retry: {count: 3, delay: 5}
215 skip_fail: false
216
217- description: Configure salt.minion on controllers
218 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls salt.minion
219 node_name: {{ HOSTNAME_CFG01 }}
220 retry: {count: 3, delay: 5}
221 skip_fail: false
222
223- description: Check salt minion versions on slaves
224 cmd: salt '*' test.version
225 node_name: {{ HOSTNAME_CFG01 }}
226 retry: {count: 3, delay: 5}
227 skip_fail: false
228
229- description: Check salt minion versions on slaves
230 cmd: salt '*' state.show_top
231 node_name: {{ HOSTNAME_CFG01 }}
232 retry: {count: 3, delay: 5}
233 skip_fail: false
234
235- description: Configure ntp on controllers
236 cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls ntp
237 node_name: {{ HOSTNAME_CFG01 }}
238 retry: {count: 5, delay: 10}
239 skip_fail: false
240