blob: 5802f2c760e115a48de0a429702f8cd0b0764726 [file] [log] [blame]
Richard Felkl4c4829d2017-11-11 00:12:20 +01001#!/bin/bash -xe
2export SALT_MASTER_DEPLOY_IP=172.16.164.15
3export SALT_MASTER_MINION_ID=cfg01.deploy-name.local
4export DEPLOY_NETWORK_GW=172.16.164.1
5export DEPLOY_NETWORK_NETMASK=255.255.255.192
6export DNS_SERVERS=8.8.8.8
Jiri Broulikcee20532018-01-08 13:30:15 +01007export http_proxy=
8export https_proxy=
9export PIPELINES_FROM_ISO=true
10export 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 Felkl4c4829d2017-11-11 00:12:20 +010013
Jiri Broulikfd84eeb2017-12-13 11:22:00 +010014rm -vf /etc/update-motd.d/52-info
Richard Felkl4c4829d2017-11-11 00:12:20 +010015echo "Configuring network interfaces"
Dmitry Stremkouskif50ea262017-12-05 19:35:40 +030016find /etc/network/interfaces.d/ -type f -delete
17kill $(pidof /sbin/dhclient) || /bin/true
Richard Felkl4c4829d2017-11-11 00:12:20 +010018envsubst < /root/interfaces > /etc/network/interfaces
Dmitry Stremkouskia94b5f32017-12-02 00:41:54 +030019ip a flush dev ens3
Dmitry Stremkouskib43c4ee2017-12-02 02:21:05 +030020rm -f /var/run/network/ifstate.ens3
21if [[ $(grep -E '^\ *gateway\ ' /etc/network/interfaces) ]]; then
22(ip r s | grep ^default) && ip r d default || /bin/true
23fi;
Dmitry Stremkouskia94b5f32017-12-02 00:41:54 +030024ifup ens3
Richard Felkl4c4829d2017-11-11 00:12:20 +010025
26echo "Preparing metadata model"
27mount /dev/cdrom /mnt/
Leontii Istomin68553f12018-02-21 18:10:12 +010028for FOLDER in
29cp -rT /mnt/model/model /srv/salt/reclass
Richard Felkl4c4829d2017-11-11 00:12:20 +010030chown -R root:root /srv/salt/reclass/*
Jiri Broulikff52d682017-11-22 14:39:08 +010031chown -R root:root /srv/salt/reclass/.git*
Richard Felkl4c4829d2017-11-11 00:12:20 +010032chmod -R 644 /srv/salt/reclass/classes/cluster/*
33chmod -R 644 /srv/salt/reclass/classes/system/*
34
Richard Felkl4c4829d2017-11-11 00:12:20 +010035echo "Configuring salt"
36#service salt-master restart
37envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf
38service salt-minion restart
39while true; do
40 salt-key | grep "$SALT_MASTER_MINION_ID" && break
41 sleep 5
42done
43sleep 5
44for i in `salt-key -l accepted | grep -v Accepted | grep -v "$SALT_MASTER_MINION_ID"`; do
45 salt-key -d $i -y
46done
47
48find /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 Broulikcee20532018-01-08 13:30:15 +010050echo "updating git repos"
51if [ "$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 Broulik739bd352018-01-09 15:26:15 +010054 umount /dev/cdrom
Jiri Broulikcee20532018-01-08 13:30:15 +010055 chown -R git:www-data /home/repo/mk/mk-pipelines/*
56 chown -R git:www-data /home/repo/mcp-ci/pipeline-library/*
57else
Jiri Broulik739bd352018-01-09 15:26:15 +010058 umount /dev/cdrom
Jiri Broulikcee20532018-01-08 13:30:15 +010059 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/*
63fi
64
Richard Felkl4c4829d2017-11-11 00:12:20 +010065salt-call saltutil.refresh_pillar
66salt-call saltutil.sync_all
67salt-call state.sls linux.network,linux,openssh,salt
68salt-call state.sls maas.cluster,maas.region,reclass
69
Jiri Broulik1261ca32018-01-18 15:30:25 +010070ssh-keyscan cfg01 > /var/lib/jenkins/.ssh/known_hosts
71
Jiri Broulike40813f2018-01-16 13:35:19 +010072pillar=`salt-call pillar.data jenkins:client`
73
74if [[ $pillar == *"job"* ]]; then
75 salt-call state.sls jenkins.client
76fi
Richard Felkl4c4829d2017-11-11 00:12:20 +010077
Dmitry Stremkouskia94b5f32017-12-02 00:41:54 +030078reboot