ansible-lint icon indicating copy to clipboard operation
ansible-lint copied to clipboard

jinja[spacing] suggested change that will break the code

Open rpelisse opened this issue 5 months ago • 0 comments

Summary

In the following report, jinja[space] suggest to remove an extra backslash to fix the spacing, which would result in a change of behavior in the code.

roles/wildfly_utils/tasks/apply_cp.yml:60: jinja[spacing]: Jinja2 spacing could be improved: {{ rhn_products.results | map(attribute='file_path') | select('match', '^[^/]*/jboss-eap-.*[0-9]*[.][0-9]*[.][0-9]*.*$') | map('regex_replace','[^/]*/jboss-eap-([0-9]*[.][0-9]*[.][0-9]*)-.*','\1' ) | list | unique }} -> {{ rhn_products.results | map(attribute='file_path') | select('match', '^[^/]*/jboss-eap-.*[0-9]*[.][0-9]*[.][0-9]*.*$') | map('regex_replace', '[^/]*/jboss-eap-([0-9]*[.][0-9]*[.][0-9]*)-.*', '\1') | list | unique }} (warning)

Note the backlash in question is NOT shown above, but you see it in the code below:

    - name: Determine patch versions list
      ansible.builtin.set_fact:
        filtered_versions: "{{ rhn_products.results | map(attribute='file_path') | select('match', '^[^/]*/jboss-eap-.*[0-9]*[.][0-9]*[.][0-9]*.*$') | map('regex_replace','[^/]*/jboss-eap-([0-9]*[.][0-9]*[.][0-9]*)-.*','\\1' ) | list | unique }}"

The invalid suggestion is a bit problematic, but also, because of the bug causing, there is no way to get ride of the warning (without breaking the code or rewriting it differently to workaround the issue).

Issue Type
  • Bug Report
OS / ENVIRONMENT
(2.16) [root@79c4779411aa work]# cat /etc/redhat-release 
Fedora release 40 (Forty)
(2.16) [root@79c4779411aa work]# python --version
Python 3.12.5
(2.16) [root@79c4779411aa work]# ansible-lint --version
ansible-lint 24.9.0 using ansible-core:2.16.0 ansible-compat:24.9.0 ruamel-yaml:0.18.6 ruamel-yaml-clib:0.2.8
STEPS TO REPRODUCE
$ git clone 
$ cd wildfly.git/
$ git checkout -b lint-issue 396036f8bde3d1f75389ab98f9e98f98f015970f
$ ansible-lint # look for the warning on file roles/wildfly_install/tasks/prereqs.yml, line 71
Desired Behavior

This is false+ as I don't think there is any issue with the spacing, so the desired outcome would be that no warning is being filed against the line.

Actual Behavior

See description above.

rpelisse avatar Sep 12 '24 13:09 rpelisse