blob: caef676ab9668c8296584a8f30b00f3f4defb110 [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-*"
alexzcd1d47e2018-04-17 12:21:59 +020017# Not avaible in 2018.4 and pre.
Jiri Broulik0173a272018-04-11 10:56:35 +020018export LOCAL_REPOS=false
Jiri Broulikcee20532018-01-08 13:30:15 +010019#for cloning from aptly image use port 8088
20#export PIPELINE_REPO_URL=http://172.16.47.182:8088
Richard Felkl4c4829d2017-11-11 00:12:20 +010021
alexzcd1d47e2018-04-17 12:21:59 +020022function _apt_cfg(){
23 # TODO remove those function after 2018.4 release
24 echo "Acquire::CompressionTypes::Order gz;" >/etc/apt/apt.conf.d/99compression-workaround-salt
25 echo "Acquire::EnableSrvRecords false;" >/etc/apt/apt.conf.d/99enablesrvrecords-false
26 echo "Acquire::http::Pipeline-Depth 0;" > /etc/apt/apt.conf.d/99aws-s3-mirrors-workaround-salt
27 echo "APT::Install-Recommends false;" > /etc/apt/apt.conf.d/99dont_install_recommends-salt
28 echo "APT::Install-Suggests false;" > /etc/apt/apt.conf.d/99dont_install_suggests-salt
29 echo "Acquire::Languages none;" > /etc/apt/apt.conf.d/99dont_acquire_all_languages-salt
30 echo "APT::Periodic::Update-Package-Lists 0;" > /etc/apt/apt.conf.d/99dont_update_package_list-salt
31 echo "APT::Periodic::Download-Upgradeable-Packages 0;" > /etc/apt/apt.conf.d/99dont_update_download_upg_packages-salt
32 echo "APT::Periodic::Unattended-Upgrade 0;" > /etc/apt/apt.conf.d/99disable_unattended_upgrade-salt
33 echo "INFO: cleaning sources lists"
34 rm -rv /etc/apt/sources.list.d/* || true
35 echo > /etc/apt/sources.list || true
36}
37
alexzd90608b2018-04-12 23:49:03 +020038function _post_maas_cfg(){
39 local PROFILE=mirantis
alexzcd1d47e2018-04-17 12:21:59 +020040 # TODO: remove those check, and use only new version, adfter 2018.4 release
41 if [[ -f /var/lib/maas/.maas_login.sh ]]; then
42 /var/lib/maas/.maas_login.sh
43 else
44 echo "WARNING: Attempt to use old maas login schema.."
45 TOKEN=$(cat /var/lib/maas/.maas_credentials);
46 maas list | cut -d' ' -f1 | xargs -I{} maas logout {}
47 maas login $PROFILE http://127.0.0.1:5240/MAAS/api/2.0/ "${TOKEN}"
48 fi
alexzd90608b2018-04-12 23:49:03 +020049 # disable backports for maas enlist pkg repo
50 maas ${PROFILE} package-repository update 1 "disabled_pockets=backports"
51 maas ${PROFILE} package-repository update 1 "arches=amd64"
52 # Download ubuntu image from MAAS local mirror
53 if [[ "$LOCAL_REPOS" == "true" ]] ; then
54 maas ${PROFILE} boot-source-selections create 2 os="ubuntu" release="xenial" arches="amd64" subarches="*" labels="*"
55 echo "WARNING: Removing default MAAS stream:"
56 maas ${PROFILE} boot-source read 1
57 maas ${PROFILE} boot-source delete 1
58 maas ${PROFILE} boot-resources import
59 # TODO wait for finish,and stop import.
60 fi
61}
62
63### Body
Richard Felkl4c4829d2017-11-11 00:12:20 +010064echo "Configuring network interfaces"
Dmitry Stremkouskif50ea262017-12-05 19:35:40 +030065find /etc/network/interfaces.d/ -type f -delete
66kill $(pidof /sbin/dhclient) || /bin/true
Richard Felkl4c4829d2017-11-11 00:12:20 +010067envsubst < /root/interfaces > /etc/network/interfaces
Dmitry Stremkouskia94b5f32017-12-02 00:41:54 +030068ip a flush dev ens3
Dmitry Stremkouskib43c4ee2017-12-02 02:21:05 +030069rm -f /var/run/network/ifstate.ens3
70if [[ $(grep -E '^\ *gateway\ ' /etc/network/interfaces) ]]; then
71(ip r s | grep ^default) && ip r d default || /bin/true
72fi;
Dmitry Stremkouskia94b5f32017-12-02 00:41:54 +030073ifup ens3
Richard Felkl4c4829d2017-11-11 00:12:20 +010074
75echo "Preparing metadata model"
76mount /dev/cdrom /mnt/
Leontii Istomin68553f12018-02-21 18:10:12 +010077cp -rT /mnt/model/model /srv/salt/reclass
Richard Felkl4c4829d2017-11-11 00:12:20 +010078chown -R root:root /srv/salt/reclass/*
alexzd90608b2018-04-12 23:49:03 +020079chown -R root:root /srv/salt/reclass/.git* || true
80chmod -R 644 /srv/salt/reclass/classes/cluster/* || true
81chmod -R 644 /srv/salt/reclass/classes/system/* || true
Richard Felkl4c4829d2017-11-11 00:12:20 +010082
Richard Felkl4c4829d2017-11-11 00:12:20 +010083echo "Configuring salt"
84#service salt-master restart
85envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf
86service salt-minion restart
87while true; do
88 salt-key | grep "$SALT_MASTER_MINION_ID" && break
89 sleep 5
90done
91sleep 5
alexzd90608b2018-04-12 23:49:03 +020092for i in $(salt-key -l accepted | grep -v Accepted | grep -v "$SALT_MASTER_MINION_ID"); do
Richard Felkl4c4829d2017-11-11 00:12:20 +010093 salt-key -d $i -y
94done
95
96find /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'
97
Jiri Broulikcee20532018-01-08 13:30:15 +010098echo "updating git repos"
alexzd90608b2018-04-12 23:49:03 +020099if [[ "$PIPELINES_FROM_ISO" == "true" ]] ; then
Jiri Broulikcee20532018-01-08 13:30:15 +0100100 cp -r /mnt/mk-pipelines/* /home/repo/mk/mk-pipelines/
101 cp -r /mnt/pipeline-library/* /home/repo/mcp-ci/pipeline-library/
alexzd90608b2018-04-12 23:49:03 +0200102 umount /dev/cdrom || true
Jiri Broulikcee20532018-01-08 13:30:15 +0100103 chown -R git:www-data /home/repo/mk/mk-pipelines/*
104 chown -R git:www-data /home/repo/mcp-ci/pipeline-library/*
105else
alexzd90608b2018-04-12 23:49:03 +0200106 umount /dev/cdrom || true
107 git clone --mirror "${PIPELINE_REPO_URL}/mk-pipelines.git" /home/repo/mk/mk-pipelines/
108 git clone --mirror "${PIPELINE_REPO_URL}/pipeline-library.git" /home/repo/mcp-ci/pipeline-library/
Jiri Broulikcee20532018-01-08 13:30:15 +0100109 chown -R git:www-data /home/repo/mk/mk-pipelines/*
110 chown -R git:www-data /home/repo/mcp-ci/pipeline-library/*
111fi
112
Richard Felkl98b45342018-04-06 13:30:28 +0200113echo "installing formulas"
alexzcd1d47e2018-04-17 12:21:59 +0200114_apt_cfg
Richard Felkl98b45342018-04-06 13:30:28 +0200115curl -s $MCP_SALT_REPO_KEY | sudo apt-key add -
116echo $MCP_SALT_REPO > /etc/apt/sources.list.d/mcp_salt.list
117apt-get update
118apt-get install -y $FORMULAS
119rm -r /srv/salt/reclass/classes/service/*
Richard Felkl58026842018-04-10 11:17:01 +0200120cd /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 +0200121
Richard Felkl4c4829d2017-11-11 00:12:20 +0100122salt-call saltutil.refresh_pillar
123salt-call saltutil.sync_all
alexzd90608b2018-04-12 23:49:03 +0200124if ! $(reclass -n ${SALT_MASTER_MINION_ID} > /dev/null ) ; then
125 echo "ERROR: Reclass render failed!"
126 exit 1
Jiri Broulik0173a272018-04-11 10:56:35 +0200127fi
128
alexzd90608b2018-04-12 23:49:03 +0200129salt-call state.sls linux.network,linux,openssh,salt
130salt-call state.sls salt
131# Sometimes, maas can stuck :(
132salt-call state.sls maas.cluster,maas.region || salt-call state.sls maas.cluster,maas.region
133salt-call state.sls reclass
Jiri Broulik1261ca32018-01-18 15:30:25 +0100134
alexzd90608b2018-04-12 23:49:03 +0200135_post_maas_cfg
136
137ssh-keyscan cfg01 > /var/lib/jenkins/.ssh/known_hosts || true
138
139pillar=$(salt-call pillar.data jenkins:client)
Jiri Broulike40813f2018-01-16 13:35:19 +0100140
141if [[ $pillar == *"job"* ]]; then
142 salt-call state.sls jenkins.client
143fi
Richard Felkl4c4829d2017-11-11 00:12:20 +0100144
Dmitry Stremkouskia94b5f32017-12-02 00:41:54 +0300145reboot