@@ -138,7 +138,13 @@ def _parse_hostvar_dir(self, inventory_path):
138
138
"""
139
139
Parse host_vars dir, if it exists.
140
140
"""
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
+
142
148
self .log .debug ("Parsing host vars (dir): {0}" .format (path ))
143
149
if not os .path .exists (path ):
144
150
self .log .warning ("No such dir {0}" .format (path ))
@@ -193,7 +199,13 @@ def _parse_groupvar_dir(self, inventory_path):
193
199
"""
194
200
Parse group_vars dir, if it exists. Encrypted vault files are skipped.
195
201
"""
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
+
197
209
self .log .debug ("Parsing group vars (dir): {0}" .format (path ))
198
210
if not os .path .exists (path ):
199
211
self .log .warning ("No such dir {0}" .format (path ))
0 commit comments