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