#!/bin/bash 
set -e
export ANSIBLE_HOST_KEY_CHECKING=False

source ./$NECTAR_ALLOCATION-openrc.sh

cd CICD

echo "[ansible_create_cluster_script] Prefixing the Stackname with CICD because heatcicdwrapper does he same"
python3 ../scripts/make_inventory.py static CICD$STACKNAME | tee ./files/inventory.$STACKNAME && chmod 755 ./files/inventory.$STACKNAME
grep -qv "I could not find any resouces tagged with project_name:" ./files/inventory.$STACKNAME   #fail if inventory file is empty
chmod 400 ../gc_key.pem
ansible -m ping -i files/inventory.$STACKNAME --key-file ../gc_key.pem all
ansible -i files/inventory.$STACKNAME --key-file ../gc_key.pem -a "sudo ls" all

#cd roles 
    #- "egrep -lRZ 'sudo: true' . | xargs -0 -l sed -i -e 's/sudo: true/become: true/g' "
#cd ..
ansible-playbook -i files/inventory.$STACKNAME --key-file ../gc_key.pem master_playbook.yml
sleep 15
echo uglyuglyfix
ansible -i files/inventory.$STACKNAME --key-file ../gc_key.pem -b -a "systemctl restart slurmdbd" ManagementNodes