Variable precedence
As you learned in the previous section, there are a few major types of variables that can be defined in a myriad of locations. This leads to a very important question, what happens when the same variable name is used in multiple locations? Ansible has a precedence for loading variable data, and thus it has an order and a definition to decide which variable will "win". Variable value overriding is an advanced usage of Ansible, so it is important to fully understand the semantics before attempting such a scenario.
Precedence order
Ansible defines the precedence order as follows:
- Extra vars (from command line) always win
- Connection variables defined in inventory
- Most everything else
- Rest of the variables defined in inventory
- Facts discovered ...
Get Mastering Ansible now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.