summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/var_blending
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-14 20:03:01 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-14 20:03:01 +0000
commita453ac31f3428614cceb99027f8efbdb9258a40b (patch)
treef61f87408f32a8511cbd91799f9cececb53e0374 /test/integration/targets/var_blending
parentInitial commit. (diff)
downloadansible-upstream.tar.xz
ansible-upstream.zip
Adding upstream version 2.10.7+merged+base+2.10.8+dfsg.upstream/2.10.7+merged+base+2.10.8+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/integration/targets/var_blending')
-rw-r--r--test/integration/targets/var_blending/aliases1
-rw-r--r--test/integration/targets/var_blending/group_vars/all9
-rw-r--r--test/integration/targets/var_blending/group_vars/local1
-rw-r--r--test/integration/targets/var_blending/host_vars/testhost4
-rw-r--r--test/integration/targets/var_blending/inventory26
-rw-r--r--test/integration/targets/var_blending/roles/test_var_blending/defaults/main.yml4
-rw-r--r--test/integration/targets/var_blending/roles/test_var_blending/files/foo.txt77
-rw-r--r--test/integration/targets/var_blending/roles/test_var_blending/tasks/main.yml57
-rw-r--r--test/integration/targets/var_blending/roles/test_var_blending/templates/foo.j277
-rw-r--r--test/integration/targets/var_blending/roles/test_var_blending/vars/main.yml4
-rw-r--r--test/integration/targets/var_blending/roles/test_var_blending/vars/more_vars.yml3
-rwxr-xr-xtest/integration/targets/var_blending/runme.sh5
-rw-r--r--test/integration/targets/var_blending/test_var_blending.yml8
-rw-r--r--test/integration/targets/var_blending/test_vars.yml1
-rw-r--r--test/integration/targets/var_blending/vars_file.yml12
15 files changed, 289 insertions, 0 deletions
diff --git a/test/integration/targets/var_blending/aliases b/test/integration/targets/var_blending/aliases
new file mode 100644
index 00000000..b5983214
--- /dev/null
+++ b/test/integration/targets/var_blending/aliases
@@ -0,0 +1 @@
+shippable/posix/group3
diff --git a/test/integration/targets/var_blending/group_vars/all b/test/integration/targets/var_blending/group_vars/all
new file mode 100644
index 00000000..30aa3d6d
--- /dev/null
+++ b/test/integration/targets/var_blending/group_vars/all
@@ -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'
diff --git a/test/integration/targets/var_blending/group_vars/local b/test/integration/targets/var_blending/group_vars/local
new file mode 100644
index 00000000..8feb93fc
--- /dev/null
+++ b/test/integration/targets/var_blending/group_vars/local
@@ -0,0 +1 @@
+tres: 'three'
diff --git a/test/integration/targets/var_blending/host_vars/testhost b/test/integration/targets/var_blending/host_vars/testhost
new file mode 100644
index 00000000..49271aef
--- /dev/null
+++ b/test/integration/targets/var_blending/host_vars/testhost
@@ -0,0 +1,4 @@
+a: 1
+b: 2
+c: 3
+d: 4
diff --git a/test/integration/targets/var_blending/inventory b/test/integration/targets/var_blending/inventory
new file mode 100644
index 00000000..f0afb18d
--- /dev/null
+++ b/test/integration/targets/var_blending/inventory
@@ -0,0 +1,26 @@
+[local]
+testhost ansible_connection=local ansible_python_interpreter="{{ ansible_playbook_python }}"
+testhost2 ansible_connection=local # connections are never made to this host, only host vars are accessed
+
+# the following inline declarations are accompanied
+# by (preferred) group_vars/ and host_vars/ variables
+# and are used in testing of variable precedence
+
+[arbitrary_parent:children]
+local
+
+[local:vars]
+parent_var=6000
+groups_tree_var=5000
+
+[arbitrary_parent:vars]
+groups_tree_var=4000
+overridden_in_parent=1000
+
+[arbitrary_grandparent:children]
+arbitrary_parent
+
+[arbitrary_grandparent:vars]
+groups_tree_var=3000
+grandparent_var=2000
+overridden_in_parent=2000
diff --git a/test/integration/targets/var_blending/roles/test_var_blending/defaults/main.yml b/test/integration/targets/var_blending/roles/test_var_blending/defaults/main.yml
new file mode 100644
index 00000000..671a1271
--- /dev/null
+++ b/test/integration/targets/var_blending/roles/test_var_blending/defaults/main.yml
@@ -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"
diff --git a/test/integration/targets/var_blending/roles/test_var_blending/files/foo.txt b/test/integration/targets/var_blending/roles/test_var_blending/files/foo.txt
new file mode 100644
index 00000000..d51be39b
--- /dev/null
+++ b/test/integration/targets/var_blending/roles/test_var_blending/files/foo.txt
@@ -0,0 +1,77 @@
+The value of groups_tree_var = 5000.
+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 overridden 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.
+
+
+
diff --git a/test/integration/targets/var_blending/roles/test_var_blending/tasks/main.yml b/test/integration/targets/var_blending/roles/test_var_blending/tasks/main.yml
new file mode 100644
index 00000000..f2b2e54a
--- /dev/null
+++ b/test/integration/targets/var_blending/roles/test_var_blending/tasks/main.yml
@@ -0,0 +1,57 @@
+# 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
+
+- set_fact:
+ output_dir: "{{ lookup('env', 'OUTPUT_DIR') }}"
+
+- 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 == ""'
+
+- name: check debug variable with same name as var content
+ debug: var=same_value_as_var_name_var
+ register: same_value_as_var_name
+
+- name: check debug variable output when variable is undefined
+ debug: var=undefined_variable
+ register: var_undefined
+
+- assert:
+ that:
+ - "'VARIABLE IS NOT DEFINED!' in var_undefined.undefined_variable"
+ - same_value_as_var_name.same_value_as_var_name_var == 'same_value_as_var_name_var'
+
+- name: cleanup temporary template output
+ file: path={{output_dir}}/foo.templated state=absent
+
+- name: cleanup temporary copy
+ file: path={{output_dir}}/foo.txt state=absent
diff --git a/test/integration/targets/var_blending/roles/test_var_blending/templates/foo.j2 b/test/integration/targets/var_blending/roles/test_var_blending/templates/foo.j2
new file mode 100644
index 00000000..10709b1a
--- /dev/null
+++ b/test/integration/targets/var_blending/roles/test_var_blending/templates/foo.j2
@@ -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 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.
+
+
+
diff --git a/test/integration/targets/var_blending/roles/test_var_blending/vars/main.yml b/test/integration/targets/var_blending/roles/test_var_blending/vars/main.yml
new file mode 100644
index 00000000..1bb08bf8
--- /dev/null
+++ b/test/integration/targets/var_blending/roles/test_var_blending/vars/main.yml
@@ -0,0 +1,4 @@
+winter: coming
+etest: 'from role vars'
+role_var_beats_inventory: 'chevron 5 encoded'
+role_var_beats_default: 'chevron 6 encoded'
diff --git a/test/integration/targets/var_blending/roles/test_var_blending/vars/more_vars.yml b/test/integration/targets/var_blending/roles/test_var_blending/vars/more_vars.yml
new file mode 100644
index 00000000..bac93d3e
--- /dev/null
+++ b/test/integration/targets/var_blending/roles/test_var_blending/vars/more_vars.yml
@@ -0,0 +1,3 @@
+badwolf: badwolf
+
+same_value_as_var_name_var: "same_value_as_var_name_var"
diff --git a/test/integration/targets/var_blending/runme.sh b/test/integration/targets/var_blending/runme.sh
new file mode 100755
index 00000000..d0cf7f09
--- /dev/null
+++ b/test/integration/targets/var_blending/runme.sh
@@ -0,0 +1,5 @@
+#!/usr/bin/env bash
+
+set -eux
+
+ansible-playbook test_var_blending.yml -i inventory -e @test_vars.yml -v "$@"
diff --git a/test/integration/targets/var_blending/test_var_blending.yml b/test/integration/targets/var_blending/test_var_blending.yml
new file mode 100644
index 00000000..88a35b2c
--- /dev/null
+++ b/test/integration/targets/var_blending/test_var_blending.yml
@@ -0,0 +1,8 @@
+- hosts: testhost
+ vars_files:
+ - vars_file.yml
+ vars:
+ vars_var: 123
+ gather_facts: True
+ roles:
+ - { role: test_var_blending, parameterized_beats_default: 1234, tags: test_var_blending }
diff --git a/test/integration/targets/var_blending/test_vars.yml b/test/integration/targets/var_blending/test_vars.yml
new file mode 100644
index 00000000..abb71a55
--- /dev/null
+++ b/test/integration/targets/var_blending/test_vars.yml
@@ -0,0 +1 @@
+etest: 'from -e'
diff --git a/test/integration/targets/var_blending/vars_file.yml b/test/integration/targets/var_blending/vars_file.yml
new file mode 100644
index 00000000..971e16a7
--- /dev/null
+++ b/test/integration/targets/var_blending/vars_file.yml
@@ -0,0 +1,12 @@
+# 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
+
+foo: "Hello"
+things1:
+ - 1
+ - 2
+things2:
+ - "{{ foo }}"
+ - "{{ foob | default('') }}"
+vars_file_var: 321