Role var/param naming (prefix)

I was converting one of my playbooks into a collection to utilize galaxy instead of manual source control for swift deployment when realized that var prefix is not enforced anymore. Since this is now a collection, it makes sense to allow correct usage outside of my playbooks. But I am not sure if I should add prefixes to all role vars (params) or keep current layout Am I getting this right that now variables supplied as parameters to a role would resolve possible collisions since role params would have higher priority?

current state (role example) charlesrocket.freebsd.desktop role – Deploys desktop tunings — charlesrocket.freebsd Ansible collection documentation

Back in the days I would append prefix as I did with dotfiles role (in another collection) and linter would agree but things seems to be different now and I can’t find any relative documentation with active links.

current var usage (playbook): https://github.com/charlesrocket/freebsd-collection/blob/trunk/profiles/charlesrocket/station.yml

I thought the linter would help to clear things out but I can not make it to complain on the topic no matter what I do :grinning: - like it does not care anymore about var prefixes.

1 Like

I’ve whined about this but from the other side. That is, I want Fully Qualified Variable Names (FQVN), not just prefixed with the role name. The fact that I have three distinct roles with the same name - one stand-alone and two in collections - makes a role-only prefix not particularly helpful. (It wasn’t my idea! I just implemented 'em, honest!)

ansible-lint will complain if you pass un-prefixed variables in a vars section of an include_role task. But it can’t really complain about a role using variables that aren’t prefixed; it has no way of knowing if those variables are unique to the role or if they come from elsewhere (I’m guessing).

I think @evgeni also mentioned something like that not too long ago, IIRC on Matrix, for the Foreman collection. There the role names are short and somewhat generic (foreman-ansible-modules/roles at develop · theforeman/foreman-ansible-modules · GitHub) and you don’t want just these as a prefix. In case of the Foreman collection, all var names start with foreman_ (or __foreman_ for private vars), so a first solution (instead of using # noqa) was to set var_naming_pattern: foreman-ansible-modules/.ansible-lint at develop · theforeman/foreman-ansible-modules · GitHub

1 Like

Yeah. Just be aware that var-naming[pattern] is not free of issues either:

2 Likes