summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/templating_lookups/template_lookups
diff options
context:
space:
mode:
Diffstat (limited to 'test/integration/targets/templating_lookups/template_lookups')
-rw-r--r--test/integration/targets/templating_lookups/template_lookups/mock_lookup_plugins/77788.py6
-rw-r--r--test/integration/targets/templating_lookups/template_lookups/tasks/errors.yml31
-rw-r--r--test/integration/targets/templating_lookups/template_lookups/tasks/main.yml101
-rw-r--r--test/integration/targets/templating_lookups/template_lookups/vars/main.yml9
4 files changed, 147 insertions, 0 deletions
diff --git a/test/integration/targets/templating_lookups/template_lookups/mock_lookup_plugins/77788.py b/test/integration/targets/templating_lookups/template_lookups/mock_lookup_plugins/77788.py
new file mode 100644
index 0000000..436ceaf
--- /dev/null
+++ b/test/integration/targets/templating_lookups/template_lookups/mock_lookup_plugins/77788.py
@@ -0,0 +1,6 @@
+from ansible.plugins.lookup import LookupBase
+
+
+class LookupModule(LookupBase):
+ def run(self, terms, variables, **kwargs):
+ return {'one': 1, 'two': 2}
diff --git a/test/integration/targets/templating_lookups/template_lookups/tasks/errors.yml b/test/integration/targets/templating_lookups/template_lookups/tasks/errors.yml
new file mode 100644
index 0000000..da57631
--- /dev/null
+++ b/test/integration/targets/templating_lookups/template_lookups/tasks/errors.yml
@@ -0,0 +1,31 @@
+- name: Task that fails due to templating error for plugin option
+ debug: msg="{{ 5 / 0 | int }}"
+ ignore_errors: true
+ register: result
+
+- assert:
+ that:
+ - result.failed
+ - result.exception
+
+- name: Loop that fails due to templating error in first entry and ignores errors
+ debug: msg="{{ 5 / item }}"
+ ignore_errors: true
+ register: result
+ loop: [0, 0, 1]
+
+- debug: var=result
+
+- assert:
+ that:
+ - result.results[0].failed
+ - result.results[0].exception
+ - result.results[0].item == 0
+
+ - result.results[1].failed
+ - result.results[1].exception
+ - result.results[1].item == 0
+
+ - not result.results[2].failed
+ - result.results[2].exception is undefined
+ - result.results[2].item == 1
diff --git a/test/integration/targets/templating_lookups/template_lookups/tasks/main.yml b/test/integration/targets/templating_lookups/template_lookups/tasks/main.yml
new file mode 100644
index 0000000..430ac91
--- /dev/null
+++ b/test/integration/targets/templating_lookups/template_lookups/tasks/main.yml
@@ -0,0 +1,101 @@
+# UNICODE
+
+# https://github.com/ansible/ansible/issues/65297
+- name: get UNICODE_VAR environment var value
+ shell: "echo $UNICODE_VAR"
+ register: unicode_var_value
+
+- name: verify the UNICODE_VAR is defined
+ assert:
+ that:
+ - "unicode_var_value.stdout"
+
+- name: use env lookup to get UNICODE_VAR value
+ set_fact:
+ test_unicode_val: "{{ lookup('env', 'UNICODE_VAR') }}"
+
+- debug: var=unicode_var_value
+- debug: var=test_unicode_val
+
+- name: compare unicode values
+ assert:
+ that:
+ - "test_unicode_val == unicode_var_value.stdout"
+
+# LOOKUP TEMPLATING
+
+- name: use bare interpolation
+ debug: msg="got {{item}}"
+ with_items: "{{things1}}"
+ register: bare_var
+
+- name: verify that list was interpolated
+ assert:
+ that:
+ - "bare_var.results[0].item == 1"
+ - "bare_var.results[1].item == 2"
+
+- name: use list with bare strings in it
+ debug: msg={{item}}
+ with_items:
+ - things2
+ - things1
+
+- name: use list with undefined var in it
+ debug: msg={{item}}
+ with_items: "{{things2}}"
+ ignore_errors: True
+
+# BUG #10073 nested template handling
+
+- name: set variable that clashes
+ set_fact:
+ PATH: foobar
+
+- name: get PATH environment var value
+ set_fact:
+ known_var_value: "{{ lookup('pipe', 'echo $PATH') }}"
+
+- name: do the lookup for env PATH
+ set_fact:
+ test_val: "{{ lookup('env', 'PATH') }}"
+
+- debug: var=test_val
+
+- name: compare values
+ assert:
+ that:
+ - "test_val != ''"
+ - "test_val == known_var_value"
+
+- name: set with_dict
+ shell: echo "{{ item.key + '=' + item.value }}"
+ with_dict: "{{ mydict }}"
+
+# BUG #34144 bad template caching
+
+- name: generate two random passwords
+ set_fact:
+ password1: "{{ lookup('password', '/dev/null length=20') }}"
+ password2: "{{ lookup('password', '/dev/null length=20') }}"
+ # If the passwords are generated randomly, the chance that they
+ # coincide is neglectable (< 1e-18 assuming 120 bits of randomness
+ # per password).
+
+- name: make sure passwords are not the same
+ assert:
+ that:
+ - password1 != password2
+
+# 77788 - KeyError when wantlist=False with dict returned
+- name: Test that dicts can be parsed with wantlist false
+ set_fact:
+ dict_wantlist_true: "{{ lookup('77788', wantlist=True) }}"
+ dict_wantlist_false: "{{ lookup('77788', wantlist=False) }}"
+
+- assert:
+ that:
+ - dict_wantlist_true is mapping
+ - dict_wantlist_false is string
+
+- include_tasks: ./errors.yml
diff --git a/test/integration/targets/templating_lookups/template_lookups/vars/main.yml b/test/integration/targets/templating_lookups/template_lookups/vars/main.yml
new file mode 100644
index 0000000..4c44b1c
--- /dev/null
+++ b/test/integration/targets/templating_lookups/template_lookups/vars/main.yml
@@ -0,0 +1,9 @@
+mydict:
+ mykey1: myval1
+ mykey2: myval2
+things1:
+ - 1
+ - 2
+things2:
+ - "{{ foo }}"
+ - "{{ foob | default('') }}"