summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/var_blending/roles/test_var_blending/templates/foo.j2
blob: 10709b1adbece35ccdd6034eab5cfa5e79b0043f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
The value of groups_tree_var = {{ groups_tree_var }}.
This comes from host, not the parents or grandparents.

The value of the grandparent variable grandparent_var is
not overridden and is = {{ grandparent_var }}

The value of the parent variable is not overridden and
is = {{ parent_var }}

The variable 'overridden_in_parent' is set in the parent
and grandparent, so the parent wins.  It's value is = {{ overridden_in_parent }}.

The values of 'uno', 'dos', and 'tres' are set in group_vars/all but 'tres' is
set to the value of 'three' in group_vars/local, which should override it.

uno = {{ uno }}
dos = {{ dos }}
tres = {{ tres }}

The values of 'a', 'b', 'c', and 'd' are set in host_vars/local and should not
be clobbered by values that are also set in group_vars.

a = {{ a }}
b = {{ b }}
c = {{ c }}
d = {{ d }}

The value of 'badwolf' is set via the include_vars plugin.

badwolf = {{ badwolf }}

The value of 'winter' is set via the main.yml in the role.   

winter = {{ winter }}

Here's an arbitrary variable set as vars_files in the playbook.

vars_file_var = {{ vars_file_var }}

And vars.

vars = {{ vars_var }}

Variables about other hosts can be looked up via hostvars.  This includes
facts but here we'll just access a variable defined in the groups.

{{ hostvars['testhost2']['a'] }}

Ansible has pretty basic precedence rules for variable overriding. We already have
some tests above about group order.  Here are a few more.

   * -e variables always win
   * then comes "most everything else"
   * then comes variables defined in inventory
   * then "role defaults", which are the most "defaulty" and lose in priority to everything.

Given the above rules, here's a test that a -e variable overrides inventory, 
and also defaults, and role vars.

etest = {{ etest }}

Now a test to make sure role variables can override inventory variables.

role_var_beats_inventory = {{ role_var_beats_inventory }}

Role variables should also beat defaults.

role_var_beats_default = {{ role_var_beats_default }}

But defaults are lower priority than inventory, so inventory should win.

inventory_beats_default = {{ inventory_beats_default }}

That's the end of the precedence tests for now, but more are welcome.