Skip to content

Force template module to use non-native Jinja2 - #68560

Merged
mkrizek merged 15 commits into
ansible:develfrom
mkrizek:46169-non-native-template-module
Sep 3, 2020
Merged

mkrizek merged 15 commits into
ansible:develfrom
mkrizek:46169-non-native-template-module

Conversation

@mkrizek

@mkrizek mkrizek commented Mar 30, 2020

Copy link
Copy Markdown
Contributor
SUMMARY

Fixes #46169

ci_complete

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

Jinja2 native types
template module

@ansibot ansibot added affects_2.10 This issue/PR affects Ansible v2.10 core_review feature This issue/PR relates to a feature request. needs_triage Needs a first human triage before being processed. labels Mar 30, 2020
@ansibot

This comment has been minimized.

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review labels Mar 30, 2020
@jctanner

Copy link
Copy Markdown
Contributor

Would it make sense to create a whole new integration target for this, with the idea that it's a whole class of potential problems we might need to expand over time?

@mkrizek

mkrizek commented Mar 31, 2020

Copy link
Copy Markdown
Contributor Author

Would it make sense to create a whole new integration target for this, with the idea that it's a whole class of potential problems we might need to expand over time?

Good point, I'll do that.

@ansibot ansibot added core_review and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Mar 31, 2020
@ansibot

This comment has been minimized.

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. core_review and removed core_review needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Mar 31, 2020
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Apr 8, 2020
@ansibot ansibot added needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review labels Apr 14, 2020
@mkrizek

This comment has been minimized.

@mkrizek
mkrizek force-pushed the 46169-non-native-template-module branch from 6d25c17 to 7f7eb91 Compare April 16, 2020 10:26
@ansibot ansibot added core_review and removed needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Apr 16, 2020
@sivel sivel removed the needs_triage Needs a first human triage before being processed. label Apr 21, 2020
@mkrizek
mkrizek force-pushed the 46169-non-native-template-module branch from 09626ab to 32ffb71 Compare August 17, 2020 09:44
@mkrizek
mkrizek requested a review from sivel August 17, 2020 09:45
@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. core_review and removed core_review needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Aug 17, 2020
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Aug 25, 2020

@sivel sivel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, just a couple of easy comments.

Comment thread lib/ansible/plugins/lookup/template.py Outdated
variable_end_string=variable_end_string,
available_variables=vars, searchpath=searchpath):
if USE_JINJA2_NATIVE:
res = templar.do_template(template_data, preserve_trailing_newlines=True,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a comment about why we call .do_template for native instead of .template?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this again (because of course I forgot why I did that), the reason is effectively to bypass Templar.is_possibly_template call in Templar.template. If we had '{\n "key": "bar"\n}\n' as an input for is_possibly_template, that would not be considered as a template and the original string would be returned. With native jinja2 we probably want it templated so it's turned into a dict. So I think what we should do here instead is to use .template for native and non-native in the template lookup and add (yet another) if USE_JINJA2_NATIVE check to is_possibly_template to always return True for native.

Sigh...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this turned out not to be a good idea as it broke the below task. Since set_fact is templated once and the result is stored (as opposed to a vars:), the below could be re-templated causing string (there are double quotes) being turned into integer.

- set_fact:
    foo: "'{{ integer_bar }}'"

So it created more problems and calling .template for both native and non-native is what I ended up with.

Comment thread lib/ansible/plugins/lookup/template.py Resolved
@mkrizek
mkrizek force-pushed the 46169-non-native-template-module branch from 32ffb71 to 8f506f4 Compare August 28, 2020 07:16
@ansibot ansibot removed the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Aug 28, 2020
@mkrizek

mkrizek commented Sep 2, 2020

Copy link
Copy Markdown
Contributor Author

!waffling core_review

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

affects_2.10 This issue/PR affects Ansible v2.10 docs This issue/PR relates to or includes documentation. feature This issue/PR relates to a feature request.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

template module with jinja2_native erroneously convert json string to dict and corrupt it

5 participants