#!/bin/bash

# This script is executed on the virtual machine during the Installation phase (need to be ran as root!).
# It is used to record a predefined VM-image of the appliance.
# Otherwise executed first during a cloud deployement in IFB-Biosphere

# Install Ansible
export DEBIAN_FRONTEND=noninteractive
APT_OPT=""
if [ $(lsb_release -is) = "Debian" ]; then
    apt-get install -y software-properties-common dirmngr
	if [ $(lsb_release -cs) = "stretch" ]; then apt-add-repository "deb http://deb.debian.org/debian stretch-backports main"; fi
	APT_OPT="-t $(lsb_release -cs)-backports --allow-unauthenticated"
    apt-get -y --allow-unauthenticated dist-upgrade
elif [ $(lsb_release -cs) != "focal" ]; then
    apt-add-repository -y ppa:ansible/ansible
fi
apt-get update
apt-get install $APT_OPT -y ansible

# Run app playbook
ansible-playbook -c local -i 127.0.0.1, -b -e 'ansible_python_interpreter=/usr/bin/python3' ubuntu-shellinabox.yaml





