-
Notifications
You must be signed in to change notification settings - Fork 23.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net_template.py: Fix j2 file search path #15134
Conversation
Coverage remained the same at 64.655% when pulling e8192a0b52bb5899d76cfed0afacb05a8211c7c2 on keinohguchi:net_template_fix into 85cc3b7 on ansible:devel. |
travis is green, as shown below: |
@@ -93,6 +94,11 @@ def _handle_template(self): | |||
except IOError: | |||
return dict(failed=True, msg='unable to load src file') | |||
|
|||
searchpath = [working_path, os.path.dirname(source)] | |||
if self._task._role is not None: | |||
searchpath.insert(1, C.DEFAULT_ROLES_PATH) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DEFAULT_ROLES_PATH should never be in use by a plugin, it should always use the 'current role path' if it exists or fallback to the playbook path. Another issue is that this is treated as a single directory entry when it could be a list of paths.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @bcoca for your quick reply! I've actually followed the existing template.py as a sample. Let me know if the issue above also exists in template.py or net_template.py is another beast which we need to play differently.
https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/action/template.py#L125
Thank you for your support!
Cheers,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, that is wrong also, going to fix that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! I'll use yours as a reference! Thanks again!
Incorporate @bcoca's comment, but needs to use ._role_path, as get_dep_chain() returns Role object. It worked on my environment but needs pro's review, as I don't have a sample dependency block playbooks... I can test in my environment if you can give me sample dependency block, which exercise the particular code block. Thank you for your support! |
Oops, I shouldn't merge the submodule dependency… I'll fix that and get back here. Cheers, |
Removed unnessesary change for the submodule git hash tag. Now the change only exists in net_template.py. Please review! |
Based on the IRC chat today, this might be the one to address the issue generically. Having a link here |
@bcoca, Any word on the generic fix for this? If not, we wondered at today's meeting if we should merge this as a short-term fix until the generic fix can be finished and merged. |
need time to finish it, too many things ... not sure if this fix is correct, it looks like one of my early attempts. As long as someone can verify the paths are correct, i'm fine with 'temp merge' |
Thanks @bcoca for the reply! We'll discuss about this during tomorrow's network meeting and will have a consensus among the team. Cheers and have a wonderful night! |
Hi @Qalthos, Can you take a look at this PR, as suggested by @privateip durinug last network meeting? networking_working_group.2016-05-04-16.03.html I should've done this but waited to get green by travis.... It seems that's common issue across the board. Thank you for your support! Cheers, |
Hi @Qalthos, I've rebased the branch against the latest devel, as it has a fix for the travis CI test case. Once we get Thank you for your support and hope this will be in to the 2.1. :) Cheers, |
Thank you @jim-c for taking care of those labels! I've just rebased the branch just now and kicked the travis. Hope we'll get a green sign from him. :) Cheers! |
if self._task._block._dep_chain: | ||
for role in sorted(self._task._block.get_dep_chain()): | ||
searchpath.insert(1, role._role_path) | ||
searchpath.insert(1, self._task._role._role_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to follow the final order of the paths... I think the final order is [working _path, _role._role_path, *_block._role_paths, dirname(source)]
Would it not be more straightforward to order it thusly:
searchpath = [working_path]
if self._task._role is not None:
searchpath.append(_role._role_path)
for role in sorted(dep_chain()):
searchpath.append(role._role_path)
searchpath.append(dirname(source))
That would seem to make the intended order clearer while avoiding the overhead of a bunch of insert(1, x) calls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @Qalthos and I agree with that suggestion.
I've incorporated your suggestion and run it locally, without any issue.
Please take a look at the updated change and let me know if you see any other issues.
Thank you for your support and hope we'll get the green sign from travis. :)
Cheers,
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.
Hi @Qalthos, I've update the patch, to use the get_dep_chain() as well as removing the sort(), as we don't need the Please take a look at the updated patch. Cheers, |
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.
Thank you @Qalthos and the team for your support and make it happen for 2.1! Really appreciated, team! I can the devel branch for my testing finally! :) Cheers and happy 2.1! :) |
ISSUE TYPE
ANSIBLE VERSION
SUMMARY
Fixes #15133
This allows to '{% include ['another.j2'] %}' work inside j2 file.