Prefixing Public, Internal, and Project Variables in Ansible
Prefix public role variables with the role name, internal role variables with __role_name_, and inventory-only variables with a project prefix.
Prefix public role variables with the role name, internal role variables with __role_name_, and inventory-only variables with a project 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.
Use loop_control.label to keep Ansible loop output short and readable when a loop iterates over dictionaries or other large values.
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.