Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot ignore rule jinja[spacing] #3935

Open
AdrienEti opened this issue Dec 6, 2023 · 1 comment
Open

Cannot ignore rule jinja[spacing] #3935

AdrienEti opened this issue Dec 6, 2023 · 1 comment
Labels

Comments

@AdrienEti
Copy link

Summary

The Jinja white-space control generates an jinja [spacing] rule violation.
I'm trying to escape this rule for a variable definition, but it seems that the escape is ignored.
I've tried to place the # noqa: jinja[spacing] mutation in several places, but it is always ignored.

Issue Type
  • Bug Report
OS / ENVIRONMENT
$ ansible-lint --version
ansible-lint 6.22.1 using ansible-core:2.16.0 ansible-compat:4.1.10 ruamel-yaml:0.18.5 ruamel-yaml-clib:0.2.7
  • ansible installation method: pip
  • ansible-lint installation method: pip
STEPS TO REPRODUCE

Defined a variable as follow and try to ignore the jinja[spacing] rule:

foo_postgresql_grafana_password_encoded: >- # noqa: jinja[spacing]
  {% if '!' in foo_postgresql_grafana_password or '#' in foo_postgresql_grafana_password %}
  {{- ('\"\"\"' + foo_postgresql_grafana_password + '\"\"\"') | b64encode -}}
  {% else %}
  {{- foo_postgresql_grafana_password | b64encode -}}
  {% endif %}

or

# noqa: jinja[spacing]
foo_postgresql_grafana_password_encoded: >-
  {% if '!' in foo_postgresql_grafana_password or '#' in foo_postgresql_grafana_password %}
  {{- ('\"\"\"' + foo_postgresql_grafana_password + '\"\"\"') | b64encode -}}
  {% else %}
  {{- foo_postgresql_grafana_password | b64encode -}}
  {% endif %}
Desired Behavior

The jinja[spacing] rule is ignored

Actual Behavior

The jinja[spacing] rule is not ignored

@AdrienEti AdrienEti added bug new Triage required labels Dec 6, 2023
@ssbarnea ssbarnea removed the new Triage required label Dec 13, 2023
@s3lph
Copy link

s3lph commented Mar 4, 2024

I'm affected by the same issue in exactly the same situation. I've found a workaround: Use |- instead of >-, and make all jinja tags remove whitespace (i.e. use {%- -%} rather than {% %}. That way, whitespace is still removed, but by Jinja rather than by the YAML parser.

So, in your example:

foo_postgresql_grafana_password_encoded: |-
  {%- if '!' in foo_postgresql_grafana_password or '#' in foo_postgresql_grafana_password -%}
  {{- ('\"\"\"' + foo_postgresql_grafana_password + '\"\"\"') | b64encode -}}
  {%- else -%}
  {{- foo_postgresql_grafana_password | b64encode -}}
  {%- endif -%}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

No branches or pull requests

3 participants