Skip to content
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

Do not crash templating when filter/test name is not a valid Ansible plugin name #78913

Merged

Conversation

felixfontein
Copy link
Contributor

SUMMARY

Fixes #78912.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

lib/ansible/template/__init__.py

@felixfontein felixfontein force-pushed the fix-missing-filter-test-templating branch from 07286a5 to 94556fd Compare September 28, 2022 19:24
@ansibot ansibot added affects_2.15 bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Sep 28, 2022
@felixfontein
Copy link
Contributor Author

Ok, this doesn't really work, since Jinja2Loader.get_with_context() uses KeyError also for a lot of other things with totally different meanings (like broken plugins). At least the test added here can be recycled in other places...

@felixfontein felixfontein marked this pull request as draft September 28, 2022 19:35
@ansibot ansibot added WIP This issue/PR is a work in progress. Nevertheless it was shared for getting input from peers. has_issue support:community This issue/PR relates to code supported by the Ansible community. and removed core_review In order to be merged, this PR must follow the core review workflow. labels Sep 28, 2022
@s-hertel
Copy link
Contributor

s-hertel commented Sep 28, 2022

I think there are just a couple places that filters/tests need to be special-cased for import/load failures. I think this would fix some test failures: c0629b9

Otherwise, we could also pass the delegatee plugins to the plugin loader, so then we wouldn't need to differentiate between missing/broken plugins outside of the loader. But I like your current approach.

Or we could save the initial KeyError and reraise with the original exception if there is no delegatee.

@bcoca
Copy link
Member

bcoca commented Sep 29, 2022

code is good start, I agree with @s-hertel on saving the keyerror in case the plugin is also not found in the JInaj2 provided ones.

@felixfontein
Copy link
Contributor Author

@s-hertel thanks, that indeed fixes the CI failures!

@felixfontein felixfontein marked this pull request as ready for review September 29, 2022 18:48
@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. core_review In order to be merged, this PR must follow the core review workflow. and removed WIP This issue/PR is a work in progress. Nevertheless it was shared for getting input from peers. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Sep 29, 2022
@felixfontein
Copy link
Contributor Author

/rebuild_failed

@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 In order to be merged, this PR must follow the core review workflow. labels Sep 29, 2022
@mattclay mattclay removed the needs_triage Needs a first human triage before being processed. label Sep 29, 2022
@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Sep 29, 2022
@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 In order to be merged, this PR must follow the core review workflow. labels Oct 4, 2022
@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Oct 4, 2022
@bcoca bcoca merged commit 6d0aeac into ansible:devel Oct 4, 2022
@felixfontein felixfontein deleted the fix-missing-filter-test-templating branch October 4, 2022 18:21
@felixfontein
Copy link
Contributor Author

@s-hertel @bcoca thanks a lot for reviewing, improving, and merging this PR!

felixfontein added a commit to felixfontein/ansible that referenced this pull request Oct 4, 2022
…plugin name (ansible#78913)

* Do not crash templating when filter/test name is not a valid Ansible plugin name.
* Store and re-raise KeyError if there was one.

Co-authored-by: s-hertel <19572925+s-hertel@users.noreply.github.com>
(cherry picked from commit 6d0aeac)
ssbarnea added a commit to ssbarnea/ansible-lint that referenced this pull request Oct 5, 2022
As ansible/ansible#78913 changed behavior
of Ansible on missing filters, we adapted the check so it would
continue to work with newer versions.
ssbarnea added a commit to ssbarnea/ansible-lint that referenced this pull request Oct 5, 2022
As ansible/ansible#78913 changed behavior
of Ansible on missing filters, we adapted the check so it would
continue to work with newer versions.
ssbarnea added a commit to ssbarnea/ansible-lint that referenced this pull request Oct 5, 2022
As ansible/ansible#78913 changed behavior
of Ansible on missing filters, we adapted the check so it would
continue to work with newer versions.
ssbarnea added a commit to ssbarnea/ansible-lint that referenced this pull request Oct 5, 2022
As ansible/ansible#78913 changed behavior
of Ansible on missing filters, we adapted the check so it would
continue to work with newer versions.
ssbarnea added a commit to ssbarnea/ansible-lint that referenced this pull request Oct 5, 2022
As ansible/ansible#78913 changed behavior
of Ansible on missing filters, we adapted the check so it would
continue to work with newer versions.
ssbarnea added a commit to ssbarnea/ansible-lint that referenced this pull request Oct 6, 2022
As ansible/ansible#78913 changed behavior
of Ansible on missing filters, we adapted the check so it would
continue to work with newer versions.
ssbarnea added a commit to ssbarnea/ansible-lint that referenced this pull request Oct 6, 2022
As ansible/ansible#78913 changed behavior
of Ansible on missing filters, we adapted the check so it would
continue to work with newer versions.
ssbarnea added a commit to ansible/ansible-lint that referenced this pull request Oct 6, 2022
* Ensure we detect templating errors

As ansible/ansible#78913 changed behavior
of Ansible on missing filters, we adapted the check so it would
continue to work with newer versions.

* chore: auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
sivel pushed a commit that referenced this pull request Oct 6, 2022
…plugin name (#78913) (#79026)

* Do not crash templating when filter/test name is not a valid Ansible plugin name.
* Store and re-raise KeyError if there was one.

Co-authored-by: s-hertel <19572925+s-hertel@users.noreply.github.com>
(cherry picked from commit 6d0aeac)
@ansible ansible locked and limited conversation to collaborators Oct 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.15 bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. has_issue support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change to filter/test plugin loading / templating breaks certain playbook constructs
5 participants