We’ve always been pretty consistent about prefixing all role variables with the role name followed by an underscore. For example the mw_common_zmaint
role’s server_url
variable is spelled mw_common_zmaint_server_url
.
Now we’re moving some of our “common” roles like mw_common_zmaint
into our “common collection” collection, hence the collection’s FQCN mw.cc
. We’re also dropping the mw_common_
from the stand-alone roles’ names, so this role becomes mw.cc.zmaint
.
That mw.cc
FQCN prefix works great on the collection’s plugins (modules, tests, filters, lookups, etc.), but not on variables. For example mw.cc.zmaint_server_url
, while unambiguous, is not allowed in current Ansible syntax. (I’ve suggested elsewhere that more “stuff” should use FQCNs, but that’s a stronger assertion than I’m making here.)
Given that we can’t FQCN-ify variables (yet!), the next best thing would be to prefix them unambiguously. In this case that means spelling it mw_cc_zmaint_server_url
. And that works pretty well for all concerned parties …
… except ansible-lint
, which throws the following shade:
collections/ansible_collections/mw/cc/roles/zmaint/defaults/main.yml:4: var-naming[no-role-prefix]:
Variables names from within roles should usezmaint_
as a prefix. (vars: mw_cc_zmaint_server_url
)
I’m not claiming ansible-lint
is wrong in this case. But I do think it should accept either a bare rolename_
prefix, or a more fully qualified namespace_collection_rolename_
variable prefix.