diff options
author | James Cammarata <jimi@sngx.net> | 2015-07-13 15:18:05 -0400 |
---|---|---|
committer | James Cammarata <jimi@sngx.net> | 2015-07-13 15:18:23 -0400 |
commit | c18fdd0c18d26cc0c5c3033509da28c30443c0ed (patch) | |
tree | d6ccf19c300d3349ebed9dafb3227712d46b973d | |
parent | 1255a0708ad4d5ddf37c03acea988ab88fccc2ee (diff) | |
download | ansible-c18fdd0c18d26cc0c5c3033509da28c30443c0ed.tar.gz |
Re-implement "conditional imports" for vars_files
-rw-r--r-- | lib/ansible/vars/__init__.py | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/lib/ansible/vars/__init__.py b/lib/ansible/vars/__init__.py index 0f1561b5a2..13c9cc8f08 100644 --- a/lib/ansible/vars/__init__.py +++ b/lib/ansible/vars/__init__.py @@ -189,13 +189,26 @@ class VariableManager: if play: all_vars = self._combine_vars(all_vars, play.get_vars()) templar = Templar(loader=loader, variables=all_vars) - for vars_file in play.get_vars_files(): + + for vars_file_item in play.get_vars_files(): try: - vars_file = templar.template(vars_file) - data = loader.load_from_file(vars_file) - if data is None: - data = dict() - all_vars = self._combine_vars(all_vars, data) + # we assume each item in the list is itself a list, as we + # support "conditional includes" for vars_files, which mimics + # the with_first_found mechanism. + vars_file_list = templar.template(vars_file_item) + if not isinstance(vars_file_list, list): + vars_file_list = [ vars_file_list ] + + # now we iterate through the (potential) files, and break out + # as soon as we read one from the list. If none are found, we + # raise an error, which is silently ignored at this point. + for vars_file in vars_file_list: + data = loader.load_from_file(vars_file) + if data is not None: + all_vars = self._combine_vars(all_vars, data) + break + else: + raise AnsibleError("vars file %s was not found" % vars_file_item) except: # FIXME: get_vars should probably be taking a flag to determine # whether or not vars files errors should be fatal at this |