#!/bin/bash -

. /etc/os-release

yum -y update
if grep "Red Hat" /etc/redhat-release &>/dev/null
then
	subscription-manager repos --enable ansible-2.8-for-rhel-8-x86_64-rpms
else
	yum -y install epel-release
fi
yum -y install ansible

ansible-galaxy install --force xe0nic.ansible_kodo_cloud_server
ansible-galaxy install --force xe0nic.ansible_kodo_cloud_agent

mkdir -p kodo
cd kodo

repo=${KODO_REPO:-"http://repo.storware.eu/kodo-cloud/current/el${VERSION_ID}"}
vdo_physical_device=${VDO_PHYSICAL_DEVICE:-""}

cat << EOF > hosts
[all:vars] 
ansible_user=root
ansible_connection=local
kodo_repo=$repo
vdo_physical_device=$vdo_physical_device

[server]
localhost 

[agents]
localhost agent_name=voyager
EOF

cat << EOF > site.yml
---

- hosts: server
  roles:
  - xe0nic.ansible_kodo_cloud_server

- hosts: agents
  roles:
  - xe0nic.ansible_kodo_cloud_agent
EOF

ansible-playbook -i hosts site.yml

echo DONE! Try to log into your Kodo Cloud Server console now.
