Prefixing Role and Project Variables in Ansible
Prefix role variables with the role name and project variables with a project-specific prefix.
Prefix role variables with the role name and project variables with a project-specific prefix.
Use item as the default loop variable. Reserve loop_control.loop_var for cases where item would collide across loop boundaries, such as nested loops and include_tasks.
Prefer dot notation for fixed keys. Use bracket notation only when dot notation cannot express the access safely or correctly.
Define download URLs and paths in variables instead of hardcoding them in tasks.
When targeting MS Windows hosts, use slashes for all paths. Convert to backslashes only if necessary.
Use a consistent tagging structure in Ansible roles to make playbook runs more targeted and maintainable.
Use dictionary merging deliberately and predictably in Ansible inventories to keep overrides maintainable.
Prefer short, consistent names that reduce noise without making variables or identifiers unclear.
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.