Update makefile, add files for variable blending tests.

pull/4889/merge
Michael DeHaan 11 years ago
parent 1489a13020
commit 1b4ba5431b

@ -3,5 +3,6 @@ all: non_destructive destructive # amazon rackspace
non_destructive:
ansible-playbook non_destructive.yml -i inventory -e @integration_config.yml -v $(TEST_FLAGS)
non_destructive:
destructive:
ansible-playbook destructive.yml -i inventory -e @integration_config.yml -v $(TEST_FLAGS)

@ -0,0 +1,9 @@
a: 999
b: 998
c: 997
d: 996
uno: 1
dos: 2
tres: 3
etest: 'from group_vars'
inventory_beats_default: 'narf'

@ -0,0 +1 @@
etest: 'from hostvars'

@ -0,0 +1,5 @@
a: 1
b: 2
c: 3
d: 4
role_var_beats_inventory: 'should_not_see_this'

@ -20,5 +20,5 @@
- { role: test_git, tags: test_git }
- { role: test_hg, tags: test_hg }
- { role: test_changed_when, tags: test_changed_when }
- { role: test_var_blending, tags: test_var_blending }
- { role: test_var_blending, parameterized_beats_default: 1234, tags: test_var_blending }

@ -0,0 +1,4 @@
etest: "from role defaults"
role_var_beats_default: "shouldn't see this"
parameterized_beats_default: "shouldn't see this"
inventory_beats_default: "shouldn't see this"

@ -0,0 +1,77 @@
The value of groups_tree_var = 4000.
This comes from host, not the parents or grandparents.
The value of the grandparent variable grandparent_var is
not overridden and is = 2000
The value of the parent variable is not overriden and
is = 6000
The variable 'overridden_in_parent' is set in the parent
and grandparent, so the parent wins. It's value is = 1000.
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 = 1
dos = 2
tres = three
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 = 1
b = 2
c = 3
d = 4
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 = coming
Here's an arbitrary variable set as vars_files in the playbook.
vars_file_var = 321
And vars.
vars = 123
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.
999
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 = from -e
Now a test to make sure role variables can override inventory variables.
role_var_beats_inventory = chevron 5 encoded
Role variables should also beat defaults.
role_var_beats_default = chevron 6 encoded
But defaults are lower priority than inventory, so inventory should win.
inventory_beats_default = narf
That's the end of the precedence tests for now, but more are welcome.

@ -0,0 +1,36 @@
# test code
# (c) 2014, Michael DeHaan <michael.dehaan@gmail.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- include_vars: more_vars.yml
- name: deploy a template that will use variables at various levels
template: src=foo.j2 dest={{output_dir}}/foo.templated
register: template_result
- name: copy known good into place
copy: src=foo.txt dest={{output_dir}}/foo.txt
- name: compare templated file to known good
shell: diff {{output_dir}}/foo.templated {{output_dir}}/foo.txt
register: diff_result
- name: verify templated file matches known good
assert:
that:
- 'diff_result.stdout == ""'

@ -0,0 +1,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 overriden 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.

@ -0,0 +1,4 @@
winter: coming
etest: 'from role vars'
role_var_beats_inventory: 'chevron 5 encoded'
role_var_beats_default: 'chevron 6 encoded'

@ -0,0 +1,5 @@
# this file is here to support testing vars_files in the blending tests only.
# in general define test data in the individual role:
# roles/role_name/vars/main.yml
vars_file_var: 321
Loading…
Cancel
Save