Tatyana Leontovich | 055b506 | 2017-04-03 13:17:25 +0300 | [diff] [blame] | 1 | {% from 'virtual_mcp10_ovs.jinja' import HOSTNAME_CFG01 with context %} |
| 2 | |
| 3 | # Install salt to the config node |
| 4 | |
| 5 | |
Tatyana Leontovich | 5fd6ed6 | 2017-04-04 15:08:29 +0300 | [diff] [blame] | 6 | - 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 Leontovich | 2dde4aa | 2017-04-04 13:06:10 +0300 | [diff] [blame] | 14 | wget -O - http://apt-mk.mirantis.com/public.gpg | apt-key add -; |
Tatyana Leontovich | 055b506 | 2017-04-03 13:17:25 +0300 | [diff] [blame] | 15 | 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 Leontovich | 055b506 | 2017-04-03 13:17:25 +0300 | [diff] [blame] | 17 | node_name: {{ HOSTNAME_CFG01 }} |
| 18 | retry: {count: 1, delay: 1} |
| 19 | skip_fail: false |
| 20 | |
Tatyana Leontovich | 055b506 | 2017-04-03 13:17:25 +0300 | [diff] [blame] | 21 | - description: Update packages on cfg01 |
Tatyana Leontovich | 2dde4aa | 2017-04-04 13:06:10 +0300 | [diff] [blame] | 22 | cmd: apt-get clean; apt-get update |
Tatyana Leontovich | 055b506 | 2017-04-03 13:17:25 +0300 | [diff] [blame] | 23 | node_name: {{ HOSTNAME_CFG01 }} |
Tatyana Leontovich | 2dde4aa | 2017-04-04 13:06:10 +0300 | [diff] [blame] | 24 | retry: {count: 1, delay: 1} |
Tatyana Leontovich | 055b506 | 2017-04-03 13:17:25 +0300 | [diff] [blame] | 25 | skip_fail: false |
| 26 | |
Tatyana Leontovich | 5fd6ed6 | 2017-04-04 15:08:29 +0300 | [diff] [blame] | 27 | - description: Installing salt master on cfg01 |
| 28 | cmd: apt-get install -y reclass git; apt-get install -y salt-master |
Tatyana Leontovich | 055b506 | 2017-04-03 13:17:25 +0300 | [diff] [blame] | 29 | node_name: {{ HOSTNAME_CFG01 }} |
Tatyana Leontovich | 2dde4aa | 2017-04-04 13:06:10 +0300 | [diff] [blame] | 30 | 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 Leontovich | 055b506 | 2017-04-03 13:17:25 +0300 | [diff] [blame] | 37 | skip_fail: false |
| 38 | |
Tatyana Leontovich | 055b506 | 2017-04-03 13:17:25 +0300 | [diff] [blame] | 39 | - 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 Leontovich | 2dde4aa | 2017-04-04 13:06:10 +0300 | [diff] [blame] | 59 | - description: Clone reclass models with submodules |
Tatyana Leontovich | 055b506 | 2017-04-03 13:17:25 +0300 | [diff] [blame] | 60 | cmd: | |
Tatyana Leontovich | 2dde4aa | 2017-04-04 13:06:10 +0300 | [diff] [blame] | 61 | ssh-keyscan -H github.com >> ~/.ssh/known_hosts; |
Tatyana Leontovich | 5fd6ed6 | 2017-04-04 15:08:29 +0300 | [diff] [blame] | 62 | 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 Leontovich | 055b506 | 2017-04-03 13:17:25 +0300 | [diff] [blame] | 64 | node_name: {{ HOSTNAME_CFG01 }} |
| 65 | retry: {count: 1, delay: 1} |
| 66 | skip_fail: false |
| 67 | |
| 68 | - description: Configure reclass |
| 69 | cmd: | |
Tatyana Leontovich | 2dde4aa | 2017-04-04 13:06:10 +0300 | [diff] [blame] | 70 | 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 Leontovich | 14f6a1a | 2017-04-04 17:30:58 +0300 | [diff] [blame^] | 81 | for formula_service in "${formula_services[@]}"; do |
Tatyana Leontovich | 2dde4aa | 2017-04-04 13:06:10 +0300 | [diff] [blame] | 82 | 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 Leontovich | 055b506 | 2017-04-03 13:17:25 +0300 | [diff] [blame] | 84 | done; |
Tatyana Leontovich | 2dde4aa | 2017-04-04 13:06:10 +0300 | [diff] [blame] | 85 | [ ! -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 Leontovich | 055b506 | 2017-04-03 13:17:25 +0300 | [diff] [blame] | 87 | [ ! -d /etc/reclass ] && mkdir /etc/reclass; |
Tatyana Leontovich | 193554a | 2017-04-04 17:19:13 +0300 | [diff] [blame] | 88 | |
Tatyana Leontovich | 055b506 | 2017-04-03 13:17:25 +0300 | [diff] [blame] | 89 | 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 Leontovich | 5fd6ed6 | 2017-04-04 15:08:29 +0300 | [diff] [blame] | 104 | master: 127.0.0.1 |
Tatyana Leontovich | 055b506 | 2017-04-03 13:17:25 +0300 | [diff] [blame] | 105 | EOF |
Tatyana Leontovich | 2dde4aa | 2017-04-04 13:06:10 +0300 | [diff] [blame] | 106 | apt-get install -y salt-minion; |
Tatyana Leontovich | 055b506 | 2017-04-03 13:17:25 +0300 | [diff] [blame] | 107 | node_name: {{ HOSTNAME_CFG01 }} |
| 108 | retry: {count: 1, delay: 1} |
| 109 | skip_fail: false |
| 110 | |
Tatyana Leontovich | 14f6a1a | 2017-04-04 17:30:58 +0300 | [diff] [blame^] | 111 | - description: Configure salt adoptors on cfg01 |
| 112 | cmd: | |
| 113 | ln -s /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py /usr/local/sbin/salt-reclass; |
| 114 | chmod +x /usr/lib/python2.7/dist-packages/reclass/adapters/salt.py |
| 115 | node_name: {{ HOSTNAME_CFG01 }} |
| 116 | retry: {count: 1, delay: 1} |
| 117 | skip_fail: false |
| 118 | |
Tatyana Leontovich | 2dde4aa | 2017-04-04 13:06:10 +0300 | [diff] [blame] | 119 | - description: Restart services |
| 120 | cmd: | |
| 121 | systemctl restart salt-master; |
| 122 | systemctl restart salt-minion; |
| 123 | echo "Showing system info and metadata ..."; |
| 124 | salt-call --no-color grains.items; |
| 125 | salt-call --no-color pillar.data; |
Tatyana Leontovich | 055b506 | 2017-04-03 13:17:25 +0300 | [diff] [blame] | 126 | node_name: {{ HOSTNAME_CFG01 }} |
| 127 | retry: {count: 3, delay: 5} |
| 128 | skip_fail: false |
| 129 | |
Tatyana Leontovich | 2dde4aa | 2017-04-04 13:06:10 +0300 | [diff] [blame] | 130 | # Prepare salt services and nodes settings |
| 131 | - description: Run 'linux' and openssh formula on cfg01 |
Tatyana Leontovich | 055b506 | 2017-04-03 13:17:25 +0300 | [diff] [blame] | 132 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
Tatyana Leontovich | 2dde4aa | 2017-04-04 13:06:10 +0300 | [diff] [blame] | 133 | -C 'I@salt:master' state.sls linux,openssh; |
| 134 | node_name: {{ HOSTNAME_CFG01 }} |
| 135 | retry: {count: 3, delay: 5} |
| 136 | skip_fail: false |
| 137 | |
| 138 | - description: Run 'reclass' formula on cfg01 |
| 139 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 140 | -C 'I@salt:master' state.sls reclass; |
Tatyana Leontovich | 055b506 | 2017-04-03 13:17:25 +0300 | [diff] [blame] | 141 | salt --hard-crash --state-output=mixed --state-verbose=False |
| 142 | -C 'I@salt:master' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication |
| 143 | yes/' /etc/ssh/sshd_config && service ssh restart"; |
| 144 | node_name: {{ HOSTNAME_CFG01 }} |
| 145 | retry: {count: 3, delay: 5} |
| 146 | skip_fail: false |
| 147 | |
Tatyana Leontovich | 055b506 | 2017-04-03 13:17:25 +0300 | [diff] [blame] | 148 | - description: Run 'salt' formula on cfg01 |
| 149 | cmd: timeout 120 salt --hard-crash --state-output=mixed --state-verbose=False |
Tatyana Leontovich | 2dde4aa | 2017-04-04 13:06:10 +0300 | [diff] [blame] | 150 | -C 'I@salt:master' state.sls salt.master.service; |
| 151 | salt-call --no-color state.sls salt.master,salt.api,salt.minion.ca -l info; |
Tatyana Leontovich | 055b506 | 2017-04-03 13:17:25 +0300 | [diff] [blame] | 152 | node_name: {{ HOSTNAME_CFG01 }} |
| 153 | retry: {count: 3, delay: 5} |
| 154 | skip_fail: true |
| 155 | |
| 156 | - description: Accept salt keys from all the nodes |
| 157 | cmd: salt-key -A -y |
| 158 | node_name: {{ HOSTNAME_CFG01 }} |
| 159 | retry: {count: 1, delay: 5} |
| 160 | skip_fail: false |
| 161 | |
| 162 | - description: Generate inventory for all the nodes to the /srv/salt/reclass/nodes/_generated |
| 163 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False |
| 164 | -C 'I@salt:master' state.sls reclass |
| 165 | node_name: {{ HOSTNAME_CFG01 }} |
| 166 | retry: {count: 3, delay: 5} |
| 167 | skip_fail: false |
| 168 | |
| 169 | - description: Refresh pillars on all minions |
| 170 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.refresh_pillar |
| 171 | node_name: {{ HOSTNAME_CFG01 }} |
| 172 | retry: {count: 3, delay: 5} |
| 173 | skip_fail: false |
| 174 | |
| 175 | - description: Sync all salt resources |
| 176 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' saltutil.sync_all |
| 177 | node_name: {{ HOSTNAME_CFG01 }} |
| 178 | retry: {count: 3, delay: 5} |
| 179 | skip_fail: false |
| 180 | |
Tatyana Leontovich | 2dde4aa | 2017-04-04 13:06:10 +0300 | [diff] [blame] | 181 | - description: Show reclass-salt --top |
| 182 | cmd: salt-call --no-color state.sls salt.minion.cert -l info |
| 183 | node_name: {{ HOSTNAME_CFG01 }} |
| 184 | retry: {count: 3, delay: 5} |
| 185 | skip_fail: false |
| 186 | |
Tatyana Leontovich | 055b506 | 2017-04-03 13:17:25 +0300 | [diff] [blame] | 187 | |
| 188 | # Bootstrap all nodes |
| 189 | |
| 190 | - description: Workaround for missing kernel modules |
| 191 | cmd: salt '*' cmd.run "for module in nf_conntrack_ipv4 ip_tables |
| 192 | x_tables nf_defrag_ipv4 nf_nat_ipv4 nf_nat |
| 193 | iptable_filter iptable_mangle iptable_nat; |
| 194 | do |
| 195 | modprobe \$module; |
| 196 | echo \$module >> /etc/modules; |
| 197 | done" |
| 198 | node_name: {{ HOSTNAME_CFG01 }} |
| 199 | retry: {count: 1, delay: 1} |
| 200 | skip_fail: false |
| 201 | |
| 202 | |
| 203 | - description: Configure linux on all nodes |
| 204 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls |
| 205 | linux |
| 206 | node_name: {{ HOSTNAME_CFG01 }} |
| 207 | retry: {count: 5, delay: 5} |
| 208 | skip_fail: false |
| 209 | |
| 210 | - description: Configure openssh on all nodes |
| 211 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False -C '* and not |
| 212 | cfg*' state.sls openssh;salt --hard-crash --state-output=mixed --state-verbose=False |
| 213 | -C '* and not cfg*' cmd.run "sed -i 's/PasswordAuthentication no/PasswordAuthentication |
| 214 | yes/' /etc/ssh/sshd_config && service ssh restart" |
| 215 | node_name: {{ HOSTNAME_CFG01 }} |
| 216 | retry: {count: 3, delay: 5} |
| 217 | skip_fail: false |
| 218 | |
| 219 | - description: '*Workaround* for the bug https://mirantis.jira.com/browse/PROD-8021' |
| 220 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' cmd.run 'apt-get |
| 221 | -y install linux-image-extra-$(uname -r)' |
| 222 | node_name: {{ HOSTNAME_CFG01 }} |
| 223 | retry: {count: 3, delay: 5} |
| 224 | skip_fail: false |
| 225 | |
| 226 | - description: Configure salt.minion on controllers |
| 227 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls salt.minion |
| 228 | node_name: {{ HOSTNAME_CFG01 }} |
| 229 | retry: {count: 3, delay: 5} |
| 230 | skip_fail: false |
| 231 | |
| 232 | - description: Check salt minion versions on slaves |
| 233 | cmd: salt '*' test.version |
| 234 | node_name: {{ HOSTNAME_CFG01 }} |
| 235 | retry: {count: 3, delay: 5} |
| 236 | skip_fail: false |
| 237 | |
| 238 | - description: Check salt minion versions on slaves |
| 239 | cmd: salt '*' state.show_top |
| 240 | node_name: {{ HOSTNAME_CFG01 }} |
| 241 | retry: {count: 3, delay: 5} |
| 242 | skip_fail: false |
| 243 | |
| 244 | - description: Configure ntp on controllers |
| 245 | cmd: salt --hard-crash --state-output=mixed --state-verbose=False '*' state.sls ntp |
| 246 | node_name: {{ HOSTNAME_CFG01 }} |
| 247 | retry: {count: 5, delay: 10} |
| 248 | skip_fail: false |
| 249 | |