You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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)
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.
Summary
Recently we added a ansible role for common shared tasks to the prometheus ansible collection. The role is named
_common
(fqcnprometheus.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 thevar-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: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
OS / ENVIRONMENT
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
Please give some details of what is happening. Include a minimum complete
verifiable example with:
ansible-playbook --syntax-check playbook
The text was updated successfully, but these errors were encountered: