Repos with recipes to deploy some infrastructure services
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

59 lignes
2.0 KiB

  1. #!/usr/bin/env bash
  2. # ENV Vars:
  3. # VAGRANT_MODE - [0,1]
  4. # - to be used with bovine-inventory's vagrant mode
  5. # ANSIBLE_RUN_MODE - ["playbook","ad-hoc"]
  6. # - specify which mode to run ansible in
  7. # ANSIBLE_PLAYBOOK_FILE - defaults to "infra.yml"
  8. # - specify playbook to pass to ansible-playbook
  9. # - NB: only used when run mode is "playbook"
  10. # ANSIBLE_BASE_ARA - ["0","1"]
  11. # - a bash STRING (not numeral) to enable ARA
  12. # VAULT_PASSWORD_FILE -
  13. export ANSIBLE_RUN_MODE="${ANSIBLE_RUN_MODE:-playbook}"
  14. export ANSIBLE_PLAYBOOK_FILE="${ANSIBLE_PLAYBOOK_FILE:-infra.yml}"
  15. export VAULT_PASSWORD_FILE="${VAULT_PASSWORD_FILE:-${HOME}/.ssh/creds/vault_password.txt}"
  16. export VAGRANT_MODE="${VAGRANT_MODE:-0}"
  17. run_ansible() {
  18. INOPTS=( "$@" )
  19. VAULTOPTS=""
  20. # Plaintext vault decryption key, not checked into SCM
  21. if [ -f "${VAULT_PASSWORD_FILE}" ]; then
  22. VAULTOPTS="--vault-password-file=${VAULT_PASSWORD_FILE}"
  23. if [ ${ANSIBLE_RUN_MODE} == 'playbook' ]; then
  24. time ansible-playbook --diff ${VAULTOPTS} "${ANSIBLE_PLAYBOOK_FILE}" "${INOPTS[@]}"
  25. return $?
  26. elif [ ${ANSIBLE_RUN_MODE} == 'ad-hoc' ]; then
  27. time ansible --diff ${VAULTOPTS} "${INOPTS[@]}"
  28. return $?
  29. fi
  30. else
  31. if [ "${ANSIBLE_RUN_MODE}" == 'playbook' ]; then
  32. echo "Vault password file unreachable. Skip steps require vault."
  33. VAULTOPTS="--skip-tags=requires_vault"
  34. #echo "ansible-playbook --diff $VAULTOPTS ${INOPTS[@]} ${ANSIBLE_PLAYBOOK_FILE}" && \
  35. time ansible-playbook --diff ${VAULTOPTS} "${ANSIBLE_PLAYBOOK_FILE}" "${INOPTS[@]}"
  36. return $?
  37. elif [ "${ANSIBLE_RUN_MODE}" == 'ad-hoc' ]; then
  38. #echo "ansible --diff $VAULTOPTS ${INOPTS[@]}" && \
  39. time ansible --diff ${VAULTOPTS} "${INOPTS[@]}"
  40. return $?
  41. else
  42. echo "Invalid run mode: ${ANSIBLE_RUN_MODE}"
  43. exit 15
  44. fi
  45. fi
  46. }
  47. if [ "${VAGRANT_MODE}" -eq 1 ]; then
  48. export ANSIBLE_SSH_ARGS="-o UserKnownHostsFile=/dev/null"
  49. export ANSIBLE_HOST_KEY_CHECKING=false
  50. fi
  51. run_ansible "$@"
  52. retcode=$?
  53. exit $retcode