Skip to content

Commit 359d866

Browse files
anusshuklaanushkshpre-commit-ci[bot]
authored
Fix Jinja template rendering error when concatenating _AnsibleTaggedStr with list (#4737)
Co-authored-by: anushka-shukla-03 <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 5a78671 commit 359d866

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/ansiblelint/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class Options: # pylint: disable=too-many-instance-attributes
181181
max_tasks: int = 100
182182
max_block_depth: int = 20
183183
# Refer to https://docs.ansible.com/ansible/latest/reference_appendices/release_and_maintenance.html#ansible-core-support-matrix
184-
_default_supported = ["2.15.", "2.16.", "2.17.", "2.18."]
184+
_default_supported = ["2.15.", "2.16.", "2.17.", "2.18.", "2.19."]
185185
supported_ansible_also: list[str] = field(default_factory=list)
186186

187187
@property

src/ansiblelint/rules/jinja.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ class Token(NamedTuple):
6969
r"^The '(.*)' test expects a dictionary$",
7070
# https://github.com/ansible/ansible-lint/issues/4338
7171
r"An unhandled exception occurred while templating (.*). Error was a <class 'ansible.errors.AnsibleFilterError'>, original message: The (.*) test expects a dictionary$",
72+
r"can only concatenate list \(not \"_AnsibleTaggedStr\"\) to list",
73+
r"can only concatenate str \(not \"_AnsibleTaggedStr\"\) to str",
7274
],
7375
),
7476
flags=re.MULTILINE | re.DOTALL,
@@ -961,3 +963,36 @@ def test_filter_import_failure(
961963
lintable = Lintable("examples/playbooks/test_filter_with_importerror.yml")
962964
results = Runner(lintable, rules=collection).run()
963965
assert len(results) == expected_results
966+
967+
def test_ansible_core_2_19_supported_version() -> None:
968+
"""Test that ansible-core 2.19 is in the supported versions list."""
969+
from ansiblelint.config import Options
970+
971+
options = Options()
972+
supported_versions = options.supported_ansible
973+
974+
# Check that 2.19 is in the supported versions
975+
assert any("2.19" in version for version in supported_versions), (
976+
f"ansible-core 2.19 not found in supported versions: {supported_versions}"
977+
)
978+
979+
@pytest.mark.parametrize(
980+
("error_message", "should_be_ignored"),
981+
(
982+
('can only concatenate list (not "_AnsibleTaggedStr") to list', True),
983+
('can only concatenate str (not "_AnsibleTaggedStr") to str', True),
984+
("Unexpected templating type error occurred on (var): details", True),
985+
("Object of type method is not JSON serializable", True),
986+
('can only concatenate list (not "int") to list', False),
987+
("TemplateSyntaxError: unexpected token", False),
988+
("UndefinedError: variable not defined", False),
989+
("can only concatenate list (not AnsibleTaggedStr) to list", False),
990+
),
991+
)
992+
def test_jinja_ignore_patterns(error_message: str, should_be_ignored: bool) -> None:
993+
"""Test that ignore patterns correctly handle ansible-core 2.19 _AnsibleTaggedStr errors."""
994+
matches = bool(ignored_re.search(error_message))
995+
assert matches == should_be_ignored, (
996+
f"Error message '{error_message}' should {'be ignored' if should_be_ignored else 'not be ignored'} "
997+
f"but {'was' if matches else 'was not'} matched by ignore pattern"
998+
)

0 commit comments

Comments
 (0)