blob: c79a871b1503403d72af0ed7a4e29a2caedff144 [file] [log] [blame]
Richard Felkl4c4829d2017-11-11 00:12:20 +01001#!/bin/bash -xe
alexzd90608b2018-04-12 23:49:03 +02002
Richard Felkl4c4829d2017-11-11 00:12:20 +01003export SALT_MASTER_DEPLOY_IP=172.16.164.15
4export SALT_MASTER_MINION_ID=cfg01.deploy-name.local
5export DEPLOY_NETWORK_GW=172.16.164.1
6export DEPLOY_NETWORK_NETMASK=255.255.255.192
7export DNS_SERVERS=8.8.8.8
Jiri Broulikcee20532018-01-08 13:30:15 +01008export http_proxy=
9export https_proxy=
10export PIPELINES_FROM_ISO=true
11export PIPELINE_REPO_URL=https://github.com/Mirantis
Richard Felkl98b45342018-04-06 13:30:28 +020012export MCP_VERSION=stable
13export MCP_SALT_REPO_KEY=http://apt.mirantis.com/public.gpg
14export MCP_SALT_REPO_URL=http://apt.mirantis.com/xenial
15export MCP_SALT_REPO="deb [arch=amd64] $MCP_SALT_REPO_URL $MCP_VERSION salt"
16export FORMULAS="salt-formula-*"
alexzd90608b2018-04-12 23:49:03 +020017# Not avaible in 2018.3.1 and pre.
18# TODO should be renamed to LOCAL_MAAS_STREAMS
Jiri Broulik0173a272018-04-11 10:56:35 +020019export LOCAL_REPOS=false
Jiri Broulikcee20532018-01-08 13:30:15 +010020#for cloning from aptly image use port 8088
21#export PIPELINE_REPO_URL=http://172.16.47.182:8088
Richard Felkl4c4829d2017-11-11 00:12:20 +010022
alexzd90608b2018-04-12 23:49:03 +020023function _post_maas_cfg(){
24 local PROFILE=mirantis
25 /var/lib/maas/.maas_login.sh
26 # disable backports for maas enlist pkg repo
27 maas ${PROFILE} package-repository update 1 "disabled_pockets=backports"
28 maas ${PROFILE} package-repository update 1 "arches=amd64"
29 # Download ubuntu image from MAAS local mirror
30 if [[ "$LOCAL_REPOS" == "true" ]] ; then
31 maas ${PROFILE} boot-source-selections create 2 os="ubuntu" release="xenial" arches="amd64" subarches="*" labels="*"
32 echo "WARNING: Removing default MAAS stream:"
33 maas ${PROFILE} boot-source read 1
34 maas ${PROFILE} boot-source delete 1
35 maas ${PROFILE} boot-resources import
36 # TODO wait for finish,and stop import.
37 fi
38}
39
40### Body
Richard Felkl4c4829d2017-11-11 00:12:20 +010041echo "Configuring network interfaces"
Dmitry Stremkouskif50ea262017-12-05 19:35:40 +030042find /etc/network/interfaces.d/ -type f -delete
43kill $(pidof /sbin/dhclient) || /bin/true
Richard Felkl4c4829d2017-11-11 00:12:20 +010044envsubst < /root/interfaces > /etc/network/interfaces
Dmitry Stremkouskia94b5f32017-12-02 00:41:54 +030045ip a flush dev ens3
Dmitry Stremkouskib43c4ee2017-12-02 02:21:05 +030046rm -f /var/run/network/ifstate.ens3
47if [[ $(grep -E '^\ *gateway\ ' /etc/network/interfaces) ]]; then
48(ip r s | grep ^default) && ip r d default || /bin/true
49fi;
Dmitry Stremkouskia94b5f32017-12-02 00:41:54 +030050ifup ens3
Richard Felkl4c4829d2017-11-11 00:12:20 +010051
52echo "Preparing metadata model"
53mount /dev/cdrom /mnt/
Leontii Istomin68553f12018-02-21 18:10:12 +010054cp -rT /mnt/model/model /srv/salt/reclass
Richard Felkl4c4829d2017-11-11 00:12:20 +010055chown -R root:root /srv/salt/reclass/*
alexzd90608b2018-04-12 23:49:03 +020056chown -R root:root /srv/salt/reclass/.git* || true
57chmod -R 644 /srv/salt/reclass/classes/cluster/* || true
58chmod -R 644 /srv/salt/reclass/classes/system/* || true
Richard Felkl4c4829d2017-11-11 00:12:20 +010059
Richard Felkl4c4829d2017-11-11 00:12:20 +010060echo "Configuring salt"
61#service salt-master restart
62envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf
63service salt-minion restart
64while true; do
65 salt-key | grep "$SALT_MASTER_MINION_ID" && break
66 sleep 5
67done
68sleep 5
alexzd90608b2018-04-12 23:49:03 +020069for i in $(salt-key -l accepted | grep -v Accepted | grep -v "$SALT_MASTER_MINION_ID"); do
Richard Felkl4c4829d2017-11-11 00:12:20 +010070 salt-key -d $i -y
71done
72
73find /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'
74
Jiri Broulikcee20532018-01-08 13:30:15 +010075echo "updating git repos"
alexzd90608b2018-04-12 23:49:03 +020076if [[ "$PIPELINES_FROM_ISO" == "true" ]] ; then
Jiri Broulikcee20532018-01-08 13:30:15 +010077 cp -r /mnt/mk-pipelines/* /home/repo/mk/mk-pipelines/
78 cp -r /mnt/pipeline-library/* /home/repo/mcp-ci/pipeline-library/
alexzd90608b2018-04-12 23:49:03 +020079 umount /dev/cdrom || true
Jiri Broulikcee20532018-01-08 13:30:15 +010080 chown -R git:www-data /home/repo/mk/mk-pipelines/*
81 chown -R git:www-data /home/repo/mcp-ci/pipeline-library/*
82else
alexzd90608b2018-04-12 23:49:03 +020083 umount /dev/cdrom || true
84 git clone --mirror "${PIPELINE_REPO_URL}/mk-pipelines.git" /home/repo/mk/mk-pipelines/
85 git clone --mirror "${PIPELINE_REPO_URL}/pipeline-library.git" /home/repo/mcp-ci/pipeline-library/
Jiri Broulikcee20532018-01-08 13:30:15 +010086 chown -R git:www-data /home/repo/mk/mk-pipelines/*
87 chown -R git:www-data /home/repo/mcp-ci/pipeline-library/*
88fi
89
Richard Felkl98b45342018-04-06 13:30:28 +020090echo "installing formulas"
91curl -s $MCP_SALT_REPO_KEY | sudo apt-key add -
92echo $MCP_SALT_REPO > /etc/apt/sources.list.d/mcp_salt.list
93apt-get update
94apt-get install -y $FORMULAS
95rm -r /srv/salt/reclass/classes/service/*
Richard Felkl58026842018-04-10 11:17:01 +020096cd /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 +020097
Richard Felkl4c4829d2017-11-11 00:12:20 +010098salt-call saltutil.refresh_pillar
99salt-call saltutil.sync_all
alexzd90608b2018-04-12 23:49:03 +0200100if ! $(reclass -n ${SALT_MASTER_MINION_ID} > /dev/null ) ; then
101 echo "ERROR: Reclass render failed!"
102 exit 1
Jiri Broulik0173a272018-04-11 10:56:35 +0200103fi
104
alexzd90608b2018-04-12 23:49:03 +0200105salt-call state.sls linux.network,linux,openssh,salt
106salt-call state.sls salt
107# Sometimes, maas can stuck :(
108salt-call state.sls maas.cluster,maas.region || salt-call state.sls maas.cluster,maas.region
109salt-call state.sls reclass
Jiri Broulik1261ca32018-01-18 15:30:25 +0100110
alexzd90608b2018-04-12 23:49:03 +0200111_post_maas_cfg
112
113ssh-keyscan cfg01 > /var/lib/jenkins/.ssh/known_hosts || true
114
115pillar=$(salt-call pillar.data jenkins:client)
Jiri Broulike40813f2018-01-16 13:35:19 +0100116
117if [[ $pillar == *"job"* ]]; then
118 salt-call state.sls jenkins.client
119fi
Richard Felkl4c4829d2017-11-11 00:12:20 +0100120
Dmitry Stremkouskia94b5f32017-12-02 00:41:54 +0300121reboot