blob: d4adbd772066e4ca15a5c881c555b03b472c1cc5 [file] [log] [blame]
#cloud-config
output:
all: '| tee -a /var/log/cloud-init-output.log /dev/tty0'
write_files:
- owner: root:root
path: /etc/cloud/mirror_environment
permissions: '0644'
content: |
[ -f /etc/cloud/mirror_environment_override ] && . /etc/cloud/mirror_environment_override
export SALT_MASTER_DEPLOY_IP=${SALT_MASTER_DEPLOY_IP:-"10.1.0.14"}
export APTLY_MINION_ID=${APTLY_MINION_ID:-"apt01.deploy-name.local"}
mirror_config:
- &mirror_config |
function docker_ca_wa(){
crt="/var/lib/docker/swarm/certificates/swarm-node.crt"
if openssl x509 -checkend 86400 -noout -in ${crt}; then
echo "WARNING: swarm CA not expired yet.Something other wrong with docker"
echo "WARNING: docker CA WA not applied"
exit 1
fi
echo 'WARNING: re-creating docker stack services!'
systemctl stop docker || true
rm -rf /var/lib/docker/swarm/*
systemctl restart docker
sleep 5
docker swarm init --advertise-addr 127.0.0.1
sleep 5
for c in docker aptly; do
pushd /etc/docker/compose/${c}/
retry=5
i=1
while [[ $i -lt $retry ]]; do
docker stack deploy --compose-file docker-compose.yml ${c};
ret=$?;
if [[ $ret -eq 0 ]]; then
echo 'Stack created'; break;
else
echo "Stack creation failed, retrying in 3 seconds.." >&2;
sleep 3;
i=$(( i + 1 ));
fi
if [[ $i -ge $retry ]]; then
echo "Stack creation failed!"; exit 1;
fi
done
popd
sleep 1
done
}
. /etc/cloud/mirror_environment
echo "Configuring salt"
rm -f /etc/salt/pki/minion/minion_master.pub
envsubst < /root/minion.conf > /etc/salt/minion.d/minion.conf
service salt-minion restart
# Check for failed docker-start.
# WA PROD-21676
if [[ ! $(docker stack ls) ]] ; then
docker_ca_wa
fi
# Set bootstrap-done flag for future
mkdir -p /var/log/mcp/
touch /var/log/mcp/.bootstrap_done
runcmd:
- [bash, -cex, *mirror_config]