diff options
author | Kei Nohguchi <kei@nohguchi.com> | 2016-05-16 07:05:08 -0700 |
---|---|---|
committer | Nathaniel Case <ncase@redhat.com> | 2016-05-16 10:10:04 -0400 |
commit | 956829f0f059e15c14af6f54395b85a51072ffda (patch) | |
tree | f0e6a9b4a80f9b2b386d40f97075d5194a5f97c6 | |
parent | af5195e33635ef5d18db13345875ca58591cb5ca (diff) | |
download | ansible-956829f0f059e15c14af6f54395b85a51072ffda.tar.gz |
net_template.py: Fix jinja2 template file search path (#15134)
The change is needed to support the multiple include statements
inside the jinja2 template file, as in '{% include ['another.j2'] %}'.
statement. I need this capability, as OpenSwitch `switch` role needs
to handle multiple *.j2 files and supporting the include statement
inside jinja2 file is essential, otherwise I need to combine multiple
template files into a single file, which easily causes conflicts
between developers working on different parts of the teamplate, ports
and interface.
-rw-r--r-- | lib/ansible/plugins/action/net_template.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/ansible/plugins/action/net_template.py b/lib/ansible/plugins/action/net_template.py index c626c8dc6b..3d27cac5f2 100644 --- a/lib/ansible/plugins/action/net_template.py +++ b/lib/ansible/plugins/action/net_template.py @@ -93,6 +93,17 @@ class ActionModule(ActionBase): except IOError: return dict(failed=True, msg='unable to load src file') + # Create a template search path in the following order: + # [working_path, self_role_path, dependent_role_paths, dirname(source)] + searchpath = [working_path] + if self._task._role is not None: + searchpath.append(self._task._role._role_path) + dep_chain = self._task._block.get_dep_chain() + if dep_chain is not None: + for role in dep_chain: + searchpath.append(role._role_path) + searchpath.append(os.path.dirname(source)) + self._templar.environment.loader.searchpath = searchpath self._task.args['src'] = self._templar.template(template_data) |