diff --git a/src/_ansible b/src/_ansible index 5a10e3a..0440e3e 100644 --- a/src/_ansible +++ b/src/_ansible @@ -58,20 +58,10 @@ __host_file_location () { # 2. else check /etc/ansible/hosts or /usr/local/etc/... # (depending on platform) # - if [ -n "${ANSIBLE_HOSTS}" ]; then # use envvar - HOST_FILE=${ANSIBLE_HOSTS} - else - if [[ "$OSTYPE" == darwin* ]]; then - CANDIDATE="/usr/local/etc/ansible/hosts" - else - CANDIDATE="/etc/ansible/hosts" - fi - if [ -f "$CANDIDATE" ]; then - HOST_FILE=${CANDIDATE} - else - HOST_FILE=/dev/null - fi - fi + [[ "$OSTYPE" == darwin* ]] && FALLBACK="/usr/local/etc/ansible/hosts" + [[ "$OSTYPE" == linux* ]] && FALLBACK="/etc/ansible/hosts" + HOST_FILE=${ANSIBLE_HOSTS:=${FALLBACK}} + [[ -f ${HOST_FILE} ]] || HOST_FILE=/dev/null echo ${HOST_FILE} } diff --git a/src/_ansible-playbook b/src/_ansible-playbook index 4b641fc..bbeccc0 100644 --- a/src/_ansible-playbook +++ b/src/_ansible-playbook @@ -56,20 +56,11 @@ __host_file_location () { # 2. else check /etc/ansible/hosts or /usr/local/etc/... # (depending on platform) # - if [ -n "${ANSIBLE_HOSTS}" ]; then # use envvar - HOST_FILE=${ANSIBLE_HOSTS} - else - if [[ "$OSTYPE" == darwin* ]]; then - CANDIDATE="/usr/local/etc/ansible/hosts" - else - CANDIDATE="/etc/ansible/hosts" - fi - if [ -f "$CANDIDATE" ]; then - HOST_FILE=${CANDIDATE} - else - HOST_FILE=/dev/null - fi - fi + + [[ "$OSTYPE" == darwin* ]] && FALLBACK="/usr/local/etc/ansible/hosts" + [[ "$OSTYPE" == linux* ]] && FALLBACK="/etc/ansible/hosts" + HOST_FILE=${ANSIBLE_HOSTS:=${FALLBACK}} + [[ -f ${HOST_FILE} ]] || HOST_FILE=/dev/null echo ${HOST_FILE} }