Skip to content

Instantly share code, notes, and snippets.

@ekreutz
Last active November 20, 2025 23:25
Show Gist options
  • Select an option

  • Save ekreutz/301c3d38a50abbaad38e638d8361a89e to your computer and use it in GitHub Desktop.

Select an option

Save ekreutz/301c3d38a50abbaad38e638d8361a89e to your computer and use it in GitHub Desktop.
Ansible variable precedence (order, hierarchy)

Ansible variable precedence

Source: http://docs.ansible.com/ansible/latest/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable

From least to most important

  • command line values (for example, -u my_user, these are not variables)
  • role defaults (defined in role/defaults/main.yml)
  • inventory file or script group vars
  • inventory group_vars/all
  • playbook group_vars/all
  • inventory group_vars/*
  • playbook group_vars/*
  • inventory file or script host vars
  • inventory host_vars/*
  • playbook host_vars/*
  • host facts / cached set_facts
  • play vars
  • play vars_prompt
  • play vars_files
  • role vars (defined in role/vars/main.yml)
  • block vars (only for tasks in block)
  • task vars (only for the task)
  • include_vars
  • set_facts / registered vars
  • role (and include_role) params
  • include params
  • extra vars (always win precedence)
@nasrally
Copy link

Why is everyone so happy about this gist? If anything it should make you scream and tear your hair out because your company or you have chosen an ungodly BAD tool for a task it wasn't really designed to do...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment