From 7bad79cdb13cfc4532a18d47974551a2b70f4039 Mon Sep 17 00:00:00 2001 From: Ferry Boender Date: Mon, 13 Nov 2017 22:15:23 +0100 Subject: [PATCH] Don't strip last part of inventory_path if it's already a dir. --- src/ansiblecmdb/ansible.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/ansiblecmdb/ansible.py b/src/ansiblecmdb/ansible.py index 488df75..dab4293 100644 --- a/src/ansiblecmdb/ansible.py +++ b/src/ansiblecmdb/ansible.py @@ -138,7 +138,13 @@ def _parse_hostvar_dir(self, inventory_path): """ Parse host_vars dir, if it exists. """ - path = os.path.join(os.path.dirname(inventory_path), 'host_vars') + # inventory_path could point to a `hosts` file, or to a dir. So we + # construct the location to the `host_vars` differently. + if os.path.isdir(inventory_path): + path = os.path.join(inventory_path, 'host_vars') + else: + path = os.path.join(os.path.dirname(inventory_path, 'host_vars')) + self.log.debug("Parsing host vars (dir): {0}".format(path)) if not os.path.exists(path): self.log.warning("No such dir {0}".format(path)) @@ -193,7 +199,13 @@ def _parse_groupvar_dir(self, inventory_path): """ Parse group_vars dir, if it exists. Encrypted vault files are skipped. """ - path = os.path.join(os.path.dirname(inventory_path), 'group_vars') + # inventory_path could point to a `hosts` file, or to a dir. So we + # construct the location to the `group_vars` differently. + if os.path.isdir(inventory_path): + path = os.path.join(inventory_path, 'group_vars') + else: + path = os.path.join(os.path.dirname(inventory_path), 'group_vars') + self.log.debug("Parsing group vars (dir): {0}".format(path)) if not os.path.exists(path): self.log.warning("No such dir {0}".format(path))