fix: add explicit bool filters for Ansible 12 jinja2_native compatibility#14963
Merged
Conversation
…lity Ansible 12 enables jinja2_native by default, which means string values like "true"/"false" are no longer automatically coerced to booleans in when: conditions and Jinja2 if statements. Add | bool filters to all boolean variable references in tasks, templates, and handlers. Also reformats long single-line Jinja2 conditionals into multi-line for readability, fixes GCE default() calls for native mode, adds help command to the algo script, and updates test fixtures to register the bool filter. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add j2lint (aristanetworks/j2lint) to catch syntax errors, spacing issues, and operator formatting in Jinja2 templates. Integrated into pre-commit hooks, lint.yml CI, and smart-tests.yml. Rules S3/S5/S6/S7/V1 are ignored — they enforce conventions incompatible with Ansible's config-file-embedded templates. Also fixes int+1 → int + 1 operator spacing in server.conf.j2. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fix 18 jinja[spacing] errors across 12 files by moving Jinja2 block delimiters to prevent YAML >- folding from introducing trailing spaces. Fix 27 key-order[task] warnings across 17 files by reordering task keys to canonical order (name → when → tags → environment → become → block). Promote key-order[task] and yaml[line-length] from warn_list to hard errors by removing warn_list entirely from .ansible-lint. Add zero-tolerance warning policy to CLAUDE.md explaining why warnings are unacceptable in a security tool and documenting resolution order. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
| boolfilters to all boolean variable references inwhen:conditions and Jinja2ifstatements across 31 filesjinja2_nativeby default, so string values"true"/"false"are no longer auto-coerced to booleans — barewhen: ipsec_enabledsilently evaluates truthy for any non-empty stringinput.yml,users.yml, all cloud provider prompts)default()calls to passtrueparameter (empty strings don't triggerdefault()in native mode)help|-h|--helpcommand to thealgoshell scriptboolfilter in Jinja2 environmentlint.ymlCI, andsmart-tests.yml— catches syntax errors, spacing issues, and operator formatting in.j2templatesj2lint configuration
Rules ignored (incompatible with Ansible config-file-embedded templates):
{%-/-%})IP_subject_alt_nameAffected areas
rules.v4.j2,rules.v6.j2| boolonipsec_enabled,wireguard_enabled,snat_aipv4,alternative_ingress_ipserver.yml| booloncloudinit,wireguard_enabled,ipsec_enabled,algo_dns_adblocking,dns_encryption,algo_ssh_tunnelingdns/tasks/main.yml,dns/handlers/main.yml, templates| boolonis_debian_based,uses_systemd_socket,algo_dns_adblocking,ipv6_supportwireguard/defaults/main.yml,tasks/main.yml,server.conf.j2| boolonipv6_support,is_debian_based; fixint+1spacingstrongswan/defaults/main.yml,tasks/,ipsec.conf.j2| boolonipv6_support,algo_dns_adblocking,dns_encryption,is_debian_basedprompts.yml+main.yml| boolonalternative_ingress_ipinput.yml,users.yml| boolonipsec_enabled,wireguard_enabledtest_iptables_rules.py,test_wireguard_key_generation.pyboolfilter, rename unused varlint.yml,smart-tests.yml,.pre-commit-config.yaml,pyproject.tomlTest plan
j2lint roles/ --ignore S3 S5 S6 S7 V1— passed (0 errors)ansible-lint .— passed (production profile)yamllint .— passedruff check .— passedshellcheck algo— passedactionlint .github/workflows/lint.yml .github/workflows/smart-tests.yml— passedansible-playbook main.yml --syntax-check— passedansible-playbook users.yml --syntax-check— passedpytest tests/unit/ -q— 90 passed🤖 Generated with Claude Code