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

--write mode creates problematic yaml output with multiline strings #3583

Closed
bnogaro opened this issue Jun 21, 2023 · 3 comments · Fixed by #3653
Closed

--write mode creates problematic yaml output with multiline strings #3583

bnogaro opened this issue Jun 21, 2023 · 3 comments · Fixed by #3653
Assignees
Labels
AAP Ansible Automation Platform bug critical

Comments

@bnogaro
Copy link

bnogaro commented Jun 21, 2023

Summary
Issue Type
  • Bug Report
OS / ENVIRONMENT
ansible-lint 6.17.1 using ansible-core:2.15.1 ruamel-yaml:0.17.26 ruamel-yaml-clib:0.2.7
  • ansible installation method: pip
  • ansible-lint installation method: pip
STEPS TO REPRODUCE

As a mean of complying with the yaml[line-length] rule with long strings without spaces (URL, for instance), one could do the following:

---
my_var: "
  Lorem_ipsum_dolor_sit_amet__consectetur_adipiscing_elit__Mauris_vitae_consectetur_lacus__ac_sagittis_metus__Curabitur_\
  nibh_diam__molestie_et_odio_a__volutpat_lacinia_nisi__Mauris_consequat_mi_felis__rutrum_sodales_sapien_varius_placerat
  "

This file passes all ansible-lint tests. However, running ansible-lint --write reassembles the two lines into one
This exceeds ansible-lint yaml[line-length] criterium, litterally meaning that ansible-lint --write created a ansible-lint violation.

                Rule Violation Summary                
 count tag               profile rule associated tags 
     1 yaml[line-length] basic   formatting, yaml    
Desired Behavior

Hopefully, ansible-lint --write would preserve the line-length rule, not removing the escaped newlines

Actual Behavior

The variable is rewritten on a single line, failing the test.

---
my_var: "Lorem_ipsum_dolor_sit_amet__consectetur_adipiscing_elit__Mauris_vitae_consectetur_lacus__ac_sagittis_metus__Curabitur_nibh_diam__molestie_et_odio_a__volutpat_lacinia_nisi__Mauris_consequat_mi_felis__rutrum_sodales_sapien_varius_placerat"
@bnogaro bnogaro added bug new Triage required labels Jun 21, 2023
@ssbarnea ssbarnea removed the new Triage required label Jun 21, 2023
@audgirka
Copy link
Contributor

@bnogaro we will be happy to accept a PR for it.

@bnogaro
Copy link
Author

bnogaro commented Jun 21, 2023

Before any contribution, I may need the input from a more experienced developer on this project.
As far as I understant the problem, this seems to come from the 'round-trip' functionality of ruamel.yaml, which doesn't seem to customisable in terms of max length of line in the output.
In your opinion, should it be a contribution to ruamel.yaml, or should we process the ruamel.yaml output with another tool to break long lines into multiline strings, using the yamllint configured max line length?

@shatakshiiii
Copy link
Contributor

shatakshiiii commented Aug 10, 2023

Hey @bnogaro, ruamel.yaml is not able to preserve these escaped newlines right now.
We have reported a bug for this issue: https://sourceforge.net/p/ruamel-yaml/tickets/474/

However, ruamel does support the other recommended syntax for writing multiline strings (i.e. using Block Style Indicators "|" and ">"). We are documenting this thing over here, using this ansible-lint --write will no longer collapse your multiline string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AAP Ansible Automation Platform bug critical
Projects
Status: Done
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants