You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.0 KiB

  1. #!/bin/bash
  2. SERVER=$1
  3. PLAYBOOK=$2
  4. SITE_NAME=$3
  5. while [[ "$#" -gt 0 ]]; do
  6. case $1 in
  7. -f|--force) force=1; shift ;;
  8. esac
  9. shift
  10. done
  11. usage() {
  12. echo "Usage: run-vps-playbook.sh server playbook [site_name]"
  13. echo "server - domain or ip address of the vps server"
  14. echo "site_name - site name"
  15. echo "playbook - playbook file"
  16. }
  17. if [[ -z "$SERVER" ]]; then
  18. echo "You must defined SERVER as first argument"
  19. usage
  20. exit 1
  21. fi
  22. if [[ -z "$PLAYBOOK" ]]; then
  23. echo "You must defined PLAYBOOK as third argument"
  24. usage
  25. exit 1
  26. fi
  27. COMMAND=$(cat <<EOF
  28. ansible-playbook -e "lxc_host=${SERVER}"
  29. EOF
  30. )
  31. if [[ -n "$SITE_NAME" ]]; then
  32. COMMAND="${COMMAND} -e initial_site_name=${SITE_NAME}"
  33. fi
  34. COMMAND="${COMMAND} ${PLAYBOOK}"
  35. if [[ -z "$force" ]]; then
  36. printf 'Launch ansible playbook:\n%s\n' "${COMMAND}"
  37. read -p "Are you sure? " -n 1 -r
  38. echo # (optional) move to a new line
  39. if [[ $REPLY =~ ^[Yy]$ ]]
  40. then
  41. /bin/bash -c "${COMMAND}"
  42. fi
  43. else
  44. /bin/bash -c "${COMMAND}"
  45. fi