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.

48 lines
1.0 KiB

  1. #!/bin/bash
  2. SERVER=$1
  3. LXC_HOST=$2
  4. PLAYBOOK=$3
  5. usage() {
  6. echo "Usage: run-playbook.sh server lxc_host playbook"
  7. echo "server - main proxmox server IP address and lxc_host that the name of lxc container"
  8. echo "lxc_host - name of lxc container"
  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 "$LXC_HOST" ]]; then
  17. echo "You must defined LXC_HOST 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. if [[ ! -f "$PLAYBOOK" ]]; then
  27. echo "Playbook file is not exists: $PLAYBOOK"
  28. usage
  29. exit 1
  30. fi
  31. COMMAND=$(cat <<EOF
  32. ansible-playbook -e "lxc_host=$LXC_HOST" --ssh-common-args="-o ProxyCommand='ssh -W %h:%p root@$SERVER'" $PLAYBOOK
  33. EOF
  34. )
  35. printf 'Launch ansible playbook:\n%s\n' "$COMMAND"
  36. read -p "Are you sure? " -n 1 -r
  37. echo # (optional) move to a new line
  38. if [[ $REPLY =~ ^[Yy]$ ]]
  39. then
  40. /bin/bash -c "$COMMAND"
  41. fi