blob: 8945ef1e46e49f8de6c37c9ff452e3f8db9b4c28 [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
Richard Felkl98b45342018-04-06 13:30:28 +020011export MCP_VERSION=stable
12export MCP_SALT_REPO_KEY=http://apt.mirantis.com/public.gpg
13export MCP_SALT_REPO_URL=http://apt.mirantis.com/xenial
14export MCP_SALT_REPO="deb [arch=amd64] $MCP_SALT_REPO_URL $MCP_VERSION salt"
15export FORMULAS="salt-formula-*"
Jiri Broulik0173a272018-04-11 10:56:35 +020016export LOCAL_REPOS=false
Jiri Broulikcee20532018-01-08 13:30:15 +010017#for cloning from aptly image use port 8088
18#export PIPELINE_REPO_URL=http://172.16.47.182:8088
Richard Felkl4c4829d2017-11-11 00:12:20 +010019
Jiri Broulikfd84eeb2017-12-13 11:22:00 +010020rm -vf /etc/update-motd.d/52-info
Richard Felkl4c4829d2017-11-11 00:12:20 +010021echo "Configuring network interfaces"
Dmitry Stremkouskif50ea262017-12-05 19:35:40 +030022find /etc/network/interfaces.d/ -type f -delete
23kill $(pidof /sbin/dhclient) || /bin/true
Richard Felkl4c4829d2017-11-11 00:12:20 +010024envsubst < /root/interfaces > /etc/network/interfaces
Dmitry Stremkouskia94b5f32017-12-02 00:41:54 +030025ip a flush dev ens3
Dmitry Stremkouskib43c4ee2017-12-02 02:21:05 +030026rm -f /var/run/network/ifstate.ens3
27if [[ $(grep -E '^\ *gateway\ ' /etc/network/interfaces) ]]; then
28(ip r s | grep ^default) && ip r d default || /bin/true
29fi;
Dmitry Stremkouskia94b5f32017-12-02 00:41:54 +030030ifup ens3
Richard Felkl4c4829d2017-11-11 00:12:20 +010031
32echo "Preparing metadata model"
33mount /dev/cdrom /mnt/
Leontii Istomin68553f12018-02-21 18:10:12 +010034cp -rT /mnt/model/model /srv/salt/reclass
Richard Felkl4c4829d2017-11-11 00:12:20 +010035chown -R root:root /srv/salt/reclass/*
Jiri Broulikff52d682017-11-22 14:39:08 +010036chown -R root:root /srv/salt/reclass/.git*
Richard Felkl4c4829d2017-11-11 00:12:20 +010037chmod -R 644 /srv/salt/reclass/classes/cluster/*
38chmod -R 644 /srv/salt/reclass/classes/system/*
39
Richard Felkl4c4829d2017-11-11 00:12:20 +010040echo "Configuring salt"
41#service salt-master restart
42envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf
43service salt-minion restart
44while true; do
45 salt-key | grep "$SALT_MASTER_MINION_ID" && break
46 sleep 5
47done
48sleep 5
49for i in `salt-key -l accepted | grep -v Accepted | grep -v "$SALT_MASTER_MINION_ID"`; do
50 salt-key -d $i -y
51done
52
53find /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'
54
Jiri Broulikcee20532018-01-08 13:30:15 +010055echo "updating git repos"
56if [ "$PIPELINES_FROM_ISO" = true ] ; then
57 cp -r /mnt/mk-pipelines/* /home/repo/mk/mk-pipelines/
58 cp -r /mnt/pipeline-library/* /home/repo/mcp-ci/pipeline-library/
Jiri Broulik739bd352018-01-09 15:26:15 +010059 umount /dev/cdrom
Jiri Broulikcee20532018-01-08 13:30:15 +010060 chown -R git:www-data /home/repo/mk/mk-pipelines/*
61 chown -R git:www-data /home/repo/mcp-ci/pipeline-library/*
62else
Jiri Broulik739bd352018-01-09 15:26:15 +010063 umount /dev/cdrom
Jiri Broulikcee20532018-01-08 13:30:15 +010064 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/*
68fi
69
Richard Felkl98b45342018-04-06 13:30:28 +020070echo "installing formulas"
71curl -s $MCP_SALT_REPO_KEY | sudo apt-key add -
72echo $MCP_SALT_REPO > /etc/apt/sources.list.d/mcp_salt.list
73apt-get update
74apt-get install -y $FORMULAS
75rm -r /srv/salt/reclass/classes/service/*
Richard Felkl58026842018-04-10 11:17:01 +020076cd /srv/salt/reclass/classes/service/;ls /usr/share/salt-formulas/reclass/service/ -1 | xargs -I{} ln -s /usr/share/salt-formulas/reclass/service/{};cd /root
Richard Felkl98b45342018-04-06 13:30:28 +020077
Richard Felkl4c4829d2017-11-11 00:12:20 +010078salt-call saltutil.refresh_pillar
79salt-call saltutil.sync_all
80salt-call state.sls linux.network,linux,openssh,salt
Ondrej Smola0c71bfd2018-03-16 12:07:38 +010081salt-call state.sls salt
Richard Felkl4c4829d2017-11-11 00:12:20 +010082salt-call state.sls maas.cluster,maas.region,reclass
83
Jiri Broulik0173a272018-04-11 10:56:35 +020084# Download ubuntu image from MAAS local mirror
85if [ "$LOCAL_REPOS" = true ] ; then
86 /var/lib/maas/.maas_login.sh
87 maas mirantis boot-source-selections create 2 os="ubuntu" release="xenial" arches="amd64" subarches="*" labels="*"
88 maas mirantis boot-source delete 1
89 maas mirantis boot-resources import
90fi
91
Jiri Broulik1261ca32018-01-18 15:30:25 +010092ssh-keyscan cfg01 > /var/lib/jenkins/.ssh/known_hosts
93
Jiri Broulike40813f2018-01-16 13:35:19 +010094pillar=`salt-call pillar.data jenkins:client`
95
96if [[ $pillar == *"job"* ]]; then
97 salt-call state.sls jenkins.client
98fi
Richard Felkl4c4829d2017-11-11 00:12:20 +010099
Dmitry Stremkouskia94b5f32017-12-02 00:41:54 +0300100reboot