From b07ab419946aa1cd2f0b9ff1869711655d79beab Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Wed, 28 Jan 2015 14:06:10 -0600 Subject: [PATCH] Fix directory loading of host/group vars in v2 --- v2/ansible/vars/__init__.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/v2/ansible/vars/__init__.py b/v2/ansible/vars/__init__.py index ac03199c974..e3cd64f541f 100644 --- a/v2/ansible/vars/__init__.py +++ b/v2/ansible/vars/__init__.py @@ -236,7 +236,27 @@ class VariableManager: basename of the file without the extension ''' - data = loader.load_from_file(path) + if os.path.isdir(path): + data = dict() + + try: + names = os.listdir(path) + except os.error, err: + raise AnsibleError("This folder cannot be listed: %s: %s." % (path, err.strerror)) + + # evaluate files in a stable order rather than whatever + # order the filesystem lists them. + names.sort() + + # do not parse hidden files or dirs, e.g. .svn/ + paths = [os.path.join(path, name) for name in names if not name.startswith('.')] + for p in paths: + _found, results = self._load_inventory_file(path=p, loader=loader) + data = self._combine_vars(data, results) + + else: + data = loader.load_from_file(path) + name = self._get_inventory_basename(path) return (name, data)