Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 1 | #!/bin/bash -xe |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 2 | |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 3 | export SALT_MASTER_DEPLOY_IP=172.16.164.15 |
| 4 | export SALT_MASTER_MINION_ID=cfg01.deploy-name.local |
| 5 | export DEPLOY_NETWORK_GW=172.16.164.1 |
| 6 | export DEPLOY_NETWORK_NETMASK=255.255.255.192 |
| 7 | export DNS_SERVERS=8.8.8.8 |
Jiri Broulik | cee2053 | 2018-01-08 13:30:15 +0100 | [diff] [blame] | 8 | export http_proxy= |
| 9 | export https_proxy= |
| 10 | export PIPELINES_FROM_ISO=true |
| 11 | export PIPELINE_REPO_URL=https://github.com/Mirantis |
Richard Felkl | 98b4534 | 2018-04-06 13:30:28 +0200 | [diff] [blame] | 12 | export MCP_VERSION=stable |
| 13 | export MCP_SALT_REPO_KEY=http://apt.mirantis.com/public.gpg |
| 14 | export MCP_SALT_REPO_URL=http://apt.mirantis.com/xenial |
| 15 | export MCP_SALT_REPO="deb [arch=amd64] $MCP_SALT_REPO_URL $MCP_VERSION salt" |
| 16 | export FORMULAS="salt-formula-*" |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 17 | # Not avaible in 2018.3.1 and pre. |
| 18 | # TODO should be renamed to LOCAL_MAAS_STREAMS |
Jiri Broulik | 0173a27 | 2018-04-11 10:56:35 +0200 | [diff] [blame] | 19 | export LOCAL_REPOS=false |
Jiri Broulik | cee2053 | 2018-01-08 13:30:15 +0100 | [diff] [blame] | 20 | #for cloning from aptly image use port 8088 |
| 21 | #export PIPELINE_REPO_URL=http://172.16.47.182:8088 |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 22 | |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 23 | function _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 Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 41 | echo "Configuring network interfaces" |
Dmitry Stremkouski | f50ea26 | 2017-12-05 19:35:40 +0300 | [diff] [blame] | 42 | find /etc/network/interfaces.d/ -type f -delete |
| 43 | kill $(pidof /sbin/dhclient) || /bin/true |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 44 | envsubst < /root/interfaces > /etc/network/interfaces |
Dmitry Stremkouski | a94b5f3 | 2017-12-02 00:41:54 +0300 | [diff] [blame] | 45 | ip a flush dev ens3 |
Dmitry Stremkouski | b43c4ee | 2017-12-02 02:21:05 +0300 | [diff] [blame] | 46 | rm -f /var/run/network/ifstate.ens3 |
| 47 | if [[ $(grep -E '^\ *gateway\ ' /etc/network/interfaces) ]]; then |
| 48 | (ip r s | grep ^default) && ip r d default || /bin/true |
| 49 | fi; |
Dmitry Stremkouski | a94b5f3 | 2017-12-02 00:41:54 +0300 | [diff] [blame] | 50 | ifup ens3 |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 51 | |
| 52 | echo "Preparing metadata model" |
| 53 | mount /dev/cdrom /mnt/ |
Leontii Istomin | 68553f1 | 2018-02-21 18:10:12 +0100 | [diff] [blame] | 54 | cp -rT /mnt/model/model /srv/salt/reclass |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 55 | chown -R root:root /srv/salt/reclass/* |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 56 | chown -R root:root /srv/salt/reclass/.git* || true |
| 57 | chmod -R 644 /srv/salt/reclass/classes/cluster/* || true |
| 58 | chmod -R 644 /srv/salt/reclass/classes/system/* || true |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 59 | |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 60 | echo "Configuring salt" |
| 61 | #service salt-master restart |
| 62 | envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf |
| 63 | service salt-minion restart |
| 64 | while true; do |
| 65 | salt-key | grep "$SALT_MASTER_MINION_ID" && break |
| 66 | sleep 5 |
| 67 | done |
| 68 | sleep 5 |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 69 | for i in $(salt-key -l accepted | grep -v Accepted | grep -v "$SALT_MASTER_MINION_ID"); do |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 70 | salt-key -d $i -y |
| 71 | done |
| 72 | |
| 73 | 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' |
| 74 | |
Jiri Broulik | cee2053 | 2018-01-08 13:30:15 +0100 | [diff] [blame] | 75 | echo "updating git repos" |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 76 | if [[ "$PIPELINES_FROM_ISO" == "true" ]] ; then |
Jiri Broulik | cee2053 | 2018-01-08 13:30:15 +0100 | [diff] [blame] | 77 | cp -r /mnt/mk-pipelines/* /home/repo/mk/mk-pipelines/ |
| 78 | cp -r /mnt/pipeline-library/* /home/repo/mcp-ci/pipeline-library/ |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 79 | umount /dev/cdrom || true |
Jiri Broulik | cee2053 | 2018-01-08 13:30:15 +0100 | [diff] [blame] | 80 | chown -R git:www-data /home/repo/mk/mk-pipelines/* |
| 81 | chown -R git:www-data /home/repo/mcp-ci/pipeline-library/* |
| 82 | else |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 83 | 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 Broulik | cee2053 | 2018-01-08 13:30:15 +0100 | [diff] [blame] | 86 | chown -R git:www-data /home/repo/mk/mk-pipelines/* |
| 87 | chown -R git:www-data /home/repo/mcp-ci/pipeline-library/* |
| 88 | fi |
| 89 | |
Richard Felkl | 98b4534 | 2018-04-06 13:30:28 +0200 | [diff] [blame] | 90 | echo "installing formulas" |
| 91 | curl -s $MCP_SALT_REPO_KEY | sudo apt-key add - |
| 92 | echo $MCP_SALT_REPO > /etc/apt/sources.list.d/mcp_salt.list |
| 93 | apt-get update |
| 94 | apt-get install -y $FORMULAS |
| 95 | rm -r /srv/salt/reclass/classes/service/* |
Richard Felkl | 5802684 | 2018-04-10 11:17:01 +0200 | [diff] [blame] | 96 | 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] | 97 | |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 98 | salt-call saltutil.refresh_pillar |
| 99 | salt-call saltutil.sync_all |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 100 | if ! $(reclass -n ${SALT_MASTER_MINION_ID} > /dev/null ) ; then |
| 101 | echo "ERROR: Reclass render failed!" |
| 102 | exit 1 |
Jiri Broulik | 0173a27 | 2018-04-11 10:56:35 +0200 | [diff] [blame] | 103 | fi |
| 104 | |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 105 | salt-call state.sls linux.network,linux,openssh,salt |
| 106 | salt-call state.sls salt |
| 107 | # Sometimes, maas can stuck :( |
| 108 | salt-call state.sls maas.cluster,maas.region || salt-call state.sls maas.cluster,maas.region |
| 109 | salt-call state.sls reclass |
Jiri Broulik | 1261ca3 | 2018-01-18 15:30:25 +0100 | [diff] [blame] | 110 | |
alexz | d90608b | 2018-04-12 23:49:03 +0200 | [diff] [blame] | 111 | _post_maas_cfg |
| 112 | |
| 113 | ssh-keyscan cfg01 > /var/lib/jenkins/.ssh/known_hosts || true |
| 114 | |
| 115 | pillar=$(salt-call pillar.data jenkins:client) |
Jiri Broulik | e40813f | 2018-01-16 13:35:19 +0100 | [diff] [blame] | 116 | |
| 117 | if [[ $pillar == *"job"* ]]; then |
| 118 | salt-call state.sls jenkins.client |
| 119 | fi |
Richard Felkl | 4c4829d | 2017-11-11 00:12:20 +0100 | [diff] [blame] | 120 | |
Dmitry Stremkouski | a94b5f3 | 2017-12-02 00:41:54 +0300 | [diff] [blame] | 121 | reboot |