@ -1,10 +1,17 @@
#!/bin/bash
#!/bin/bash
SERVER = $1
SERVER = $1
SITE_NAME = $2
PLAYBOOK = $3
PLAYBOOK = $2
SITE_NAME = $3
while [ [ " $# " -gt 0 ] ] ; do
case $1 in
-f| --force) force = 1; shift ; ;
esac
shift
done
usage( ) {
usage( ) {
echo "Usage: run-vps-playbook.sh server site_name playbook"
echo "Usage: run-vps-playbook.sh server playbook [site_name] "
echo "server - domain or ip adress of the vps server"
echo "server - domain or ip adress of the vps server"
echo "site_name - site name"
echo "site_name - site name"
echo "playbook - playbook file"
echo "playbook - playbook file"
@ -16,27 +23,32 @@ if [[ -z "$SERVER" ]]; then
exit 1
exit 1
fi
fi
if [ [ -z " $SITE_NAME " ] ] ; then
echo "You must defined SITE_NAME as second argument"
usage
exit 1
fi
if [ [ -z " $PLAYBOOK " ] ] ; then
if [ [ -z " $PLAYBOOK " ] ] ; then
echo "You must defined PLAYBOOK as third argument"
echo "You must defined PLAYBOOK as third argument"
usage
usage
exit 1
exit 1
fi
fi
COMMAND = $( cat <<EOF
COMMAND = $( cat <<EOF
ansible-playbook -e " lxc_host= $SERVER " -e " site_name= $SITE_NAME " $PLAYBOOK
ansible-playbook -e " lxc_host= ${ SERVER } "
EOF
EOF
)
)
printf 'Launch ansible playbook:\n%s\n' " $COMMAND "
read -p "Are you sure? " -n 1 -r
echo # (optional) move to a new line
if [ [ $REPLY = ~ ^[ Yy] $ ] ]
then
/bin/bash -c " $COMMAND "
if [ [ -n " $SITE_NAME " ] ] ; then
COMMAND = " ${ COMMAND } -e initial_site_name= ${ SITE_NAME } "
fi
COMMAND = " ${ COMMAND } ${ PLAYBOOK } "
if [ [ -z " $force " ] ] ; then
printf 'Launch ansible playbook:\n%s\n' " ${ COMMAND } "
read -p "Are you sure? " -n 1 -r
echo # (optional) move to a new line
if [ [ $REPLY = ~ ^[ Yy] $ ] ]
then
/bin/bash -c " ${ COMMAND } "
fi
else
/bin/bash -c " ${ COMMAND } "
fi
fi