Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 1 | #!/bin/bash -xe |
| 2 | export SALT_MASTER_DEPLOY_IP=172.16.164.15 |
| 3 | export SALT_MASTER_MINION_ID=cfg01.deploy-name.local |
| 4 | export DEPLOY_NETWORK_GW=172.16.164.1 |
| 5 | export DEPLOY_NETWORK_NETMASK=255.255.255.192 |
| 6 | export DNS_SERVERS=8.8.8.8 |
Jiri Broulik | cee2053 | 2018-01-08 13:30:15 +0100 | [diff] [blame] | 7 | export http_proxy= |
| 8 | export https_proxy= |
| 9 | export PIPELINES_FROM_ISO=true |
| 10 | export PIPELINE_REPO_URL=https://github.com/Mirantis |
Richard Felkl | 98b4534 | 2018-04-06 13:30:28 +0200 | [diff] [blame] | 11 | export MCP_VERSION=stable |
| 12 | export MCP_SALT_REPO_KEY=http://apt.mirantis.com/public.gpg |
| 13 | export MCP_SALT_REPO_URL=http://apt.mirantis.com/xenial |
| 14 | export MCP_SALT_REPO="deb [arch=amd64] $MCP_SALT_REPO_URL $MCP_VERSION salt" |
| 15 | export FORMULAS="salt-formula-*" |
Jiri Broulik | 0173a27 | 2018-04-11 10:56:35 +0200 | [diff] [blame^] | 16 | export LOCAL_REPOS=false |
Jiri Broulik | cee2053 | 2018-01-08 13:30:15 +0100 | [diff] [blame] | 17 | #for cloning from aptly image use port 8088 |
| 18 | #export PIPELINE_REPO_URL=http://172.16.47.182:8088 |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 19 | |
Jiri Broulik | fd84eeb | 2017-12-13 11:22:00 +0100 | [diff] [blame] | 20 | rm -vf /etc/update-motd.d/52-info |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 21 | echo "Configuring network interfaces" |
Dmitry Stremkouski | f50ea26 | 2017-12-05 19:35:40 +0300 | [diff] [blame] | 22 | find /etc/network/interfaces.d/ -type f -delete |
| 23 | kill $(pidof /sbin/dhclient) || /bin/true |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 24 | envsubst < /root/interfaces > /etc/network/interfaces |
Dmitry Stremkouski | a94b5f3 | 2017-12-02 00:41:54 +0300 | [diff] [blame] | 25 | ip a flush dev ens3 |
Dmitry Stremkouski | b43c4ee | 2017-12-02 02:21:05 +0300 | [diff] [blame] | 26 | rm -f /var/run/network/ifstate.ens3 |
| 27 | if [[ $(grep -E '^\ *gateway\ ' /etc/network/interfaces) ]]; then |
| 28 | (ip r s | grep ^default) && ip r d default || /bin/true |
| 29 | fi; |
Dmitry Stremkouski | a94b5f3 | 2017-12-02 00:41:54 +0300 | [diff] [blame] | 30 | ifup ens3 |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 31 | |
| 32 | echo "Preparing metadata model" |
| 33 | mount /dev/cdrom /mnt/ |
Leontii Istomin | 68553f1 | 2018-02-21 18:10:12 +0100 | [diff] [blame] | 34 | cp -rT /mnt/model/model /srv/salt/reclass |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 35 | chown -R root:root /srv/salt/reclass/* |
Jiri Broulik | ff52d68 | 2017-11-22 14:39:08 +0100 | [diff] [blame] | 36 | chown -R root:root /srv/salt/reclass/.git* |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 37 | chmod -R 644 /srv/salt/reclass/classes/cluster/* |
| 38 | chmod -R 644 /srv/salt/reclass/classes/system/* |
| 39 | |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 40 | echo "Configuring salt" |
| 41 | #service salt-master restart |
| 42 | envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf |
| 43 | service salt-minion restart |
| 44 | while true; do |
| 45 | salt-key | grep "$SALT_MASTER_MINION_ID" && break |
| 46 | sleep 5 |
| 47 | done |
| 48 | sleep 5 |
| 49 | for i in `salt-key -l accepted | grep -v Accepted | grep -v "$SALT_MASTER_MINION_ID"`; do |
| 50 | salt-key -d $i -y |
| 51 | done |
| 52 | |
| 53 | find /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 Broulik | cee2053 | 2018-01-08 13:30:15 +0100 | [diff] [blame] | 55 | echo "updating git repos" |
| 56 | if [ "$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 Broulik | 739bd35 | 2018-01-09 15:26:15 +0100 | [diff] [blame] | 59 | umount /dev/cdrom |
Jiri Broulik | cee2053 | 2018-01-08 13:30:15 +0100 | [diff] [blame] | 60 | chown -R git:www-data /home/repo/mk/mk-pipelines/* |
| 61 | chown -R git:www-data /home/repo/mcp-ci/pipeline-library/* |
| 62 | else |
Jiri Broulik | 739bd35 | 2018-01-09 15:26:15 +0100 | [diff] [blame] | 63 | umount /dev/cdrom |
Jiri Broulik | cee2053 | 2018-01-08 13:30:15 +0100 | [diff] [blame] | 64 | 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/* |
| 68 | fi |
| 69 | |
Richard Felkl | 98b4534 | 2018-04-06 13:30:28 +0200 | [diff] [blame] | 70 | echo "installing formulas" |
| 71 | curl -s $MCP_SALT_REPO_KEY | sudo apt-key add - |
| 72 | echo $MCP_SALT_REPO > /etc/apt/sources.list.d/mcp_salt.list |
| 73 | apt-get update |
| 74 | apt-get install -y $FORMULAS |
| 75 | rm -r /srv/salt/reclass/classes/service/* |
Richard Felkl | 5802684 | 2018-04-10 11:17:01 +0200 | [diff] [blame] | 76 | cd /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 Felkl | 98b4534 | 2018-04-06 13:30:28 +0200 | [diff] [blame] | 77 | |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 78 | salt-call saltutil.refresh_pillar |
| 79 | salt-call saltutil.sync_all |
| 80 | salt-call state.sls linux.network,linux,openssh,salt |
Ondrej Smola | 0c71bfd | 2018-03-16 12:07:38 +0100 | [diff] [blame] | 81 | salt-call state.sls salt |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 82 | salt-call state.sls maas.cluster,maas.region,reclass |
| 83 | |
Jiri Broulik | 0173a27 | 2018-04-11 10:56:35 +0200 | [diff] [blame^] | 84 | # Download ubuntu image from MAAS local mirror |
| 85 | if [ "$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 |
| 90 | fi |
| 91 | |
Jiri Broulik | 1261ca3 | 2018-01-18 15:30:25 +0100 | [diff] [blame] | 92 | ssh-keyscan cfg01 > /var/lib/jenkins/.ssh/known_hosts |
| 93 | |
Jiri Broulik | e40813f | 2018-01-16 13:35:19 +0100 | [diff] [blame] | 94 | pillar=`salt-call pillar.data jenkins:client` |
| 95 | |
| 96 | if [[ $pillar == *"job"* ]]; then |
| 97 | salt-call state.sls jenkins.client |
| 98 | fi |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 99 | |
Dmitry Stremkouski | a94b5f3 | 2017-12-02 00:41:54 +0300 | [diff] [blame] | 100 | reboot |