Skip to content

Commit 7bad79c

Browse files
author
Ferry Boender
committed
Don't strip last part of inventory_path if it's already a dir.
1 parent 78d359b commit 7bad79c

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/ansiblecmdb/ansible.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,13 @@ def _parse_hostvar_dir(self, inventory_path):
138138
"""
139139
Parse host_vars dir, if it exists.
140140
"""
141-
path = os.path.join(os.path.dirname(inventory_path), 'host_vars')
141+
# inventory_path could point to a `hosts` file, or to a dir. So we
142+
# construct the location to the `host_vars` differently.
143+
if os.path.isdir(inventory_path):
144+
path = os.path.join(inventory_path, 'host_vars')
145+
else:
146+
path = os.path.join(os.path.dirname(inventory_path, 'host_vars'))
147+
142148
self.log.debug("Parsing host vars (dir): {0}".format(path))
143149
if not os.path.exists(path):
144150
self.log.warning("No such dir {0}".format(path))
@@ -193,7 +199,13 @@ def _parse_groupvar_dir(self, inventory_path):
193199
"""
194200
Parse group_vars dir, if it exists. Encrypted vault files are skipped.
195201
"""
196-
path = os.path.join(os.path.dirname(inventory_path), 'group_vars')
202+
# inventory_path could point to a `hosts` file, or to a dir. So we
203+
# construct the location to the `group_vars` differently.
204+
if os.path.isdir(inventory_path):
205+
path = os.path.join(inventory_path, 'group_vars')
206+
else:
207+
path = os.path.join(os.path.dirname(inventory_path), 'group_vars')
208+
197209
self.log.debug("Parsing group vars (dir): {0}".format(path))
198210
if not os.path.exists(path):
199211
self.log.warning("No such dir {0}".format(path))

0 commit comments

Comments
 (0)