Skip to content

Instantly share code, notes, and snippets.

@chefgs
Last active June 26, 2019 12:57
Show Gist options
  • Save chefgs/2ed3d3172bb4a6ec9e47c5a571a49998 to your computer and use it in GitHub Desktop.
Save chefgs/2ed3d3172bb4a6ec9e47c5a571a49998 to your computer and use it in GitHub Desktop.
Ansible variable precedence (order of priority) from least to greatest -

Ansible Var Precedence

Quite often, Ansible playbook developers finding it diffcult on, where to place the 'vars'. Because Ansible supports variable declaration at various levels.

Here is the order of precedence from least to greatest (the last listed variables winning prioritization):

  • command line values (eg “-u user”)
  • role defaults
  • 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)

Refer the Ansible documentation below, it provides the updated list time by time https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable

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