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.

53 lines
1.0 KiB

  1. #!/bin/bash
  2. SERVER=$1
  3. PLAYBOOK=$2
  4. USER=$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 [user]"
  13. echo "server - domain or ip address of the vps server"
  14. echo "playbook - playbook file"
  15. echo "[user] - if choose the use it, otherwise used root"
  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 second argument"
  24. usage
  25. exit 1
  26. fi
  27. if [[ -z "$USER" ]]; then
  28. USER=root
  29. fi
  30. COMMAND=$(cat <<EOF
  31. ansible-playbook -e "lxc_host=${SERVER}" -e "runner=normal" -e "ansible_user=${USER}"
  32. EOF
  33. )
  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