summaryrefslogtreecommitdiff
path: root/test/integration/targets/lookup_first_found
diff options
context:
space:
mode:
authorMatt Clay <mclay@redhat.com>2020-02-11 18:00:01 -0800
committerGitHub <noreply@github.com>2020-02-11 18:00:01 -0800
commit9788daf13b62853f04e8bc2aa3ca2b778eb186e6 (patch)
treee70f90f7d3943a1311b6fbd4a0cbd6df989bfec5 /test/integration/targets/lookup_first_found
parentcad0110228acd04196d31e258d570153b8a9040f (diff)
downloadansible-9788daf13b62853f04e8bc2aa3ca2b778eb186e6.tar.gz
Split up more lookup integration tests. (#67328)
Diffstat (limited to 'test/integration/targets/lookup_first_found')
-rw-r--r--test/integration/targets/lookup_first_found/aliases2
-rw-r--r--test/integration/targets/lookup_first_found/files/bar11
-rw-r--r--test/integration/targets/lookup_first_found/files/foo11
-rw-r--r--test/integration/targets/lookup_first_found/tasks/main.yml73
4 files changed, 77 insertions, 0 deletions
diff --git a/test/integration/targets/lookup_first_found/aliases b/test/integration/targets/lookup_first_found/aliases
new file mode 100644
index 0000000000..ed821c2754
--- /dev/null
+++ b/test/integration/targets/lookup_first_found/aliases
@@ -0,0 +1,2 @@
+shippable/posix/group2
+skip/aix
diff --git a/test/integration/targets/lookup_first_found/files/bar1 b/test/integration/targets/lookup_first_found/files/bar1
new file mode 100644
index 0000000000..5716ca5987
--- /dev/null
+++ b/test/integration/targets/lookup_first_found/files/bar1
@@ -0,0 +1 @@
+bar
diff --git a/test/integration/targets/lookup_first_found/files/foo1 b/test/integration/targets/lookup_first_found/files/foo1
new file mode 100644
index 0000000000..257cc5642c
--- /dev/null
+++ b/test/integration/targets/lookup_first_found/files/foo1
@@ -0,0 +1 @@
+foo
diff --git a/test/integration/targets/lookup_first_found/tasks/main.yml b/test/integration/targets/lookup_first_found/tasks/main.yml
new file mode 100644
index 0000000000..87f2a4045c
--- /dev/null
+++ b/test/integration/targets/lookup_first_found/tasks/main.yml
@@ -0,0 +1,73 @@
+- name: test with_first_found
+ #shell: echo {{ item }}
+ set_fact: "first_found={{ item }}"
+ with_first_found:
+ - "{{ role_path + '/files/does_not_exist' }}"
+ - "{{ role_path + '/files/foo1' }}"
+ - "{{ role_path + '/files/bar1' }}"
+
+- name: set expected
+ set_fact: first_expected="{{ role_path + '/files/foo1' }}"
+
+- name: set unexpected
+ set_fact: first_unexpected="{{ role_path + '/files/bar1' }}"
+
+- name: verify with_first_found results
+ assert:
+ that:
+ - "first_found == first_expected"
+ - "first_found != first_unexpected"
+
+- name: test q(first_found) with no files produces empty list
+ set_fact:
+ first_found_var: "{{ q('first_found', params, errors='ignore') }}"
+ vars:
+ params:
+ files: "not_a_file.yaml"
+
+- name: verify q(first_found) result
+ assert:
+ that:
+ - "first_found_var == []"
+
+- name: test lookup(first_found) with no files produces empty string
+ set_fact:
+ first_found_var: "{{ lookup('first_found', params, errors='ignore') }}"
+ vars:
+ params:
+ files: "not_a_file.yaml"
+
+- name: verify lookup(first_found) result
+ assert:
+ that:
+ - "first_found_var == ''"
+
+# NOTE: skip: True deprecated e17a2b502d6601be53c60d7ba1c627df419460c9, remove 2.12
+- name: test first_found with no matches and skip=True does nothing
+ set_fact: "this_not_set={{ item }}"
+ vars:
+ params:
+ files:
+ - not/a/file.yaml
+ - another/non/file.yaml
+ skip: True
+ loop: "{{ q('first_found', params) }}"
+
+- name: verify skip
+ assert:
+ that:
+ - "this_not_set is not defined"
+
+- name: test first_found with no matches and errors='ignore' skips in a loop
+ set_fact: "this_not_set={{ item }}"
+ vars:
+ params:
+ files:
+ - not/a/file.yaml
+ - another/non/file.yaml
+ loop: "{{ query('first_found', params, errors='ignore') }}"
+
+- name: verify errors=ignore
+ assert:
+ that:
+ - "this_not_set is not defined"