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

var-naming[no-role-prefix] triggering for vars when used with "include_role" in 6.16.1 #3465

Closed
Rylon opened this issue May 19, 2023 · 4 comments · Fixed by #3473
Closed
Assignees
Labels

Comments

@Rylon
Copy link
Contributor

Rylon commented May 19, 2023

Summary

We have various roles that encapsulate shared functionality. We use include_role to include these shared roles in our main roles, and we pass along variables to the included role using vars, for example:

- name: Include shared role
  include_role:
    name: shared_role
  vars:
    shared_role_parameter: "a value"

In Ansible Lint 6.16.1 we're getting tons of errors for var-naming[no-role-prefix] I'm assuming because the prefix shared_role_ doesn't match the name of the role that is including the shared role or something?

The issue is not present in 6.16.0.

Issue Type
  • Bug Report
OS / ENVIRONMENT
ansible-lint 6.16.0 using ansible 2.14.5
  • ansible installation method: pip
  • ansible-lint installation method: pip
STEPS TO REPRODUCE

As described in the summary, try to include a second role from a first role, and pass role vars along.

Desired Behavior

There should be no failure detected in the linter.

Actual Behavior

The linter shows var-naming[no-role-prefix] errors for each occurrence.

@Rylon Rylon added bug new Triage required labels May 19, 2023
@drybjed
Copy link
Contributor

drybjed commented May 20, 2023

I think that this is a valid false positive which can be handled using noqa var-naming[no-role-prefix]. To fix this correctly, ansible-lint would need to check the variable against the imported role; I'm not sure if that can be done currently or is possible with current architecture. But a better solution would be welcome, of course.

@ssbarnea
Copy link
Member

It is true that in this context, the prefix should be determined not by current role, but by included role, so that is a valid bug.

@Rylon
Copy link
Contributor Author

Rylon commented May 24, 2023

Hi @ssbarnea I've tested with 6.16.2 but this error still seems present, can we re-open the issue please?

Here's an example which raises this error:

# roles/this_role/tasks/main.yml
- name: Configure DNS
  ansible.builtin.include_role:
    name: dns_record
  vars:
    dns_record_state:  "{{ this_role_state }}"
    dns_record_name:   "{{ this_role_name }}"
    dns_record_domain: "{{ this_role_domain }}"
    dns_record_value:  "{{ this_role_ip }}"

The linter returns errors:

var-naming[no-role-prefix]: Variables names from within roles should use role_name_ as a prefix. (vars: dns_record_domain)
roles/this_role/tasks/main.yml:11 Task/Handler: Configure DNS

var-naming[no-role-prefix]: Variables names from within roles should use role_name_ as a prefix. (vars: dns_record_name)
roles/this_role/tasks/main.yml:11 Task/Handler: Configure DNS

var-naming[no-role-prefix]: Variables names from within roles should use role_name_ as a prefix. (vars: dns_record_state)
roles/this_role/tasks/main.yml:11 Task/Handler: Configure DNS

var-naming[no-role-prefix]: Variables names from within roles should use role_name_ as a prefix. (vars: dns_record_value)
roles/this_role/tasks/main.yml:11 Task/Handler: Configure DNS

@drybjed
Copy link
Contributor

drybjed commented May 24, 2023

@Rylon the fix is not in a tagged release yet, currently just in the main branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants