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.

69 lines
1.5 KiB

  1. #!/bin/bash
  2. SERVER=$1
  3. PLAYBOOK=$2
  4. SITE_NAME=$3
  5. DOMAIN_NAME=$4
  6. while [[ "$#" -gt 0 ]]; do
  7. case $1 in
  8. -f|--force) force=1; shift ;;
  9. esac
  10. shift
  11. done
  12. usage() {
  13. echo "Usage: run-vps-playbook.sh server playbook site_name domain_name"
  14. echo "server - domain or ip address of the vps server"
  15. echo "playbook - playbook file"
  16. echo "site_name - site name, e.g. intermetiz - that is a project name used for create home directory and www directory, and database dump base file name"
  17. echo "domain_name - domain name, e.g. intermetiz.ru"
  18. }
  19. if [[ -z "$SERVER" ]]; then
  20. echo "You must defined SERVER as first argument"
  21. usage
  22. exit 1
  23. fi
  24. if [[ -z "$PLAYBOOK" ]]; then
  25. echo "You must defined PLAYBOOK as second argument"
  26. usage
  27. exit 1
  28. fi
  29. if [[ ! -f "$PLAYBOOK" ]]; then
  30. echo "Playbook file is not exists: $PLAYBOOK"
  31. usage
  32. exit 1
  33. fi
  34. if [[ -z "$SITE_NAME" ]]; then
  35. echo "You must defined SITE_NAME as third argument"
  36. usage
  37. exit 1
  38. fi
  39. if [[ -z "$DOMAIN_NAME" ]]; then
  40. echo "You must defined DOMAIN_NAME as fourth argument"
  41. usage
  42. exit 1
  43. fi
  44. COMMAND=$(cat <<EOF
  45. ansible-playbook -e "lxc_host=${SERVER}" -e "initial_site_name=${SITE_NAME}" -e "domain_name=${DOMAIN_NAME}" -e runner=site
  46. EOF
  47. )
  48. COMMAND="${COMMAND} ${PLAYBOOK}"
  49. if [[ -z "$force" ]]; then
  50. printf 'Launch ansible playbook:\n%s\n' "${COMMAND}"
  51. read -p "Are you sure? " -n 1 -r
  52. echo # (optional) move to a new line
  53. if [[ $REPLY =~ ^[Yy]$ ]]
  54. then
  55. /bin/bash -c "${COMMAND}"
  56. fi
  57. else
  58. /bin/bash -c "${COMMAND}"
  59. fi