ansiblelint.rules.var_naming enforce role-name as variable prefix
Summary
Allow/enable to check variable names if they have the role name as prefix
Issue Type
- Bug Report/Feature Request .. not sure
STEPS TO REPRODUCE
create the following .ansible-lint file in your role
var_naming_pattern: "^{role}__[a-z0-9_]*$"
run ansible lint and it fails telling that it "violates variable naming standards"
Desired Behavior
set a variable that represents the role name inside the var_naming_pattern (as in the documentation of loop_var_prefix: "{role}_") to enforce prefixing every variable inside the role with the role name
Actual Behavior
var-naming: File defines variable 'k8s_grafana_users__url' that violates variable naming standards
defaults/main.yml:1
Are you aware of https://github.com/ansible/ansible-lint/blob/main/.ansible-lint#L27 ?
If I am correct what you want is a new rule that would enforce roles to use only variables with unique prefixes, like role name?
If I am correct what you want is a new rule that would enforce roles to use only variables with unique prefixes, like role name?
This is exactly what I want
Has this gotten implemented? I'm hoping to use the logic that @SpikePy describes
Now experiencing this new development, first thing I added var-naming[no-role-prefix] into my skip_list right away.
I understand when it checks the variables, that you set_fact yourself, but why does it check the vars, that are needed by other roles?
- name: invoking main of some other role
ansible.builtin.include_role:
name: some_other_role
vars:
variable_some_other_role_needs: "value of the variable some other role needs"
Why ansible-lint 6.16.2 complains with var-naming[no-role-prefix] about this variable_some_other_role_needs I gave to the other role, I haven't written that some_other_role. It's someone else's role, it's their problem. I'm just providing the vars that main.yml of some_other_role needs to work.
The rule var-naming[no-role-prefix] should only check what I create by set_fact or some other means the var is born.
EDIT: Oh, this complaint exists as a bug https://github.com/ansible/ansible-lint/issues/3465