-
Notifications
You must be signed in to change notification settings - Fork 654
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 should not report var-naming[no-role-prefix] in certain situations - block variables and task variables #3544
Comments
The variables showed above (in the example role & playbook) are valid only inside task or block. I don't think they should be reported. Bare variable exported using set_fact should be reported. It's accessible later / is valid since declaration to the end of the play. The warning is not displayed for the same code, but from an included file. Such code has the same effect, variable is defined for the rest of the play. - name: Include tasks
ansible.builtin.include_tasks: include/main.yml
# include/main.yml
- name: Set fact in include
ansible.builtin.set_fact:
potentionally_bad_named_var: test ansible-playbook -i inventory/ playbook.yml
...
TASK [Debug of another set_fact var - but not reported] ************************************************************************************************************************************************************************
ok: [localhost] =>
potentionally_bad_named_var: test ## it's available
PLAY RECAP *********************************************************************************************************************************************************************************************************************
localhost : ok=11 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ansible-lint roles/ playbook.yml
WARNING Listing 2 violation(s) that are fatal
var-naming[no-role-prefix]: Variables names from within roles should use role_name_ as a prefix. (vars: some_block_internal_var)
roles/lint_test/tasks/main.yml:8 Task/Handler: Block var test
var-naming[no-role-prefix]: Variables names from within roles should use role_name_ as a prefix. (vars: temp_var)
roles/lint_test/tasks/main.yml:21 Task/Handler: Task vars
Read documentation for instructions on how to ignore specific rule violations.
Rule Violation Summary
count tag profile rule associated tags
2 var-naming[no-role-prefix] basic idiom
Failed after min profile: 2 failure(s), 0 warning(s) on 6 files. |
I agree. I have an "additional" case (just specific block var-spec) which break the rule itself:
Then, role B expects b_params to contains its params:
- debug:
var: b_params
- include_role:
name: b
var:
b_params: "Hello World !" |
@ssbarnea TYVM. 6.17.1 works for me. |
Summary
Ansible-lint (starting version 6.17) reports var-naming[no-role-prefix] issue for all role variables that are not starting with <role_name> prefix.
I don't think it's correct. Do we rally want' to prefix every single variable in the role like this. It's not throwing warning for variables created by loops (for example.)
Issue Type
OS / ENVIRONMENT
STEPS TO REPRODUCE
Desired Behavior
I think that task vars:
or block vars (technically task vars too)
should not be reported as issues.
Actual Behavior
Getting linter issues for things that should probably be ignored/skipped.
The text was updated successfully, but these errors were encountered: