Interview Prep/Ansible/Variables, Facts and Precedence

What are the naming rules for variables, and why prefix role variables?

BeginnerConceptVariables, Facts and Precedence
Answer

Names must be letters, digits and underscores, start with a letter or underscore, and must not be Python keywords or reserved names like environment, name or hosts used as play keywords. No dashes or dots.

Role variables share one global namespace per host, so prefix them with the role name (nginx_port, postgres_version) to avoid collisions. Variables meant to be private get a double prefix __nginx_pkg, which is the community convention.

All Ansible questions Roadmap: Ansible

More on Variables, Facts and Precedence