blob: d4adbd772066e4ca15a5c881c555b03b472c1cc5 [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"}
Dennis Dmitriev8fa33f92018-10-10 01:13:48 +030011 export APTLY_MINION_ID=${APTLY_MINION_ID:-"apt01.deploy-name.local"}
azvyagintsev829bfd82018-12-19 12:58:17 +020012
Ivan Berezovskiy1d48e482018-09-21 19:08:31 +040013mirror_config:
14- &mirror_config |
15 function docker_ca_wa(){
16 crt="/var/lib/docker/swarm/certificates/swarm-node.crt"
Denis Egorenko3535d2a2020-02-12 15:20:46 +040017 if openssl x509 -checkend 86400 -noout -in ${crt}; then
azvyagintsev829bfd82018-12-19 12:58:17 +020018 echo "WARNING: swarm CA not expired yet.Something other wrong with docker"
Ivan Berezovskiy1d48e482018-09-21 19:08:31 +040019 echo "WARNING: docker CA WA not applied"
20 exit 1
21 fi
22 echo 'WARNING: re-creating docker stack services!'
23
24 systemctl stop docker || true
25 rm -rf /var/lib/docker/swarm/*
26 systemctl restart docker
27 sleep 5
28 docker swarm init --advertise-addr 127.0.0.1
29 sleep 5
30 for c in docker aptly; do
31 pushd /etc/docker/compose/${c}/
32 retry=5
33 i=1
34 while [[ $i -lt $retry ]]; do
35 docker stack deploy --compose-file docker-compose.yml ${c};
36 ret=$?;
37 if [[ $ret -eq 0 ]]; then
38 echo 'Stack created'; break;
39 else
40 echo "Stack creation failed, retrying in 3 seconds.." >&2;
41 sleep 3;
42 i=$(( i + 1 ));
43 fi
44 if [[ $i -ge $retry ]]; then
45 echo "Stack creation failed!"; exit 1;
46 fi
47 done
48 popd
49 sleep 1
50 done
51 }
52
53 . /etc/cloud/mirror_environment
54
Ivan Berezovskiy1d48e482018-09-21 19:08:31 +040055 echo "Configuring salt"
56 rm -f /etc/salt/pki/minion/minion_master.pub
57 envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf
58 service salt-minion restart
59
60 # Check for failed docker-start.
61 # WA PROD-21676
62 if [[ ! $(docker stack ls) ]] ; then
63 docker_ca_wa
64 fi
65
66 # Set bootstrap-done flag for future
67 mkdir -p /var/log/mcp/
68 touch /var/log/mcp/.bootstrap_done
69runcmd:
70 - [bash, -cex, *mirror_config]