From 7fdbfd490eadf65f64f9cf8cdcbef5a3c8692eb8 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Sun, 24 Jul 2016 21:31:11 -0400 Subject: [PATCH] allow include_vars to namespace imports --- lib/ansible/plugins/action/include_vars.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/ansible/plugins/action/include_vars.py b/lib/ansible/plugins/action/include_vars.py index c7283d14f7a..9eecf94dd91 100644 --- a/lib/ansible/plugins/action/include_vars.py +++ b/lib/ansible/plugins/action/include_vars.py @@ -26,13 +26,19 @@ class ActionModule(ActionBase): TRANSFERS_FILES = False def run(self, tmp=None, task_vars=None): + + varname = self._task.args.get('name') + source = self._task.args.get('file') + if not source: + source = self._task.args.get('_raw_params') + if task_vars is None: task_vars = dict() result = super(ActionModule, self).run(tmp, task_vars) try: - source = self._find_needle('vars', self._task.args.get('_raw_params')) + source = self._find_needle('vars', source) except AnsibleError as e: result['failed'] = True result['message'] = to_str(e) @@ -46,6 +52,10 @@ class ActionModule(ActionBase): result['failed'] = True result['message'] = "%s must be stored as a dictionary/hash" % source else: + if varname: + scope = {} + scope[varname] = data + data = scope result['ansible_facts'] = data result['_ansible_no_log'] = not show_content