From 14de12bcf9c5fdf29966212e4ad741538cf7844d Mon Sep 17 00:00:00 2001 From: songtingxu-okta Date: Mon, 3 Feb 2020 15:53:45 -0800 Subject: [PATCH] Revert "refactor lansible and print more info (#24)" (#25) This reverts commit 6e42b8265143b2f9a826011b6676cba6ff85bcf4. --- .travis.yml | 2 +- cmd/lansible | 16 ++++------------ lib/ansible.sh | 6 +++--- test/ci/run | 2 +- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6a752dc..cbc4ac2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,7 +39,7 @@ jobs: before_install: test/ci/before_install -install: skip +install: false script: test/ci/run diff --git a/cmd/lansible b/cmd/lansible index 0ae9ce6..3dbba1b 100755 --- a/cmd/lansible +++ b/cmd/lansible @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# Summary: Runs strap and ansible playbook/role(s) to ensure your machine is fully configured -# Usage: strap lansible [--role|--with-role ] [--playbook|--with-playbook ] +# Summary: Runs strap to ensure your machine is fully configured +# Usage: strap lansible set -Eeuo pipefail # https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ @@ -38,7 +38,6 @@ STRAP_QUIET_FLAG="-q" Q="$STRAP_QUIET_FLAG" STRAP_ISSUES_URL="https://github.com/ultimatedotfiles/strap/issues/new" -STRAP_LANSIBLE_DEFAULT_PLAYBOOK=".strap/ansible/playbooks/default/main.yml" function array_contains() { local -r arr="${1:-}" value="${2:-}" @@ -123,18 +122,11 @@ EOF done } -function argument_check() { - if ! [[ "$@" == *--role* || "$@" == *--with-role* || "$@" == *--playbook* || "$@" == *--with-playbook* ]] && ! [[ -z "$@" && -f "${STRAP_WORKING_DIR}/${STRAP_LANSIBLE_DEFAULT_PLAYBOOK}" ]]; then - strap::abort "Unknown options $@ for strap lansible or no default ansible playbook ${STRAP_LANSIBLE_DEFAULT_PLAYBOOK} is found under current working directory." - fi -} - function main() { # Trap any exit call: trap cleanup SIGINT SIGTERM EXIT - argument_check "$@" [[ "$STRAP_USER" == "root" && "$STRAP_ROOT_ALLOWED" != true ]] && strap::abort "Run 'strap lansible' as yourself, not root." if [[ "$STRAP_OS" == 'mac' ]] && ! groups | grep $Q admin; then strap::abort "Add $STRAP_USER to the admin group."; fi @@ -322,9 +314,9 @@ EOF elif [[ "$@" == *--playbook* ]] || [[ "$@" == *--with-playbook* ]]; then strap::bot "Run Ansible Playbook" strap::ansible::playbook::run "$@" - elif [[ -z "$@" ]] && [[ -f "${STRAP_WORKING_DIR}/${STRAP_LANSIBLE_DEFAULT_PLAYBOOK}" ]]; then + elif [[ -d "${STRAP_WORKING_DIR}/.strap/ansible/playbooks/default" ]]; then strap::bot "Run Ansible Playbook" - strap::ansible::playbook::run --with-playbook="${STRAP_WORKING_DIR}/${STRAP_LANSIBLE_DEFAULT_PLAYBOOK}" "$@" + strap::ansible::playbook::run --with-playbook="${STRAP_WORKING_DIR}/.strap/ansible/playbooks/default" "$@" fi # make config/state a little more secure, just in case: diff --git a/lib/ansible.sh b/lib/ansible.sh index 70fc9f2..aeccd0a 100644 --- a/lib/ansible.sh +++ b/lib/ansible.sh @@ -287,8 +287,8 @@ strap::ansible::playbook::run() { [[ "$1" == --*=* ]] && set -- "${1%%=*}" "${1#*=}" "${@:2}" # normalize `--foo=bar` into `--foo bar` case "$1" in --playbook|--with-playbook) - playbook_file="${2}" - [[ -f "${playbook_file}" ]] || strap::abort "strap lansible: ${playbook_file} doesn't exist!" + playbook_dir="${2:-${STRAP_WORKING_DIR}/.strap/ansible/playbooks/default}" + [[ -d "${playbook_dir}" ]] || strap::abort "strap lansible: $1 needs to be a directory" shift 2 ;; -i|--inventory|--inventory-file) @@ -316,7 +316,7 @@ strap::ansible::playbook::run() { set -- "${params[@]}" # reset positional arguments fi - playbook_dir="$(dirname $playbook_file)" + playbook_file="${playbook_dir}/main.yml" requirements_file="${playbook_dir}/meta/requirements.yml" [[ -f "${requirements_file}" ]] || requirements_file="${playbook_dir}/requirements.yml" diff --git a/test/ci/run b/test/ci/run index 5141e59..60128e3 100755 --- a/test/ci/run +++ b/test/ci/run @@ -36,6 +36,6 @@ function main() { pushd "${TRAVIS_BUILD_DIR}/test" > /dev/null STRAP_INTERACTIVE=false "${TRAVIS_BUILD_DIR}/bin/strap" lansible popd > /dev/null - STRAP_INTERACTIVE=false bin/strap lansible --playbook="${TRAVIS_BUILD_DIR}/test/.strap/ansible/playbooks/default/main.yml" + STRAP_INTERACTIVE=false bin/strap lansible --playbook="${TRAVIS_BUILD_DIR}/test/.strap/ansible/playbooks/default" } main