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 |
Jiri Broulik | cee2053 | 2018-01-08 13:30:15 +0100 | [diff] [blame^] | 8 | export http_proxy= |
| 9 | export https_proxy= |
| 10 | export PIPELINES_FROM_ISO=true |
| 11 | export PIPELINE_REPO_URL=https://github.com/Mirantis |
| 12 | #for cloning from aptly image use port 8088 |
| 13 | #export PIPELINE_REPO_URL=http://172.16.47.182:8088 |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 14 | |
Jiri Broulik | fd84eeb | 2017-12-13 11:22:00 +0100 | [diff] [blame] | 15 | rm -vf /etc/update-motd.d/52-info |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 16 | echo "Configuring network interfaces" |
Dmitry Stremkouski | f50ea26 | 2017-12-05 19:35:40 +0300 | [diff] [blame] | 17 | find /etc/network/interfaces.d/ -type f -delete |
| 18 | kill $(pidof /sbin/dhclient) || /bin/true |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 19 | envsubst < /root/interfaces > /etc/network/interfaces |
Dmitry Stremkouski | a94b5f3 | 2017-12-02 00:41:54 +0300 | [diff] [blame] | 20 | ip a flush dev ens3 |
Dmitry Stremkouski | b43c4ee | 2017-12-02 02:21:05 +0300 | [diff] [blame] | 21 | rm -f /var/run/network/ifstate.ens3 |
| 22 | if [[ $(grep -E '^\ *gateway\ ' /etc/network/interfaces) ]]; then |
| 23 | (ip r s | grep ^default) && ip r d default || /bin/true |
| 24 | fi; |
Dmitry Stremkouski | a94b5f3 | 2017-12-02 00:41:54 +0300 | [diff] [blame] | 25 | ifup ens3 |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 26 | |
| 27 | echo "Preparing metadata model" |
| 28 | mount /dev/cdrom /mnt/ |
| 29 | cp -r /mnt/model/model/* /srv/salt/reclass/ |
Jiri Broulik | ff52d68 | 2017-11-22 14:39:08 +0100 | [diff] [blame] | 30 | cp -r /mnt/model/model/.git /srv/salt/reclass/ |
| 31 | envsubst < /root/gitmodules > /srv/salt/reclass/.gitmodules |
| 32 | cd /srv/salt/reclass/classes/system/ |
| 33 | git remote remove origin |
| 34 | git remote add origin $SYSTEM_URL |
| 35 | cd /srv/salt/reclass/ |
| 36 | git submodule update --init --recursive |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 37 | chown -R root:root /srv/salt/reclass/* |
Jiri Broulik | ff52d68 | 2017-11-22 14:39:08 +0100 | [diff] [blame] | 38 | chown -R root:root /srv/salt/reclass/.git* |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 39 | chmod -R 644 /srv/salt/reclass/classes/cluster/* |
| 40 | chmod -R 644 /srv/salt/reclass/classes/system/* |
| 41 | |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 42 | echo "Configuring salt" |
| 43 | #service salt-master restart |
| 44 | envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf |
| 45 | service salt-minion restart |
| 46 | while true; do |
| 47 | salt-key | grep "$SALT_MASTER_MINION_ID" && break |
| 48 | sleep 5 |
| 49 | done |
| 50 | sleep 5 |
| 51 | for i in `salt-key -l accepted | grep -v Accepted | grep -v "$SALT_MASTER_MINION_ID"`; do |
| 52 | salt-key -d $i -y |
| 53 | done |
| 54 | |
| 55 | 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' |
| 56 | |
Jiri Broulik | cee2053 | 2018-01-08 13:30:15 +0100 | [diff] [blame^] | 57 | echo "updating git repos" |
| 58 | if [ "$PIPELINES_FROM_ISO" = true ] ; then |
| 59 | cp -r /mnt/mk-pipelines/* /home/repo/mk/mk-pipelines/ |
| 60 | cp -r /mnt/pipeline-library/* /home/repo/mcp-ci/pipeline-library/ |
| 61 | chown -R git:www-data /home/repo/mk/mk-pipelines/* |
| 62 | chown -R git:www-data /home/repo/mcp-ci/pipeline-library/* |
| 63 | else |
| 64 | git clone --mirror $PIPELINE_REPO_URL/mk-pipelines.git /home/repo/mk/mk-pipelines/ |
| 65 | git clone --mirror $PIPELINE_REPO_URL/pipeline-library.git /home/repo/mcp-ci/pipeline-library/ |
| 66 | chown -R git:www-data /home/repo/mk/mk-pipelines/* |
| 67 | chown -R git:www-data /home/repo/mcp-ci/pipeline-library/* |
| 68 | fi |
| 69 | |
| 70 | umount /dev/cdrom |
| 71 | |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 72 | salt-call saltutil.refresh_pillar |
| 73 | salt-call saltutil.sync_all |
| 74 | salt-call state.sls linux.network,linux,openssh,salt |
| 75 | salt-call state.sls maas.cluster,maas.region,reclass |
| 76 | |
| 77 | ssh-keyscan cfg01 > /var/lib/jenkins/.ssh/known_hosts |
| 78 | |
Dmitry Stremkouski | a94b5f3 | 2017-12-02 00:41:54 +0300 | [diff] [blame] | 79 | reboot |