Skip to content

Commit

Permalink
Avoid jinja[invalid] with ansible.builtin.mandatory filter (#3917)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Nov 29, 2023
1 parent 868ebac commit 58e4ba5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions examples/playbooks/rule-jinja-pass.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,7 @@
- name: "Bug https://github.com/ansible/ansible-lint/issues/3155"
ansible.builtin.debug:
msg: "Is changed:{{ date_cmd is changed }}"

- name: Bug https://github.com/ansible/ansible-lint/issues/3908
ansible.builtin.debug:
msg: "{{ foo | ansible.builtin.mandatory(msg='My message') }}"
4 changes: 3 additions & 1 deletion src/ansiblelint/rules/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import black
import jinja2
from ansible.errors import AnsibleError, AnsibleParserError
from ansible.errors import AnsibleError, AnsibleFilterError, AnsibleParserError
from ansible.parsing.yaml.objects import AnsibleUnicode
from jinja2.exceptions import TemplateSyntaxError

Expand Down Expand Up @@ -132,6 +132,8 @@ def matchtask(
variables=deannotate(task.get("vars", {})),
fail_on_error=True, # we later decide which ones to ignore or not
)
except AnsibleFilterError:
bypass = True
# ValueError RepresenterError
except AnsibleError as exc:
bypass = False
Expand Down

0 comments on commit 58e4ba5

Please sign in to comment.