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

jinja[spacing] conflict with yaml[line-length] #2522

Closed
sathieu opened this issue Sep 30, 2022 · 2 comments
Closed

jinja[spacing] conflict with yaml[line-length] #2522

sathieu opened this issue Sep 30, 2022 · 2 comments
Labels

Comments

@sathieu
Copy link
Contributor

sathieu commented Sep 30, 2022

Summary

With the following roles/test/tasks/main.yml:

- name: Test
  ansible.builtin.debug:
    msg: "Hello: world"
  vars:
    sealed_raw_input: "{{ {
          cluster_namespace + '/' + cluster_name + '/username': hostvars[control_plane].cluster_api_vsphere_username,
          cluster_namespace + '/' + cluster_name + '/password': hostvars[control_plane].cluster_api_vsphere_password,
      } }}"

I get:

$ ansible-lint 
WARNING  Listing 1 violation(s) that are fatal
jinja: Jinja2 spacing could be improved: {{ { cluster_namespace + '/' + cluster_name + '/username': hostvars[control_plane].cluster_api_vsphere_username, cluster_namespace + '/' + cluster_name + '/password': hostvars[control_plane].cluster_api_vsphere_password, } }} -> {{ {
    cluster_namespace + '/' + cluster_name + '/username': hostvars[control_plane].cluster_api_vsphere_username,
    cluster_namespace + '/' + cluster_name + '/password': hostvars[control_plane].cluster_api_vsphere_password,
} }} (jinja[spacing])
roles/test/tasks/main.yml:1 Jinja2 template rewrite recommendation: `{{ {
    cluster_namespace + '/' + cluster_name + '/username': hostvars.cluster_api_vsphere_username,
    cluster_namespace + '/' + cluster_name + '/password': hostvars.cluster_api_vsphere_password,
} }}`.


Finished with 0 failure(s), 1 warning(s) on 2 files.

Running ansible-lint --write makes the code less readable:

diff --git a/roles/test/tasks/main.yml b/roles/test/tasks/main.yml
index b8d293d..a218bfe 100644
--- a/roles/test/tasks/main.yml
+++ b/roles/test/tasks/main.yml
@@ -1,8 +1,7 @@
+---
 - name: Test
   ansible.builtin.debug:
     msg: "Hello: world"
   vars:
-    sealed_raw_input: "{{ {
-          cluster_namespace + '/' + cluster_name + '/username': hostvars[control_plane].cluster_api_vsphere_username,
-          cluster_namespace + '/' + cluster_name + '/password': hostvars[control_plane].cluster_api_vsphere_password,
-      } }}"
+    sealed_raw_input: "{{ { cluster_namespace + '/' + cluster_name + '/username': hostvars[control_plane].cluster_api_vsphere_username, cluster_namespace + '/' +\
+      \ cluster_name + '/password': hostvars[control_plane].cluster_api_vsphere_password, } }}"

And also add a new error:

 ansible-lint 
WARNING  Listing 2 violation(s) that are fatal
jinja: Jinja2 spacing could be improved: {{ { cluster_namespace + '/' + cluster_name + '/username': hostvars[control_plane].cluster_api_vsphere_username, cluster_namespace + '/' + cluster_name + '/password': hostvars[control_plane].cluster_api_vsphere_password, } }} -> {{ {
    cluster_namespace + '/' + cluster_name + '/username': hostvars[control_plane].cluster_api_vsphere_username,
    cluster_namespace + '/' + cluster_name + '/password': hostvars[control_plane].cluster_api_vsphere_password,
} }} (jinja[spacing])
roles/test/tasks/main.yml:2 Jinja2 template rewrite recommendation: `{{ {
    cluster_namespace + '/' + cluster_name + '/username': hostvars.cluster_api_vsphere_username,
    cluster_namespace + '/' + cluster_name + '/password': hostvars.cluster_api_vsphere_password,
} }}`.

yaml: line too long (162 > 160 characters) (yaml[line-length])
roles/test/tasks/main.yml:6

You can skip specific rules or tags by adding them to your configuration file:
# .config/ansible-lint.yml
warn_list:  # or 'skip_list' to silence them completely
  - yaml[line-length]  # Violations reported by yamllint.

Finished with 1 failure(s), 1 warning(s) on 2 files.
Issue Type
  • Bug Report
Ansible and Ansible Lint details
$ ansible --version
ansible [core 2.13.0]
  config file = None
  configured module search path = ['/home/mathieu/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/mathieu/git/gitlab.com/kubitus-project/kubitus-installer/venv/lib/python3.9/site-packages/ansible
  ansible collection location = /home/mathieu/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/mathieu/git/gitlab.com/kubitus-project/kubitus-installer/venv/bin/ansible
  python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110]
  jinja version = 3.1.2
  libyaml = True
$ ansible-lint --version
ansible-lint 6.7.0 using ansible 2.13.0
  • ansible installation method: pip (in virtualenv)
  • ansible-lint installation method: pip (in virtualenv)
@sathieu sathieu added bug new Triage required labels Sep 30, 2022
@ssbarnea ssbarnea removed the new Triage required label Sep 30, 2022
@ssbarnea
Copy link
Member

Sorry but there are no current plans to add re-wrap jinja. While @cognifloyd worked towards allowing this, we have to say that for now, we rely on humans to do the wrapping, as only they can decide where it makes more sense to split the line.

Here is a YAML hint to cut few columns:

var_name: >
  value...

Basically technically doable, but the outcomes almost always sub-par.

@ssbarnea ssbarnea closed this as not planned Won't fix, can't repro, duplicate, stale Sep 30, 2022
@sathieu
Copy link
Contributor Author

sathieu commented Sep 30, 2022

Thanks @ssbarnea I'll try this way.

rndmh3ro pushed a commit to dev-sec/ansible-collection-hardening that referenced this issue Nov 28, 2022
rndmh3ro pushed a commit to dev-sec/ansible-collection-hardening that referenced this issue Nov 28, 2022
rndmh3ro pushed a commit to dev-sec/ansible-collection-hardening that referenced this issue Nov 29, 2022
rndmh3ro pushed a commit to dev-sec/ansible-collection-hardening that referenced this issue Jan 23, 2023
rndmh3ro pushed a commit to dev-sec/ansible-collection-hardening that referenced this issue Jan 23, 2023
rndmh3ro pushed a commit to dev-sec/ansible-collection-hardening that referenced this issue Jan 23, 2023
rndmh3ro added a commit to dev-sec/ansible-collection-hardening that referenced this issue Jan 24, 2023
* linting

Signed-off-by: Sebastian Gumprich <[email protected]>

* more linting

Signed-off-by: Sebastian Gumprich <[email protected]>

* change line length issues

Signed-off-by: Sebastian Gumprich <[email protected]>

* replace yes with true in tasks

Signed-off-by: Sebastian Gumprich <[email protected]>

* use manual line-wrapping because ansible-lint does not support it correctly.

see ansible/ansible-lint#2522

* use manual line-wrapping because ansible-lint does not support it correctly.

see ansible/ansible-lint#2522

Signed-off-by: Sebastian Gumprich <[email protected]>

* use manual line-wrapping because ansible-lint does not support it correctly.

see ansible/ansible-lint#2522

Signed-off-by: Sebastian Gumprich <[email protected]>

* add exception for task

Signed-off-by: Sebastian Gumprich <[email protected]>

* remove trailing whitespace

* add back deleted params

Signed-off-by: Sebastian Gumprich <[email protected]>

* add back deleted params

Signed-off-by: Sebastian Gumprich <[email protected]>

* add back tasks

Signed-off-by: Sebastian Gumprich <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants