terser hostfile fallback mechanism

This commit is contained in:
Romain Bossart 2015-03-04 08:04:12 +01:00
parent 5903ef0e7b
commit 3bfd530fda
2 changed files with 9 additions and 28 deletions

View File

@ -58,20 +58,10 @@ __host_file_location () {
# 2. else check /etc/ansible/hosts or /usr/local/etc/... # 2. else check /etc/ansible/hosts or /usr/local/etc/...
# (depending on platform) # (depending on platform)
# #
if [ -n "${ANSIBLE_HOSTS}" ]; then # use envvar [[ "$OSTYPE" == darwin* ]] && FALLBACK="/usr/local/etc/ansible/hosts"
HOST_FILE=${ANSIBLE_HOSTS} [[ "$OSTYPE" == linux* ]] && FALLBACK="/etc/ansible/hosts"
else HOST_FILE=${ANSIBLE_HOSTS:=${FALLBACK}}
if [[ "$OSTYPE" == darwin* ]]; then [[ -f ${HOST_FILE} ]] || HOST_FILE=/dev/null
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
echo ${HOST_FILE} echo ${HOST_FILE}
} }

View File

@ -56,20 +56,11 @@ __host_file_location () {
# 2. else check /etc/ansible/hosts or /usr/local/etc/... # 2. else check /etc/ansible/hosts or /usr/local/etc/...
# (depending on platform) # (depending on platform)
# #
if [ -n "${ANSIBLE_HOSTS}" ]; then # use envvar
HOST_FILE=${ANSIBLE_HOSTS} [[ "$OSTYPE" == darwin* ]] && FALLBACK="/usr/local/etc/ansible/hosts"
else [[ "$OSTYPE" == linux* ]] && FALLBACK="/etc/ansible/hosts"
if [[ "$OSTYPE" == darwin* ]]; then HOST_FILE=${ANSIBLE_HOSTS:=${FALLBACK}}
CANDIDATE="/usr/local/etc/ansible/hosts" [[ -f ${HOST_FILE} ]] || HOST_FILE=/dev/null
else
CANDIDATE="/etc/ansible/hosts"
fi
if [ -f "$CANDIDATE" ]; then
HOST_FILE=${CANDIDATE}
else
HOST_FILE=/dev/null
fi
fi
echo ${HOST_FILE} echo ${HOST_FILE}
} }