Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .config/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ indentless
inlinehilite
iscsi
junitxml
kdump
kubevirt
libyaml
licensedb
Expand Down
14 changes: 11 additions & 3 deletions src/ansiblelint/rules/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ class Token(NamedTuple):
r"An unhandled exception occurred while templating (.*). Error was a <class 'ansible.errors.AnsibleFilterError'>, original message: The (.*) test expects a dictionary$",
r"can only concatenate list \(not \"_AnsibleTaggedStr\"\) to list",
r"can only concatenate str \(not \"_AnsibleTaggedStr\"\) to str",
r"can only concatenate list \(not \"UndefinedMarker\"\) to list",
r"can only concatenate str \(not \"UndefinedMarker\"\) to str",
r"can only concatenate list \(not \"AnsibleUndefined\"\) to list",
r"can only concatenate str \(not \"AnsibleUndefined\"\) to str",
r"can only concatenate list \(not \"StrictUndefined\"\) to list",
r"can only concatenate str \(not \"StrictUndefined\"\) to str",
r"can only concatenate list \(not \"ChainableUndefined\"\) to list",
r"can only concatenate str \(not \"ChainableUndefined\"\) to str",
],
),
flags=re.MULTILINE | re.DOTALL,
Expand Down Expand Up @@ -977,7 +985,7 @@ def test_jinja_template_generates_ansible_tagged_str_error() -> None:
f"Normal error should not be ignored: {normal_error_msg}"
)

# Test that the ignore pattern works for the specific error we're testing
# Test UndefinedMarker errors are ignored
assert ignored_re.search(
'can only concatenate str (not "_AnsibleTaggedStr") to str'
), "String concatenation with _AnsibleTaggedStr should also be ignored"
'can only concatenate list (not "UndefinedMarker") to list'
), "UndefinedMarker concatenation should be ignored"
26 changes: 25 additions & 1 deletion test/test_jinja_ansible_tagged_str.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,42 @@ def test_jinja_template_generates_ansible_tagged_str_error_comprehensive(
@pytest.mark.parametrize(
("error_message", "should_be_ignored"),
(
# _AnsibleTaggedStr errors (cockpit issue)
('can only concatenate list (not "_AnsibleTaggedStr") to list', True),
('can only concatenate str (not "_AnsibleTaggedStr") to str', True),
# UndefinedMarker errors (kdump issue)
('can only concatenate list (not "UndefinedMarker") to list', True),
('can only concatenate str (not "UndefinedMarker") to str', True),
# AnsibleUndefined errors (kernel_settings issue)
('can only concatenate list (not "AnsibleUndefined") to list', True),
('can only concatenate str (not "AnsibleUndefined") to str', True),
# StrictUndefined errors (kernel_settings issue)
('can only concatenate list (not "StrictUndefined") to list', True),
('can only concatenate str (not "StrictUndefined") to str', True),
# ChainableUndefined errors (vpn issue)
('can only concatenate list (not "ChainableUndefined") to list', True),
('can only concatenate str (not "ChainableUndefined") to str', True),
# Other known patterns
("Unexpected templating type error occurred on", True),
("Object of type method is not JSON serializable", True),
# Legitimate errors that should NOT be ignored
('can only concatenate list (not "int") to list', False),
("TemplateSyntaxError: unexpected char '!' at 5", False),
),
)
def test_jinja_ignore_patterns_comprehensive(
self, error_message: str, should_be_ignored: bool
) -> None:
"""Test comprehensive ignore patterns for _AnsibleTaggedStr errors."""
"""Test comprehensive ignore patterns for ansible-core 2.19+ type errors.

This covers:
- _AnsibleTaggedStr errors (cockpit role)
- UndefinedMarker errors (kdump role)
- AnsibleUndefined/StrictUndefined errors (kernel_settings role)
- ChainableUndefined errors (vpn role)

See: linux-system-roles/vpn#207
"""
matches = bool(ignored_re.search(error_message))
assert matches == should_be_ignored, (
f"Error message '{error_message}' should {'be ignored' if should_be_ignored else 'not be ignored'} "
Expand Down