Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

  • 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
  • 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)
  • role (and include_role) params
  • include params
  • include_vars
  • set_facts / registered vars
  • extra vars (always win precedence)
@devarshgandhi1

This comment has been minimized.

Copy link

devarshgandhi1 commented Feb 27, 2018

Awesome Gist!! Very helpful.

@Elmeri

This comment has been minimized.

Copy link

Elmeri commented May 22, 2018

Good stuff

@aaronjameshorne

This comment has been minimized.

Copy link

aaronjameshorne commented Sep 20, 2018

This makes things clear now. Thanks.

@quazar0

This comment has been minimized.

Copy link

quazar0 commented Nov 7, 2018

I have seen variables in a playbooks/vars/main.yml file, where is that in the list?

@let-thomas

This comment has been minimized.

Copy link

let-thomas commented Nov 21, 2018

Well this list does not seems to fully true. In version 2.7 set_fact does not override role vars.
I.e. https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable seems to be more precise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.