-
Notifications
You must be signed in to change notification settings - Fork 660
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
Add prefix checking for facts and variables #2784
Comments
Another case to consider is |
@MarkusTeufelberger You are right and I was already thinking about it. For example, I would not want to discourage uses of That would an interesting rule to write, to scan the task tree for bad usages while ignoring basic ones. Still, it would clearly help some people improve their playbook authoring skills. |
Especially problematic with |
I would love to have a rule that requires registered vars to follow some sort of pattern name, I kinda try to do this in my own code most of the time but a rule would be great. |
So this is an expansion to the COP standards. For the first one, All facts within a role should match {role_name_*} pattern, as long as you set this to be an opt_in rule I don't see an issue: For the second one, 'All inventory variables should match inv_* pattern' I don't think this is a good idea. Currently we have multiple dynamic inventory sources and the variables set by those use the plugin name not inv_ as the prefix. I think this would fall onto the latter category (see below). For the last 2, how would you know which variables fall into the categories: These really look not like standards but company conventions that would be covered in a code review process and not in ansible-lint. |
Summary
As one of our clients suggested, they would like to enforce the presence of a particular prefix for all facts they use, something like:
{role_name_*}
patterninv_*
patterncredential_*
patternsurvey_*
patternIt should be noted that this rule is closely related to one that we already have for
loop_var
prefix, where we require users to use unique variables, especially within roles.Notes
set_fact
. Still we need to add some context information, so a task would know if is part of a role (and its name) or a playbook.ini
files. Also, it will likely not work for dynamic inventories, at least initially. Still, we could use ansible-inventory output and check only this, making it work for any kind of inventory, but we will not be able to tell exactly where the non-conformance comes from. Still, would help with enforcement.In my view the example above is legit as this variable can be considered "local", so there is no real need to enforce prefixes on it.
Still, if that
vars:
would be at playbook level or even a block level, I could see more reasons to be careful with its naming.It is interesting to mention that I did not see any proposal from the customer for adding prefixes to role
vars/
anddefaults/
. I will wait for feedback and update the ticket.As usual, any feedback is welcomed.
The text was updated successfully, but these errors were encountered: