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

ansible-lint --fix munges ansible-galaxy role init meta/main.yml indentation #3941

Open
jeffmcutter opened this issue Dec 12, 2023 · 2 comments · May be fixed by ansible/ansible#82529
Open
Assignees
Labels

Comments

@jeffmcutter
Copy link

jeffmcutter commented Dec 12, 2023

Summary

If you generate an Ansible role using the ansible-galaxy role init command, it creates a default meta/main.yml file.

If you later run ansible-lint --fix against that role, it changes the comment indentation for the galaxy_tags section.

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.8
  • Fedora 39
  • ansible installation method: OS package
  • ansible-lint installation method: pip
STEPS TO REPRODUCE

ansible-galaxy role init test_role

check it into git or make a backup of meta/main.yml to diff

ansible-lint --fix test_role
git diff test_role

N/A
Desired Behavior

ansible-lint would keep the indentation of the meta/main.yml consistent.

Actual Behavior

The indentation of the comments for galaxy_tags is moved to the beginning of the line which is inconsistent with the rest of the meta/main.yml file.

diff --git i/roles/test_role4/meta/main.yml w/roles/test_role4/meta/main.yml
index c572acc..62bafb9 100644
--- i/roles/test_role4/meta/main.yml
+++ w/roles/test_role4/meta/main.yml
@@ -1,3 +1,4 @@
+---
 galaxy_info:
   author: your name
   description: your role description
@@ -40,12 +41,12 @@ galaxy_info:
   #   - 99.99
 
   galaxy_tags: []
-    # List tags for your role here, one per line. A tag is a keyword that describes
-    # and categorizes the role. Users find roles by searching for tags. Be sure to
-    # remove the '[]' above, if you add tags to this list.
-    #
-    # NOTE: A tag is limited to a single word comprised of alphanumeric characters.
-    #       Maximum 20 tags per role.
+# List tags for your role here, one per line. A tag is a keyword that describes
+# and categorizes the role. Users find roles by searching for tags. Be sure to
+# remove the '[]' above, if you add tags to this list.
+#
+# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
+#       Maximum 20 tags per role.
 
 dependencies: []
   # List your role dependencies here, one per line. Be sure to remove the '[]' above,
@jeffmcutter jeffmcutter added bug new Triage required labels Dec 12, 2023
@jeffmcutter
Copy link
Author

I opened an issue in ansible/ansible for this, initially thinking of updating the generated meta/main.yml file to be ansible-lint friendly.

ansible/ansible#82394

I'm not sure if that's viable, but I thought it was worth raising an issue here as well.

@ssbarnea ssbarnea removed the new Triage required label Dec 13, 2023
@shatakshiiii shatakshiiii self-assigned this Dec 27, 2023
@nitzmahone
Copy link
Member

nitzmahone commented Jan 15, 2024

I 100% agree that ignoring this is a substandard dev experience- if we're going to implement formatting rules, our own sample/skeleton content should probably pass it cleanly, one way or another.

That said, I assume the root cause of this issue is ruamel's invented comment-to-node mapping. Since comments are still officially not part of the YAML presentation stream (the meaty spec line there is "comments are not associated with a particular node"), ruamel's comment preservation/emission behavior defines its own extra-spec rules to make this work. IIRC, comments and whitespace-only lines on lines containing no YAML content are assumed to "belong" to the next node below them, and are thus force-aligned to that node by the emitter.

If my assumption above is correct, and we're just leaning on a round-trip through ruamel as the SoT for the ansible-lint rule in question, it makes me slightly nervous that those rules are at the whim of a non-YAML-spec implementation that's not necessarily stable. I don't really have a problem adjusting the core skeleton for this case (ala something like ansible/ansible#82529), but bigger-picture, before we completely delegate that off to ruamel, can we see if there's a reasonable way to ignore comment-only line changes in the rule (at least where there's >0 empty lines before the node it wants to align with)? The role metadata skeleton case is borderline anyway, so I don't really care about changing that one as-proposed, but there may be legitimate cases where this rule will force users to change comment indentation in ways that negatively affect readability.

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

Successfully merging a pull request may close this issue.

4 participants