Support to find Ansible hosts file in DebOps style projects

In [DebOps](https://debops.org/), it is common to have the Ansible host
inventory in a projects directory below "$HOME". This allows to have multiple
and separate Ansible environments.  For such a setup, the host inventory can be
found at `$PWD/ansible/inventory/hosts` as Ansible is typically executed from
the root of the project.  This patch adds support for such a layout as
fallback.

Ref: https://docs.debops.org/en/latest/debops-playbooks/docs/guides/getting-started.html
This commit is contained in:
Robin Schneider 2017-02-11 12:15:22 +01:00
parent fb28eaf1d6
commit 48d620dcb2
No known key found for this signature in database
GPG Key ID: 489A4D5EC353C98A
2 changed files with 2 additions and 0 deletions

View File

@ -62,6 +62,7 @@ __host_file_location () {
[[ "$OSTYPE" == darwin* ]] && FALLBACK="/usr/local/etc/ansible/hosts" [[ "$OSTYPE" == darwin* ]] && FALLBACK="/usr/local/etc/ansible/hosts"
[[ "$OSTYPE" == linux* ]] && FALLBACK="/etc/ansible/hosts" [[ "$OSTYPE" == linux* ]] && FALLBACK="/etc/ansible/hosts"
HOST_FILE=${ANSIBLE_HOSTS:=${FALLBACK}} HOST_FILE=${ANSIBLE_HOSTS:=${FALLBACK}}
[[ -f ${HOST_FILE} ]] || HOST_FILE="$PWD/ansible/inventory/hosts"
[[ -f ${HOST_FILE} ]] || HOST_FILE=/dev/null [[ -f ${HOST_FILE} ]] || HOST_FILE=/dev/null
echo ${HOST_FILE} echo ${HOST_FILE}

View File

@ -61,6 +61,7 @@ __host_file_location () {
[[ "$OSTYPE" == darwin* ]] && FALLBACK="/usr/local/etc/ansible/hosts" [[ "$OSTYPE" == darwin* ]] && FALLBACK="/usr/local/etc/ansible/hosts"
[[ "$OSTYPE" == linux* ]] && FALLBACK="/etc/ansible/hosts" [[ "$OSTYPE" == linux* ]] && FALLBACK="/etc/ansible/hosts"
HOST_FILE=${ANSIBLE_HOSTS:=${FALLBACK}} HOST_FILE=${ANSIBLE_HOSTS:=${FALLBACK}}
[[ -f ${HOST_FILE} ]] || HOST_FILE="$PWD/ansible/inventory/hosts"
[[ -f ${HOST_FILE} ]] || HOST_FILE=/dev/null [[ -f ${HOST_FILE} ]] || HOST_FILE=/dev/null
echo ${HOST_FILE} echo ${HOST_FILE}