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 reports key-duplicates in EXAMPLE doc of plugins #3860
Comments
That is a genuine error as the entire EXAMPLES is no longer a valid YAML file. Still, I do not know what is the correct way to include more than one example... |
From the docs: "The DOCUMENTATION block must be valid YAML." and for the examples: "Here you show users how your module works with real-world examples in multi-line plain-text YAML format. The best examples are ready for the user to copy and paste into a playbook." This is the way I think about the examples, which is why linting them is so important, they should be cut-and-paste ready for the user. WRT the example above, that's a tricky one :) Examples are generally assumed to playbook/tasks in which case they are a list and we don't have to worry about duplicate keys. But for 2 examples of an inventory plugin, each of which is a dictionary it makes sense why it was done like it was. In this case, the error could be ignored or maybe it would pass with a yaml doc seperator between them, which is probably more accurate because these are 2 examples of the same file. (I haven't tested the doc seperator) |
@Qalthos I think that we might want to modify the current implementation to allow it to use multi-documents. What we need to do is to split the multi-document into multiple file before linting the example, that is because ansible itself does not allow loading of multi-document files. That is also opening few other questions regarding how can we guess/infer the nature of the example (file kind). I guess we could ask our users to add magic comments? The alternative is to only support tasks and playbooks and determine it based on what we find (dictionary or list). |
Is there a way to disable the rule for DOCUMENTATION and EXAMPLE only? duplicated-key is a very important rule but for those two strings, I'd disable it and forget forever |
I think that excluding the plugin file should work. |
For anyone else hitting this, if you use the document separator ( eg
unfortunately ansible-test's sanity checks then complain
|
it is not required to be YAML, |
It is still an issue for the EXAMPLES of dynamic inventory plugins. Those cant have
Error: yaml[key-duplicates]: Duplication of key "plugin" in mapping Interesting, how to avoid it... |
The yaml[key-duplicates]: Duplication of key "plugin" in mapping error was solved as @tremble said using --- between different plugin examples. But then using ansible-test sanity received: |
This is a problem with ansible-test. It's been fixed in Ansible Core 2.17 (currently in release candidate stage). |
Summary
ansible-lint 2.21.0 reports duplicate-keys inside EXAMPLE documentation of plugins
Issue Type
OS / ENVIRONMENT
STEPS TO REPRODUCE
Run ansible-lint against a plugin with the following code:
Desired Behavior
Should not report an en error
Actual Behavior
Reports an error:
yaml[key-duplicates]: Duplication of key "plugin" in mapping
https://github.com/kubevirt/kubevirt.core/actions/runs/6570606188/job/17848302926#step:6:93
The text was updated successfully, but these errors were encountered: