#! /bin/bash -xe

#
# See https://docs.egi.eu/providers/notebooks/operations/
# (without terraform and ansible-inventory tools)
#

INGRESS_HOSTNAME='eosc.zcu.cz'

ip4=78.128.247.56
ip6=2001:718:ff05:205::56

# wait ping
while ! ping -c 1 "$ip4"; do sleep 5; done

# wait ssh
while ! ssh egi@"$ip4" -o ConnectTimeout=10 -o PreferredAuthentications=publickey -o StrictHostKeyChecking=no :; do sleep 10; done

# check ssh access
ansible -m command -a 'uname -a' allnodes

# wait cloud-init
ansible -m shell -a 'while ! test -f /var/lib/cloud/instance/boot-finished; do sleep 2; done' allnodes

# kubernetes
ansible-playbook playbooks/k8s.yaml

# image repository
ansible-playbook playbooks/repository-nexus.yaml

# wait for finish
while ansible -m command -a 'kubectl get pods --all-namespaces' master | tail -n +3 | grep -v ' Running '; do sleep 5; done
