blob: 55972b0509c4bfd5c1a9c6fc4ba2bd27e5447bbd [file] [log] [blame]
Ivan Berezovskiy1d48e482018-09-21 19:08:31 +04001#cloud-config
2output:
3 all: '| tee -a /var/log/cloud-init-output.log /dev/tty0'
4write_files:
5- owner: root:root
6 path: /etc/cloud/mirror_environment
7 permissions: '0644'
8 content: |
Dennis Dmitriev8fa33f92018-10-10 01:13:48 +03009 [ -f /etc/cloud/mirror_environment_override ] && . /etc/cloud/mirror_environment_override
10 export SALT_MASTER_DEPLOY_IP=${SALT_MASTER_DEPLOY_IP:-"10.1.0.14"}
11 export APTLY_DEPLOY_IP=${APTLY_DEPLOY_IP:-"10.1.0.14"}
12 export APTLY_DEPLOY_NETMASK=${APTLY_DEPLOY_NETMASK:-"255.255.0.0"}
13 export APTLY_MINION_ID=${APTLY_MINION_ID:-"apt01.deploy-name.local"}
azvyagintsev829bfd82018-12-19 12:58:17 +020014
Ivan Berezovskiy1d48e482018-09-21 19:08:31 +040015mirror_config:
16- &mirror_config |
17 function docker_ca_wa(){
18 crt="/var/lib/docker/swarm/certificates/swarm-node.crt"
19 if ! $(openssl x509 -checkend 86400 -noout -in ${crt}); then
azvyagintsev829bfd82018-12-19 12:58:17 +020020 echo "WARNING: swarm CA not expired yet.Something other wrong with docker"
Ivan Berezovskiy1d48e482018-09-21 19:08:31 +040021 echo "WARNING: docker CA WA not applied"
22 exit 1
23 fi
24 echo 'WARNING: re-creating docker stack services!'
25
26 systemctl stop docker || true
27 rm -rf /var/lib/docker/swarm/*
28 systemctl restart docker
29 sleep 5
30 docker swarm init --advertise-addr 127.0.0.1
31 sleep 5
32 for c in docker aptly; do
33 pushd /etc/docker/compose/${c}/
34 retry=5
35 i=1
36 while [[ $i -lt $retry ]]; do
37 docker stack deploy --compose-file docker-compose.yml ${c};
38 ret=$?;
39 if [[ $ret -eq 0 ]]; then
40 echo 'Stack created'; break;
41 else
42 echo "Stack creation failed, retrying in 3 seconds.." >&2;
43 sleep 3;
44 i=$(( i + 1 ));
45 fi
46 if [[ $i -ge $retry ]]; then
47 echo "Stack creation failed!"; exit 1;
48 fi
49 done
50 popd
51 sleep 1
52 done
53 }
54
55 . /etc/cloud/mirror_environment
56
57 echo "Configuring network interfaces"
58 find /etc/network/interfaces.d/ -type f -delete
59 kill $(pidof /sbin/dhclient) || /bin/true
60 envsubst < /root/interfaces > /etc/network/interfaces
61 ip a flush dev ens3
62 rm -f /var/run/network/ifstate.ens3
63 if [[ $(grep -E '^\ *gateway\ ' /etc/network/interfaces) ]]; then
64 (ip r s | grep ^default) && ip r d default || /bin/true
65 fi;
66 ifup ens3
67
68 echo "Configuring salt"
69 rm -f /etc/salt/pki/minion/minion_master.pub
70 envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf
71 service salt-minion restart
72
73 # Check for failed docker-start.
74 # WA PROD-21676
75 if [[ ! $(docker stack ls) ]] ; then
76 docker_ca_wa
77 fi
78
79 # Set bootstrap-done flag for future
80 mkdir -p /var/log/mcp/
81 touch /var/log/mcp/.bootstrap_done
82runcmd:
83 - [bash, -cex, *mirror_config]