From 8a754e0858d922e955e71b253c139e071ecec432 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 18:04:21 +0200 Subject: Adding upstream version 2.14.3. Signed-off-by: Daniel Baumann --- .../integration/targets/lookup_first_found/aliases | 1 + .../targets/lookup_first_found/files/bar1 | 1 + .../targets/lookup_first_found/files/foo1 | 1 + .../lookup_first_found/files/vars file spaces.yml | 1 + .../targets/lookup_first_found/tasks/main.yml | 96 ++++++++++++++++++++++ 5 files changed, 100 insertions(+) create mode 100644 test/integration/targets/lookup_first_found/aliases create mode 100644 test/integration/targets/lookup_first_found/files/bar1 create mode 100644 test/integration/targets/lookup_first_found/files/foo1 create mode 100644 test/integration/targets/lookup_first_found/files/vars file spaces.yml create mode 100644 test/integration/targets/lookup_first_found/tasks/main.yml (limited to 'test/integration/targets/lookup_first_found') diff --git a/test/integration/targets/lookup_first_found/aliases b/test/integration/targets/lookup_first_found/aliases new file mode 100644 index 0000000..3005e4b --- /dev/null +++ b/test/integration/targets/lookup_first_found/aliases @@ -0,0 +1 @@ +shippable/posix/group4 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 0000000..5716ca5 --- /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 0000000..257cc56 --- /dev/null +++ b/test/integration/targets/lookup_first_found/files/foo1 @@ -0,0 +1 @@ +foo diff --git a/test/integration/targets/lookup_first_found/files/vars file spaces.yml b/test/integration/targets/lookup_first_found/files/vars file spaces.yml new file mode 100644 index 0000000..790bc26 --- /dev/null +++ b/test/integration/targets/lookup_first_found/files/vars file spaces.yml @@ -0,0 +1 @@ +foo: 1 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 0000000..9aeaf1d --- /dev/null +++ b/test/integration/targets/lookup_first_found/tasks/main.yml @@ -0,0 +1,96 @@ +- name: test with_first_found + set_fact: "first_found={{ item }}" + with_first_found: + - "does_not_exist" + - "foo1" + - "{{ role_path + '/files/bar1' }}" # will only hit this if dwim search is broken + +- 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" + skip: True + +- 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" + +- name: test legacy formats + set_fact: hatethisformat={{item}} + vars: + params: + files: not/a/file.yaml;hosts + paths: not/a/path:/etc + loop: "{{ q('first_found', params) }}" + +- name: verify /etc/hosts was found + assert: + that: + - "hatethisformat == '/etc/hosts'" + +- name: test spaces in names + include_vars: "{{ item }}" + with_first_found: + - files: + - "{{ role_path + '/files/vars file spaces.yml' }}" + +- assert: + that: + - foo is defined -- cgit v1.2.3