Replies: 1 comment
-
You cannot use the linter to process templated yaml files, it will open only files that are valid YAML without processing templates. Also the support for checking comments is bit limited so I would not advise writing rules that rely on them. The only exception that we currently have is that we allow using comments for silencing some rules. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When a user has the
ansible_managed
variable set to a multi-line entry,# {{ ansible_managed }}
in templates expands to theansible_managed
variable with only the first line commented out.For example, consider
ansible_managed
set to the following inansible.cfg
:In this case,
# {{ ansible_managed }}
expands to the following in the resulting config file:Because only the first line is commented, the config file reads incorrectly and services fail to start.
This must be fixed by using the
comment
filter, i.e. by using{{ ansible_managed | comment }}
. If you need a different comment sign, you can customize it, e.g.{{ "C style" | comment('c') }}
.This is described in Adding comments to files in Ansible documentation.
I tried writing an ansible-lint rule for that and faced the issue that ansible-lint skips the commented lines, i.e. my rule would find
# {{ ansible_managed }}
in the middle of the line, e.g. in the following case:- # {{ ansible_managed }}
But the rule does not work in a real-life case - when
{{ ansible_managed }}
is commented on the first line of the template.Is it possible to make ansible-lint to check commented lines? I would like to see that check in ansible-lint, but I am not that good in coding to do it myself.
Here is the simple rule I used, it is not ready, just a rule I used in my testing.
Beta Was this translation helpful? Give feedback.
All reactions