Skip to content
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

rules var-naming[no-role-prefix] and var-naming[pattern] collide if var_naming_pattern is changed from default #4142

Open
mhallin2 opened this issue May 8, 2024 · 2 comments
Labels
AAP Ansible Automation Platform bug

Comments

@mhallin2
Copy link

mhallin2 commented May 8, 2024

Summary

Role variable prefix does not work if var_naming_pattern: has been altered from its default.
#Bradley Thornton has requested me to create this as a bug.

If the var_naming_pattern setting in .ansible-lint.cfg file is changed from its default
and you create a role and use set_fact to set a variable
The rules var-naming[no-role-prefix] and var-naming[pattern] will collide as both scenarios can not be fulfilled

Issue Type
  • Bug Report
OS / ENVIRONMENT
ansible-lint --version
ansible-lint 24.2.3 using ansible-core:2.16.6 ansible-compat:4.1.11 ruamel-yaml:0.18.6 ruamel-yaml-clib:0.2.8
  • ansible installation method: pip
  • ansible-lint installation method: pip
STEPS TO REPRODUCE

update .ansible-lint with the below setting

var_naming_pattern: "^[A-Z_][A-Za-z0-9_]*$"

Add a variable to the role vars main.yml file

---
Register_DNS_Host_Record_Variable: dummyvalue

Run ansible-lint on the new role

ansible-lint /collections/mynamespace/network/roles/register_dns_host_record
Desired Behavior

No errors should be reported

Actual Behavior

var-naming[no-role-prefix]: Variables names from within roles should use register_dns_host_record_ as a prefix. (vars: Register_DNS_Host_Record_Variable)

@mhallin2 mhallin2 added bug new Triage required labels May 8, 2024
@Qalthos Qalthos removed the new Triage required label May 8, 2024
@Qalthos
Copy link
Contributor

Qalthos commented May 8, 2024

The var-naming[no-role-prefix] rule checks that role variables start with the role name exactly, i.e. including case. This is intentional to ensure consistency and clarity of role variables.

I can see in this case why you might want to use different casing, even if the prefix is otherwise the same, but we do not presently support this and are not planning on working on it at present. However, we do always welcome community contributions, and if you put together a PR, we will absolutely consider it.

@cidrblock
Copy link
Contributor

Let's talk about this one. I think we can expose the regex to the user.

@cidrblock cidrblock added the AAP Ansible Automation Platform label May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AAP Ansible Automation Platform bug
Projects
Status: No status
Development

No branches or pull requests

3 participants