Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 1 | #!/bin/bash -xe |
| 2 | export SALT_MASTER_DEPLOY_IP=172.16.164.15 |
| 3 | export SALT_MASTER_MINION_ID=cfg01.deploy-name.local |
| 4 | export DEPLOY_NETWORK_GW=172.16.164.1 |
| 5 | export DEPLOY_NETWORK_NETMASK=255.255.255.192 |
| 6 | export DNS_SERVERS=8.8.8.8 |
Jiri Broulik | ff52d68 | 2017-11-22 14:39:08 +0100 | [diff] [blame] | 7 | export SYSTEM_URL=https://github.com/Mirantis/reclass-system-salt-model.git |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 8 | |
| 9 | echo "Configuring network interfaces" |
Dmitry Stremkouski | f50ea26 | 2017-12-05 19:35:40 +0300 | [diff] [blame^] | 10 | find /etc/network/interfaces.d/ -type f -delete |
| 11 | kill $(pidof /sbin/dhclient) || /bin/true |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 12 | envsubst < /root/interfaces > /etc/network/interfaces |
Dmitry Stremkouski | a94b5f3 | 2017-12-02 00:41:54 +0300 | [diff] [blame] | 13 | ip a flush dev ens3 |
Dmitry Stremkouski | b43c4ee | 2017-12-02 02:21:05 +0300 | [diff] [blame] | 14 | rm -f /var/run/network/ifstate.ens3 |
| 15 | if [[ $(grep -E '^\ *gateway\ ' /etc/network/interfaces) ]]; then |
| 16 | (ip r s | grep ^default) && ip r d default || /bin/true |
| 17 | fi; |
Dmitry Stremkouski | a94b5f3 | 2017-12-02 00:41:54 +0300 | [diff] [blame] | 18 | ifup ens3 |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 19 | |
| 20 | echo "Preparing metadata model" |
| 21 | mount /dev/cdrom /mnt/ |
| 22 | cp -r /mnt/model/model/* /srv/salt/reclass/ |
Jiri Broulik | ff52d68 | 2017-11-22 14:39:08 +0100 | [diff] [blame] | 23 | cp -r /mnt/model/model/.git /srv/salt/reclass/ |
| 24 | envsubst < /root/gitmodules > /srv/salt/reclass/.gitmodules |
| 25 | cd /srv/salt/reclass/classes/system/ |
| 26 | git remote remove origin |
| 27 | git remote add origin $SYSTEM_URL |
| 28 | cd /srv/salt/reclass/ |
| 29 | git submodule update --init --recursive |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 30 | chown -R root:root /srv/salt/reclass/* |
Jiri Broulik | ff52d68 | 2017-11-22 14:39:08 +0100 | [diff] [blame] | 31 | chown -R root:root /srv/salt/reclass/.git* |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 32 | chmod -R 644 /srv/salt/reclass/classes/cluster/* |
| 33 | chmod -R 644 /srv/salt/reclass/classes/system/* |
| 34 | |
| 35 | echo "updating git repos" |
| 36 | cp -r /mnt/mk-pipelines/* /home/repo/mk/mk-pipelines/ |
| 37 | cp -r /mnt/mk-pipelines/.git* /home/repo/mk/mk-pipelines/ |
| 38 | cp -r /mnt/pipeline-library/* /home/repo/mcp-ci/pipeline-library/ |
| 39 | cp -r /mnt/pipeline-library/.git* /home/repo/mcp-ci/pipeline-library/ |
| 40 | chown -R git:www-data /home/repo/mk/mk-pipelines/* |
| 41 | chown -R git:www-data /home/repo/mk/mk-pipelines/.git* |
| 42 | chown -R git:www-data /home/repo/mcp-ci/pipeline-library/* |
| 43 | chown -R git:www-data /home/repo/mcp-ci/pipeline-library/.git* |
| 44 | umount /dev/cdrom |
| 45 | |
| 46 | echo "Configuring salt" |
| 47 | #service salt-master restart |
| 48 | envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf |
| 49 | service salt-minion restart |
| 50 | while true; do |
| 51 | salt-key | grep "$SALT_MASTER_MINION_ID" && break |
| 52 | sleep 5 |
| 53 | done |
| 54 | sleep 5 |
| 55 | for i in `salt-key -l accepted | grep -v Accepted | grep -v "$SALT_MASTER_MINION_ID"`; do |
| 56 | salt-key -d $i -y |
| 57 | done |
| 58 | |
| 59 | find /var/lib/jenkins/jenkins.model.JenkinsLocationConfiguration.xml -type f -print0 | xargs -0 sed -i -e 's/10.167.4.15/'$SALT_MASTER_DEPLOY_IP'/g' |
| 60 | |
| 61 | salt-call saltutil.refresh_pillar |
| 62 | salt-call saltutil.sync_all |
| 63 | salt-call state.sls linux.network,linux,openssh,salt |
| 64 | salt-call state.sls maas.cluster,maas.region,reclass |
| 65 | |
| 66 | ssh-keyscan cfg01 > /var/lib/jenkins/.ssh/known_hosts |
| 67 | |
Dmitry Stremkouski | a94b5f3 | 2017-12-02 00:41:54 +0300 | [diff] [blame] | 68 | reboot |