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

ansible-lint should allow role names beginning with a underscore #4370

Open
gardar opened this issue Oct 18, 2024 · 1 comment
Open

ansible-lint should allow role names beginning with a underscore #4370

gardar opened this issue Oct 18, 2024 · 1 comment
Labels
bug new Triage required

Comments

@gardar
Copy link

gardar commented Oct 18, 2024

Summary

Recently we added a ansible role for common shared tasks to the prometheus ansible collection. The role is named _common (fqcn prometheus.prometheus._common) to distinguish it from the other roles in the collection, as it is a internal role that's only supposed to be used by the other roles and not directly by a user.

ansible-lint generates false positives for that particular role, the role-name rule and the var-naming[no-role-prefix] rule.
The error message for the var-naming[no-role-prefix] rule suggests that the variable should be named exactly like it is already named, for example:

var-naming[no-role-prefix]: Variables names from within roles should use _common_ as a prefix. (vars: _common_service_name)
var-naming[no-role-prefix]: Variables names from within roles should use _common_ as a prefix. (vars: __common_binary_basename)
Error: Variables names from within roles should use _common_ as a prefix. (vars: _common_local_cache_path)
Error: Variables names from within roles should use _common_ as a prefix. (vars: _common_binaries)
Error: Variables names from within roles should use _common_ as a prefix. (vars: _common_binary_name)
Error: Variables names from within roles should use _common_ as a prefix. (vars: _common_binary_install_dir)
Error: Variables names from within roles should use _common_ as a prefix. (vars: _common_config_dir)
Error: Variables names from within roles should use _common_ as a prefix. (vars: _common_binary_url)
Error: Variables names from within roles should use _common_ as a prefix. (vars: _common_checksums_url)

I know the Ansible docs suggest that role names should not begin with a underscore, but Ansible does not seem to have any issues with consuming a role with a name like this, and neither does ansible galaxy have any issues with importing the role. I've tested with every ansible version between 2.9 - 2.17.

Issue Type
  • Bug Report
OS / ENVIRONMENT
Run ansible/ansible-lint@main
  with:
    setup_python: true
    expected_return_code: 0
  env:
    ANSIBLE_FORCE_COLOR: true
    ANSIBLE_GALAXY_SERVER_GALAXY_URL: https://galaxy.ansible.com/
    ANSIBLE_GALAXY_SERVER_GALAXY_TIMEOUT: 120
    ANSIBLE_GALAXY_SERVER_LIST: galaxy

Using ansible-lint github action.

STEPS TO REPRODUCE
Desired Behavior

ansible-lint should allow ansible role names beginning with _. At least when they are a part of a collection, continue to disallow a _ prefix in standalone roles is probably a good idea.

Actual Behavior
role-name: Role name _common does not match ``^[a-z][a-z0-9_]*$`` pattern.
roles/_common:1
Error: Role name _common does not match ``^\[a-z]\[a-z0-9_]*$`` pattern.
var-naming[no-role-prefix]: Variables names from within roles should use _common_ as a prefix. (vars: _common_service_name)
var-naming[no-role-prefix]: Variables names from within roles should use _common_ as a prefix. (vars: __common_binary_basename)
Error: Variables names from within roles should use _common_ as a prefix. (vars: _common_local_cache_path)
Error: Variables names from within roles should use _common_ as a prefix. (vars: _common_binaries)
Error: Variables names from within roles should use _common_ as a prefix. (vars: _common_binary_name)
Error: Variables names from within roles should use _common_ as a prefix. (vars: _common_binary_install_dir)
Error: Variables names from within roles should use _common_ as a prefix. (vars: _common_config_dir)
Error: Variables names from within roles should use _common_ as a prefix. (vars: _common_binary_url)
Error: Variables names from within roles should use _common_ as a prefix. (vars: _common_checksums_url)

Please give some details of what is happening. Include a minimum complete
verifiable example
with:

  • minimized playbook to reproduce the error
  • the output of running ansible-lint including the command line used
  • if you're getting a stack trace, also the output of
    ansible-playbook --syntax-check playbook

@cavcrosby
Copy link
Contributor

I wonder if this implies that there is a bug elsewhere (e.g. docs, Galaxy), as according to the documentation, the verbiage suggests roles within a collection starting with an underscore shouldn't be able to be imported via Galaxy.

The collection import into Galaxy will fail if a role name does not comply with these rules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug new Triage required
Projects
Status: No status
Development

No branches or pull requests

2 participants