summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToshio Kuratomi <a.badger@gmail.com>2016-03-04 11:03:18 -0800
committerToshio Kuratomi <a.badger@gmail.com>2016-03-04 11:03:18 -0800
commit8494d3867c85b294a901404497c32c9c4367943a (patch)
tree519be61b2ada562ac0ee5f8370929aab8c6c2ba4
parentb11f2a026701af1b37303b3d680c5e93814829c3 (diff)
parente856ac2320d4bd2e8559d7e214241ec55f29325f (diff)
downloadansible-8494d3867c85b294a901404497c32c9c4367943a.tar.gz
Merge pull request #13556 from xytis/inventory_dir
fix loading host/group vars when inventory is directory and using --limit
-rw-r--r--lib/ansible/inventory/__init__.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/ansible/inventory/__init__.py b/lib/ansible/inventory/__init__.py
index 78e9f3c793..976769f293 100644
--- a/lib/ansible/inventory/__init__.py
+++ b/lib/ansible/inventory/__init__.py
@@ -559,11 +559,20 @@ class Inventory(object):
return False
return os.path.exists(self.host_list)
+ def is_dir(self):
+ """ did inventory come from a directory? """
+ if not isinstance(self.host_list, basestring):
+ return False
+ return os.path.isdir(self.host_list)
+
def basedir(self):
""" if inventory came from a file, what's the directory? """
if not self.is_file():
return None
- dname = os.path.dirname(self.host_list)
+ if self.is_dir():
+ dname = os.path.dirname(os.path.dirname(self.host_list))
+ else:
+ dname = os.path.dirname(self.host_list)
if dname is None or dname == '' or dname == '.':
cwd = os.getcwd()
return os.path.abspath(cwd)