From 48d620dcb2c8937190ad213e868330ea956b272d Mon Sep 17 00:00:00 2001 From: Robin Schneider Date: Sat, 11 Feb 2017 12:15:22 +0100 Subject: [PATCH] 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 --- src/_ansible | 1 + src/_ansible-playbook | 1 + 2 files changed, 2 insertions(+) diff --git a/src/_ansible b/src/_ansible index 60864d4..e3a1d0c 100644 --- a/src/_ansible +++ b/src/_ansible @@ -62,6 +62,7 @@ __host_file_location () { [[ "$OSTYPE" == darwin* ]] && FALLBACK="/usr/local/etc/ansible/hosts" [[ "$OSTYPE" == linux* ]] && FALLBACK="/etc/ansible/hosts" HOST_FILE=${ANSIBLE_HOSTS:=${FALLBACK}} + [[ -f ${HOST_FILE} ]] || HOST_FILE="$PWD/ansible/inventory/hosts" [[ -f ${HOST_FILE} ]] || HOST_FILE=/dev/null echo ${HOST_FILE} diff --git a/src/_ansible-playbook b/src/_ansible-playbook index f0a85d0..95aa261 100644 --- a/src/_ansible-playbook +++ b/src/_ansible-playbook @@ -61,6 +61,7 @@ __host_file_location () { [[ "$OSTYPE" == darwin* ]] && FALLBACK="/usr/local/etc/ansible/hosts" [[ "$OSTYPE" == linux* ]] && FALLBACK="/etc/ansible/hosts" HOST_FILE=${ANSIBLE_HOSTS:=${FALLBACK}} + [[ -f ${HOST_FILE} ]] || HOST_FILE="$PWD/ansible/inventory/hosts" [[ -f ${HOST_FILE} ]] || HOST_FILE=/dev/null echo ${HOST_FILE}