blob: 485d1dfff53151eba14d475eba802b79a61b33cd [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.
Pavel Cizinsky1abc0862018-05-30 14:14:33 +020060 else
61 maas ${PROFILE} boot-source-selections create 1 os="ubuntu" release="xenial" arches="amd64" subarches="*" labels="*"
62 maas ${PROFILE} boot-resources import
alexzd90608b2018-04-12 23:49:03 +020063 fi
64}
65
66### Body
Richard Felkl4c4829d2017-11-11 00:12:20 +010067echo "Configuring network interfaces"
Dmitry Stremkouskif50ea262017-12-05 19:35:40 +030068find /etc/network/interfaces.d/ -type f -delete
69kill $(pidof /sbin/dhclient) || /bin/true
Richard Felkl4c4829d2017-11-11 00:12:20 +010070envsubst < /root/interfaces > /etc/network/interfaces
Dmitry Stremkouskia94b5f32017-12-02 00:41:54 +030071ip a flush dev ens3
Dmitry Stremkouskib43c4ee2017-12-02 02:21:05 +030072rm -f /var/run/network/ifstate.ens3
73if [[ $(grep -E '^\ *gateway\ ' /etc/network/interfaces) ]]; then
74(ip r s | grep ^default) && ip r d default || /bin/true
75fi;
Dmitry Stremkouskia94b5f32017-12-02 00:41:54 +030076ifup ens3
Richard Felkl4c4829d2017-11-11 00:12:20 +010077
78echo "Preparing metadata model"
79mount /dev/cdrom /mnt/
Leontii Istomin68553f12018-02-21 18:10:12 +010080cp -rT /mnt/model/model /srv/salt/reclass
Richard Felkl4c4829d2017-11-11 00:12:20 +010081chown -R root:root /srv/salt/reclass/*
alexzd90608b2018-04-12 23:49:03 +020082chown -R root:root /srv/salt/reclass/.git* || true
83chmod -R 644 /srv/salt/reclass/classes/cluster/* || true
84chmod -R 644 /srv/salt/reclass/classes/system/* || true
Richard Felkl4c4829d2017-11-11 00:12:20 +010085
Richard Felkl4c4829d2017-11-11 00:12:20 +010086echo "Configuring salt"
87#service salt-master restart
88envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf
89service salt-minion restart
90while true; do
91 salt-key | grep "$SALT_MASTER_MINION_ID" && break
92 sleep 5
93done
94sleep 5
alexzd90608b2018-04-12 23:49:03 +020095for i in $(salt-key -l accepted | grep -v Accepted | grep -v "$SALT_MASTER_MINION_ID"); do
Richard Felkl4c4829d2017-11-11 00:12:20 +010096 salt-key -d $i -y
97done
98
99find /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'
100
Jiri Broulikcee20532018-01-08 13:30:15 +0100101echo "updating git repos"
alexzd90608b2018-04-12 23:49:03 +0200102if [[ "$PIPELINES_FROM_ISO" == "true" ]] ; then
Jiri Broulikcee20532018-01-08 13:30:15 +0100103 cp -r /mnt/mk-pipelines/* /home/repo/mk/mk-pipelines/
104 cp -r /mnt/pipeline-library/* /home/repo/mcp-ci/pipeline-library/
alexzd90608b2018-04-12 23:49:03 +0200105 umount /dev/cdrom || true
Jiri Broulikcee20532018-01-08 13:30:15 +0100106 chown -R git:www-data /home/repo/mk/mk-pipelines/*
107 chown -R git:www-data /home/repo/mcp-ci/pipeline-library/*
108else
alexzd90608b2018-04-12 23:49:03 +0200109 umount /dev/cdrom || true
110 git clone --mirror "${PIPELINE_REPO_URL}/mk-pipelines.git" /home/repo/mk/mk-pipelines/
111 git clone --mirror "${PIPELINE_REPO_URL}/pipeline-library.git" /home/repo/mcp-ci/pipeline-library/
Jiri Broulikcee20532018-01-08 13:30:15 +0100112 chown -R git:www-data /home/repo/mk/mk-pipelines/*
113 chown -R git:www-data /home/repo/mcp-ci/pipeline-library/*
114fi
115
Richard Felkl98b45342018-04-06 13:30:28 +0200116echo "installing formulas"
alexzcd1d47e2018-04-17 12:21:59 +0200117_apt_cfg
Richard Felkl98b45342018-04-06 13:30:28 +0200118curl -s $MCP_SALT_REPO_KEY | sudo apt-key add -
119echo $MCP_SALT_REPO > /etc/apt/sources.list.d/mcp_salt.list
120apt-get update
121apt-get install -y $FORMULAS
Jiri Broulik727978e2018-04-17 12:56:02 +0200122rm -rf /srv/salt/reclass/classes/service/*
Richard Felkl58026842018-04-10 11:17:01 +0200123cd /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 +0200124
Richard Felkl4c4829d2017-11-11 00:12:20 +0100125salt-call saltutil.refresh_pillar
126salt-call saltutil.sync_all
alexzd90608b2018-04-12 23:49:03 +0200127if ! $(reclass -n ${SALT_MASTER_MINION_ID} > /dev/null ) ; then
128 echo "ERROR: Reclass render failed!"
129 exit 1
Jiri Broulik0173a272018-04-11 10:56:35 +0200130fi
131
alexzd90608b2018-04-12 23:49:03 +0200132salt-call state.sls linux.network,linux,openssh,salt
Jiri Broulik6b7ca672018-04-19 13:16:32 +0200133salt-call -t5 pkg.install salt-master,salt-minion
134sleep 5
alexzd90608b2018-04-12 23:49:03 +0200135salt-call state.sls salt
136# Sometimes, maas can stuck :(
137salt-call state.sls maas.cluster,maas.region || salt-call state.sls maas.cluster,maas.region
138salt-call state.sls reclass
Jiri Broulik1261ca32018-01-18 15:30:25 +0100139
alexzd90608b2018-04-12 23:49:03 +0200140_post_maas_cfg
141
142ssh-keyscan cfg01 > /var/lib/jenkins/.ssh/known_hosts || true
143
144pillar=$(salt-call pillar.data jenkins:client)
Jiri Broulike40813f2018-01-16 13:35:19 +0100145
146if [[ $pillar == *"job"* ]]; then
147 salt-call state.sls jenkins.client
148fi
Richard Felkl4c4829d2017-11-11 00:12:20 +0100149
Dmitry Stremkouskia94b5f32017-12-02 00:41:54 +0300150reboot