run 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/bash -e
  2. #
  3. # This file serves as the default command to the openshift-ansible image.
  4. # Runs a playbook with inventory as specified by environment variables.
  5. #
  6. # For more information see the documentation:
  7. # https://github.com/openshift/openshift-ansible/blob/master/README_CONTAINER_IMAGE.md
  8. # SOURCE and HOME DIRECTORY: /opt/app-root/src
  9. if [[ -z "${PLAYBOOK_FILE}" ]]; then
  10. echo
  11. echo "PLAYBOOK_FILE must be provided."
  12. exec /usr/local/bin/usage
  13. fi
  14. INVENTORY="$(mktemp)"
  15. if [[ -v INVENTORY_FILE ]]; then
  16. # Make a copy so that ALLOW_ANSIBLE_CONNECTION_LOCAL below
  17. # does not attempt to modify the original
  18. cp ${INVENTORY_FILE} ${INVENTORY}
  19. elif [[ -v INVENTORY_DIR ]]; then
  20. INVENTORY="$(mktemp -d)"
  21. cp -RL ${INVENTORY_DIR}/* ${INVENTORY}
  22. elif [[ -v INVENTORY_URL ]]; then
  23. curl -o ${INVENTORY} ${INVENTORY_URL}
  24. elif [[ -v DYNAMIC_SCRIPT_URL ]]; then
  25. curl -o ${INVENTORY} ${DYNAMIC_SCRIPT_URL}
  26. chmod 755 ${INVENTORY}
  27. elif [[ -v GENERATE_INVENTORY ]]; then
  28. # dynamically generate inventory file using bind-mounted info
  29. /usr/local/bin/generate ${INVENTORY}
  30. else
  31. echo
  32. echo "One of INVENTORY_FILE, INVENTORY_DIR, INVENTORY_URL, GENERATE_INVENTORY, or DYNAMIC_SCRIPT_URL must be provided."
  33. exec /usr/local/bin/usage
  34. fi
  35. INVENTORY_ARG="-i ${INVENTORY}"
  36. if [[ "$ALLOW_ANSIBLE_CONNECTION_LOCAL" = false ]]; then
  37. sed -i s/ansible_connection=local// ${INVENTORY}
  38. fi
  39. if [[ -v VAULT_PASS ]]; then
  40. VAULT_PASS_FILE="$(mktemp)"
  41. echo ${VAULT_PASS} > ${VAULT_PASS_FILE}
  42. VAULT_PASS_ARG="--vault-password-file ${VAULT_PASS_FILE}"
  43. fi
  44. cd ${WORK_DIR}
  45. exec ansible-playbook ${INVENTORY_ARG} ${VAULT_PASS_ARG} ${OPTS} ${PLAYBOOK_FILE}