Skip to content

Fix data tag related tests #400

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

Merged
merged 25 commits into from
Jun 9, 2025
Merged

Conversation

Ruchip16
Copy link
Member

@Ruchip16 Ruchip16 commented May 28, 2025

SUMMARY

This PR addresses and resolves several failing unit and integration tests in the ansible.utils collection caused by recent changes in Ansible 2.19’s templating system.

also related to #398

Root Cause:

Starting with Ansible 2.19, the internal behavior of the Jinja2-based templating engine has changed. Specifically:

  • Undefined values (e.g., AnsibleUndefined) are now intercepted earlier by the Templar.
  • These values no longer reach filter functions directly. Instead, the Templar raises a TemplateError or TemplatePluginError before any filter logic is invoked.
  • As a result, unit tests that manually create and pass AnsibleUndefined values to filters (bypassing the Templar) are invalid and misleading, since such situations will not occur in actual playbook execution.

Additionally, some integration tests showed inconsistent behavior across Ansible versions (e.g., 2.17, 2.18 vs 2.19) due to how JSON was read and interpreted from file lookups:

  • In certain environments, lookup('file') returned a raw string, which caused the validate filter to behave incorrectly.
  • This inconsistency has been resolved by explicitly parsing input data and criteria using the from_json filter

Fixes the certain failing unit and integration tests in utils

IMPACT

In Ansible 2.19, undefined values (like AnsibleUndefined) no longer reach filter functions directly. Instead:

  • The Templar catches them earlier and raises a TemplateError or TemplatePluginError before the filter even runs.
  • So tests that manually create and pass AnsibleUndefined to filters are invalid now.
  • The ipaddr filter does not support undefined values, so there’s no point in testing that behavior anymore.
  • Ensures test consistency across Ansible versions
  • Avoids false positives or misleading failures in CI due to template handling differences.
  • Aligns tests with the intended and supported behavior of Ansible 2.19+.
  • Removes reliance on Ansible internals (Templar, _internal._ambient_context, etc.) for unit tests that do not require them.
ISSUE TYPE
  • Bugfix Pull Request

Copy link
Contributor

Copy link
Contributor

Copy link
Contributor

Copy link
Contributor

Copy link
Contributor

Copy link
Contributor

@Ruchip16 Ruchip16 requested a review from roverflow June 9, 2025 12:51
@Ruchip16 Ruchip16 merged commit 7fb5056 into ansible-collections:main Jun 9, 2025
46 checks passed
@Ruchip16 Ruchip16 deleted the ci_failures branch June 9, 2025 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants