#!/bin/bash # Set environment variables export ANSIBLE_CONFIG="./ansible.cfg" options="" target="$1" ssh_key="$HOME/.ssh/id_rsa" if [ -z "$target" ]; then echo "No target specified. Please specify an inventory or 'bootstrap' !" exit 1 fi if [ "$target" == "bootstrap" -o "$target" == "bootstrap-minimal" ]; then if [ -z "$2" ]; then echo "Please specify the target host !" exit 1 fi host="$2" echo "Starting $target..." echo echo -n "Please enter the initial root password: " read -s password echo echo echo "Connecting to $host to register the SSH Host Key !" sshpass -p "$password" ssh -i $ssh_key -o StrictHostKeyChecking=no "root@$host" /bin/true auth="" if [ -n "$password" ]; then auth="ansible_ssh_pass=$password" else auth="ansible_ssh_private_key_file=$ssh_key" fi echo -e "[$target]\n$2 ansible_ssh_user=root $auth\n" > ./hosts-$target else shift options="$@" fi if [ ! -f "./hosts-$target" ]; then echo "Invalid target '$target' !" exit 1 fi ansible-playbook -i ./hosts-$target $options site.yml rm -f hosts-bootstrap hosts-bootstrap-minimal # temporary file