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.

42 lines
852 B

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