#!/usr/bin/env bash
mkdir -p /root/.ssh
cp ansible_pub_user.pem /root/.ssh
chmod 400 /root/.ssh/ansible_pub_user.pem
cat config >> /root/.ssh/config

#get OS distro
. /etc/os-release
OS=$NAME
VER=$VERSION_ID

echo "Installing Ansible & Git..."
if [[ $NAME =~ "Ubuntu" ]];
then
    apt-get update
    apt-add-repository ppa:ansible/ansible -y
    apt-get update
    apt-get install ansible -y
    apt-get install git -y
fi

if [[ $NAME =~ "Debian GNU/Linux" ]];
then
    apt-get update
    apt-get install dirmngr --install-recommends -y
    echo "deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main" >> /etc/apt/sources.list
    apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367
    apt-get update
    apt-get install ansible -y
    apt-get install git -y
fi



if [[ $NAME =~ "CentOS Linux" ]];
then
    yum install epel-release -y
    yum install ansible -y
    yum install python-pip -y
    pip install pywinrm
    yum install git -y
fi

git clone git@git.alphatech-computing.com:Ansible/playbooks/proxmox/pve.git
ansible-playbook pve/install-roles.yml
rm pve/group_vars/all.yml
cp pve-vars.yml pve/group_vars/all.yml
ansible-playbook pve/site.yml
