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.

59 lines
1.2 KiB

  1. #!/bin/bash
  2. SERVER=$1
  3. LXC_HOST=$2
  4. PLAYBOOK=$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-lxc-playbook.sh server lxc_host playbook"
  13. echo "server - main proxmox server IP address and lxc_host that the name of lxc container"
  14. echo "lxc_host - name of lxc container"
  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 "$LXC_HOST" ]]; then
  23. echo "You must defined LXC_HOST as second argument"
  24. usage
  25. exit 1
  26. fi
  27. if [[ -z "$PLAYBOOK" ]]; then
  28. echo "You must defined PLAYBOOK as third argument"
  29. usage
  30. exit 1
  31. fi
  32. if [[ ! -f "$PLAYBOOK" ]]; then
  33. echo "Playbook file is not exists: $PLAYBOOK"
  34. usage
  35. exit 1
  36. fi
  37. COMMAND=$(cat <<EOF
  38. ansible-playbook -e "lxc_host=$LXC_HOST" -e runner=lxc --ssh-common-args="-o ProxyCommand='ssh -W %h:%p -q root@$SERVER'" $PLAYBOOK
  39. EOF
  40. )
  41. if [[ -z "$force" ]]; then
  42. printf 'Launch ansible playbook:\n%s\n' "$COMMAND"
  43. read -p "Are you sure? " -n 1 -r
  44. echo # (optional) move to a new line
  45. if [[ $REPLY =~ ^[Yy]$ ]]
  46. then
  47. /bin/bash -c "$COMMAND"
  48. fi
  49. else
  50. /bin/bash -c "$COMMAND"
  51. fi