diff options
author | Matt Clay <mclay@redhat.com> | 2020-02-11 01:41:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-11 01:41:45 +0100 |
commit | 89c8eb5a085552b544c4da9b1c1f272b645c64d9 (patch) | |
tree | b4b60c5c435e52aa1c83befec8f13886bea3b88c /test/integration/targets | |
parent | ansible-test - add constraint for virtualenv (#67289) (diff) | |
download | ansible-89c8eb5a085552b544c4da9b1c1f272b645c64d9.tar.xz ansible-89c8eb5a085552b544c4da9b1c1f272b645c64d9.zip |
Split up lookup integration tests. (#67294)
* Split up lookup integration tests.
* Rename lookup_paths integration test.
This will avoid confusing it for a test of the `paths` lookup plugin, which does not exist.
* Fix lookup_pipe integration test.
The test now verifies it receives the correct output.
Adding a second task also causes code coverage to be properly registered for the lookup plugin.
* Rename ini lookup test to match plugin name.
* Update sanity ignore path.
Diffstat (limited to 'test/integration/targets')
47 files changed, 340 insertions, 348 deletions
diff --git a/test/integration/targets/lookup_cartesian/aliases b/test/integration/targets/lookup_cartesian/aliases new file mode 100644 index 0000000000..f8e28c7e46 --- /dev/null +++ b/test/integration/targets/lookup_cartesian/aliases @@ -0,0 +1,2 @@ +shippable/posix/group1 +skip/aix diff --git a/test/integration/targets/lookup_cartesian/tasks/main.yml b/test/integration/targets/lookup_cartesian/tasks/main.yml new file mode 100644 index 0000000000..3624d58948 --- /dev/null +++ b/test/integration/targets/lookup_cartesian/tasks/main.yml @@ -0,0 +1,19 @@ +- name: Test cartesian lookup + debug: var=item + with_cartesian: + - ["A", "B", "C"] + - ["1", "2", "3"] + register: product + +- name: Verify cartesian lookup + assert: + that: + - product.results[0]['item'] == ["A", "1"] + - product.results[1]['item'] == ["A", "2"] + - product.results[2]['item'] == ["A", "3"] + - product.results[3]['item'] == ["B", "1"] + - product.results[4]['item'] == ["B", "2"] + - product.results[5]['item'] == ["B", "3"] + - product.results[6]['item'] == ["C", "1"] + - product.results[7]['item'] == ["C", "2"] + - product.results[8]['item'] == ["C", "3"] diff --git a/test/integration/targets/lookup_env/aliases b/test/integration/targets/lookup_env/aliases new file mode 100644 index 0000000000..f8e28c7e46 --- /dev/null +++ b/test/integration/targets/lookup_env/aliases @@ -0,0 +1,2 @@ +shippable/posix/group1 +skip/aix diff --git a/test/integration/targets/lookup_env/tasks/main.yml b/test/integration/targets/lookup_env/tasks/main.yml new file mode 100644 index 0000000000..daaeb35f40 --- /dev/null +++ b/test/integration/targets/lookup_env/tasks/main.yml @@ -0,0 +1,15 @@ +- name: get HOME environment var value + shell: "echo $HOME" + register: home_var_value + +- name: use env lookup to get HOME var + set_fact: + test_val: "{{ lookup('env', 'HOME') }}" + +- debug: var=home_var_value.stdout +- debug: var=test_val + +- name: compare values + assert: + that: + - "test_val == home_var_value.stdout" diff --git a/test/integration/targets/lookup_file/aliases b/test/integration/targets/lookup_file/aliases new file mode 100644 index 0000000000..f8e28c7e46 --- /dev/null +++ b/test/integration/targets/lookup_file/aliases @@ -0,0 +1,2 @@ +shippable/posix/group1 +skip/aix diff --git a/test/integration/targets/lookup_file/tasks/main.yml b/test/integration/targets/lookup_file/tasks/main.yml new file mode 100644 index 0000000000..a6d636db88 --- /dev/null +++ b/test/integration/targets/lookup_file/tasks/main.yml @@ -0,0 +1,13 @@ +- name: make a new file to read + copy: dest={{output_dir}}/foo.txt mode=0644 content="bar" + +- name: load the file as a fact + set_fact: + foo: "{{ lookup('file', output_dir + '/foo.txt' ) }}" + +- debug: var=foo + +- name: verify file lookup + assert: + that: + - "foo == 'bar'" diff --git a/test/integration/targets/lookup_paths/aliases b/test/integration/targets/lookup_ini/aliases index b59832142f..b59832142f 100644 --- a/test/integration/targets/lookup_paths/aliases +++ b/test/integration/targets/lookup_ini/aliases diff --git a/test/integration/targets/lookup_properties/lookup-8859-15.ini b/test/integration/targets/lookup_ini/lookup-8859-15.ini index 33f9c29d18..33f9c29d18 100644 --- a/test/integration/targets/lookup_properties/lookup-8859-15.ini +++ b/test/integration/targets/lookup_ini/lookup-8859-15.ini diff --git a/test/integration/targets/lookup_properties/lookup.ini b/test/integration/targets/lookup_ini/lookup.ini index 5b7cc34b55..5b7cc34b55 100644 --- a/test/integration/targets/lookup_properties/lookup.ini +++ b/test/integration/targets/lookup_ini/lookup.ini diff --git a/test/integration/targets/lookup_properties/lookup.properties b/test/integration/targets/lookup_ini/lookup.properties index d71ce1217b..d71ce1217b 100644 --- a/test/integration/targets/lookup_properties/lookup.properties +++ b/test/integration/targets/lookup_ini/lookup.properties diff --git a/test/integration/targets/lookup_properties/runme.sh b/test/integration/targets/lookup_ini/runme.sh index 71a507de42..71a507de42 100755 --- a/test/integration/targets/lookup_properties/runme.sh +++ b/test/integration/targets/lookup_ini/runme.sh diff --git a/test/integration/targets/lookup_properties/test_lookup_properties.yml b/test/integration/targets/lookup_ini/test_lookup_properties.yml index a8cad9de48..a8cad9de48 100644 --- a/test/integration/targets/lookup_properties/test_lookup_properties.yml +++ b/test/integration/targets/lookup_ini/test_lookup_properties.yml diff --git a/test/integration/targets/lookup_password/aliases b/test/integration/targets/lookup_password/aliases new file mode 100644 index 0000000000..f8e28c7e46 --- /dev/null +++ b/test/integration/targets/lookup_password/aliases @@ -0,0 +1,2 @@ +shippable/posix/group1 +skip/aix diff --git a/test/integration/targets/lookup_password/runme.sh b/test/integration/targets/lookup_password/runme.sh new file mode 100755 index 0000000000..a3637a7e22 --- /dev/null +++ b/test/integration/targets/lookup_password/runme.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -eux + +source virtualenv.sh + +# Requirements have to be installed prior to running ansible-playbook +# because plugins and requirements are loaded before the task runs +pip install passlib + +ANSIBLE_ROLES_PATH=../ ansible-playbook runme.yml -e "output_dir=${OUTPUT_DIR}" "$@" diff --git a/test/integration/targets/lookup_password/runme.yml b/test/integration/targets/lookup_password/runme.yml new file mode 100644 index 0000000000..4f55c1da85 --- /dev/null +++ b/test/integration/targets/lookup_password/runme.yml @@ -0,0 +1,4 @@ +- hosts: localhost + gather_facts: no + roles: + - { role: lookup_password } diff --git a/test/integration/targets/lookup_password/tasks/main.yml b/test/integration/targets/lookup_password/tasks/main.yml new file mode 100644 index 0000000000..4eeef151f8 --- /dev/null +++ b/test/integration/targets/lookup_password/tasks/main.yml @@ -0,0 +1,104 @@ +- name: create a password file + set_fact: + newpass: "{{ lookup('password', output_dir + '/lookup/password length=8') }}" + +- name: stat the password file directory + stat: path="{{output_dir}}/lookup" + register: result + +- name: assert the directory's permissions + assert: + that: + - result.stat.mode == '0700' + +- name: stat the password file + stat: path="{{output_dir}}/lookup/password" + register: result + +- name: assert the directory's permissions + assert: + that: + - result.stat.mode == '0600' + +- name: get password length + shell: wc -c {{output_dir}}/lookup/password | awk '{print $1}' + register: wc_result + +- debug: var=wc_result.stdout + +- name: read password + shell: cat {{output_dir}}/lookup/password + register: cat_result + +- debug: var=cat_result.stdout + +- name: verify password + assert: + that: + - "wc_result.stdout == '9'" + - "cat_result.stdout == newpass" + - "' salt=' not in cat_result.stdout" + +- name: fetch password from an existing file + set_fact: + pass2: "{{ lookup('password', output_dir + '/lookup/password length=8') }}" + +- name: read password (again) + shell: cat {{output_dir}}/lookup/password + register: cat_result2 + +- debug: var=cat_result2.stdout + +- name: verify password (again) + assert: + that: + - "cat_result2.stdout == newpass" + - "' salt=' not in cat_result2.stdout" + + + +- name: create a password (with salt) file + debug: msg={{ lookup('password', output_dir + '/lookup/password_with_salt encrypt=sha256_crypt') }} + +- name: read password and salt + shell: cat {{output_dir}}/lookup/password_with_salt + register: cat_pass_salt + +- debug: var=cat_pass_salt.stdout + +- name: fetch unencrypted password + set_fact: + newpass: "{{ lookup('password', output_dir + '/lookup/password_with_salt') }}" + +- debug: var=newpass + +- name: verify password and salt + assert: + that: + - "cat_pass_salt.stdout != newpass" + - "cat_pass_salt.stdout.startswith(newpass)" + - "' salt=' in cat_pass_salt.stdout" + - "' salt=' not in newpass" + + +- name: fetch unencrypted password (using empty encrypt parameter) + set_fact: + newpass2: "{{ lookup('password', output_dir + '/lookup/password_with_salt encrypt=') }}" + +- name: verify lookup password behavior + assert: + that: + - "newpass == newpass2" + +- name: verify that we can generate a 1st password without writing it + set_fact: + newpass: "{{ lookup('password', '/dev/null') }}" + +- name: verify that we can generate a 2nd password without writing it + set_fact: + newpass2: "{{ lookup('password', '/dev/null') }}" + +- name: verify lookup password behavior with /dev/null + assert: + that: + - "newpass != newpass2" diff --git a/test/integration/targets/lookup_pipe/aliases b/test/integration/targets/lookup_pipe/aliases new file mode 100644 index 0000000000..f8e28c7e46 --- /dev/null +++ b/test/integration/targets/lookup_pipe/aliases @@ -0,0 +1,2 @@ +shippable/posix/group1 +skip/aix diff --git a/test/integration/targets/lookup_pipe/tasks/main.yml b/test/integration/targets/lookup_pipe/tasks/main.yml new file mode 100644 index 0000000000..8aa1bc64e2 --- /dev/null +++ b/test/integration/targets/lookup_pipe/tasks/main.yml @@ -0,0 +1,9 @@ +# https://github.com/ansible/ansible/issues/6550 +- name: confirm pipe lookup works with a single positional arg + set_fact: + result: "{{ lookup('pipe', 'echo $OUTPUT_DIR') }}" + +- name: verify the expected output was received + assert: + that: + - "result == output_dir" diff --git a/test/integration/targets/lookup_template/aliases b/test/integration/targets/lookup_template/aliases new file mode 100644 index 0000000000..f8e28c7e46 --- /dev/null +++ b/test/integration/targets/lookup_template/aliases @@ -0,0 +1,2 @@ +shippable/posix/group1 +skip/aix diff --git a/test/integration/targets/lookup_template/tasks/main.yml b/test/integration/targets/lookup_template/tasks/main.yml new file mode 100644 index 0000000000..df11576654 --- /dev/null +++ b/test/integration/targets/lookup_template/tasks/main.yml @@ -0,0 +1,19 @@ +# ref #18526 +- name: Test that we have a proper jinja search path in template lookup + set_fact: + hello_world: "{{ lookup('template', 'hello.txt') }}" + +- assert: + that: + - "hello_world|trim == 'Hello world!'" + + +- name: Test that we have a proper jinja search path in template lookup with different variable start and end string + vars: + my_var: world + set_fact: + hello_world_string: "{{ lookup('template', 'hello_string.txt', variable_start_string='[%', variable_end_string='%]') }}" + +- assert: + that: + - "hello_world_string|trim == 'Hello world!'" diff --git a/test/integration/targets/lookups/templates/hello.txt b/test/integration/targets/lookup_template/templates/hello.txt index be15a4f333..be15a4f333 100644 --- a/test/integration/targets/lookups/templates/hello.txt +++ b/test/integration/targets/lookup_template/templates/hello.txt diff --git a/test/integration/targets/lookups/templates/hello_string.txt b/test/integration/targets/lookup_template/templates/hello_string.txt index 75199afd56..75199afd56 100644 --- a/test/integration/targets/lookups/templates/hello_string.txt +++ b/test/integration/targets/lookup_template/templates/hello_string.txt diff --git a/test/integration/targets/lookups/templates/world.txt b/test/integration/targets/lookup_template/templates/world.txt index cc628ccd10..cc628ccd10 100644 --- a/test/integration/targets/lookups/templates/world.txt +++ b/test/integration/targets/lookup_template/templates/world.txt diff --git a/test/integration/targets/lookups/aliases b/test/integration/targets/lookup_url/aliases index 1a9a4facbc..1a9a4facbc 100644 --- a/test/integration/targets/lookups/aliases +++ b/test/integration/targets/lookup_url/aliases diff --git a/test/integration/targets/lookups/meta/main.yml b/test/integration/targets/lookup_url/meta/main.yml index 8169f34744..374b5fdf25 100644 --- a/test/integration/targets/lookups/meta/main.yml +++ b/test/integration/targets/lookup_url/meta/main.yml @@ -1,3 +1,2 @@ dependencies: - - prepare_tests - prepare_http_tests diff --git a/test/integration/targets/lookup_url/tasks/main.yml b/test/integration/targets/lookup_url/tasks/main.yml new file mode 100644 index 0000000000..4eaa32e076 --- /dev/null +++ b/test/integration/targets/lookup_url/tasks/main.yml @@ -0,0 +1,28 @@ +- name: Test that retrieving a url works + set_fact: + web_data: "{{ lookup('url', 'https://gist.githubusercontent.com/abadger/9858c22712f62a8effff/raw/43dd47ea691c90a5fa7827892c70241913351963/test') }}" + +- name: Assert that the url was retrieved + assert: + that: + - "'one' in web_data" + +- name: Test that retrieving a url with invalid cert fails + set_fact: + web_data: "{{ lookup('url', 'https://{{ badssl_host }}/') }}" + ignore_errors: True + register: url_invalid_cert + +- assert: + that: + - "url_invalid_cert.failed" + - "'Error validating the server' in url_invalid_cert.msg or 'Hostname mismatch' in url_invalid_cert.msg or ( url_invalid_cert.msg is search('hostname .* doesn.t match .*'))" + +- name: Test that retrieving a url with invalid cert with validate_certs=False works + set_fact: + web_data: "{{ lookup('url', 'https://{{ badssl_host }}/', validate_certs=False) }}" + register: url_no_validate_cert + +- assert: + that: + - "'{{ badssl_host_substring }}' in web_data" diff --git a/test/integration/targets/lookup_vars/aliases b/test/integration/targets/lookup_vars/aliases new file mode 100644 index 0000000000..f8e28c7e46 --- /dev/null +++ b/test/integration/targets/lookup_vars/aliases @@ -0,0 +1,2 @@ +shippable/posix/group1 +skip/aix diff --git a/test/integration/targets/lookup_vars/tasks/main.yml b/test/integration/targets/lookup_vars/tasks/main.yml new file mode 100644 index 0000000000..f24d8657ad --- /dev/null +++ b/test/integration/targets/lookup_vars/tasks/main.yml @@ -0,0 +1,16 @@ +- name: Test that we can give it a single value and receive a single value + set_fact: + var_host: '{{ lookup("vars", "ansible_host") }}' + +- assert: + that: + - 'var_host == ansible_host' + +- name: Test that we can give a list of values to var and receive a list of values back + set_fact: + var_host_info: '{{ query("vars", "ansible_host", "ansible_connection") }}' + +- assert: + that: + - 'var_host_info[0] == ansible_host' + - 'var_host_info[1] == ansible_connection' diff --git a/test/integration/targets/lookups/lookups.yml b/test/integration/targets/lookups/lookups.yml deleted file mode 100644 index b50d63c044..0000000000 --- a/test/integration/targets/lookups/lookups.yml +++ /dev/null @@ -1,4 +0,0 @@ -- hosts: localhost - gather_facts: yes - roles: - - { role: lookups } diff --git a/test/integration/targets/lookups/runme.sh b/test/integration/targets/lookups/runme.sh deleted file mode 100755 index 59015bee74..0000000000 --- a/test/integration/targets/lookups/runme.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash - -set -eux - -source virtualenv.sh - -# Requirements have to be installed prior to running ansible-playbook -# because plugins and requirements are loaded before the task runs -pip install passlib - -# UNICODE_VAR is used in testing the env lookup plugin unicode functionality -ANSIBLE_ROLES_PATH=../ UNICODE_VAR=café ansible-playbook lookups.yml "$@" - -ansible-playbook template_lookup_vaulted.yml --vault-password-file test_vault_pass "$@" - -ansible-playbook -i template_deepcopy/hosts template_deepcopy/playbook.yml "$@" diff --git a/test/integration/targets/lookups/tasks/main.yml b/test/integration/targets/lookups/tasks/main.yml deleted file mode 100644 index faa051c3ed..0000000000 --- a/test/integration/targets/lookups/tasks/main.yml +++ /dev/null @@ -1,327 +0,0 @@ -# test code for lookup plugins -# Copyright: (c) 2014, James Tanner <tanner.jc@gmail.com> -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -# FILE LOOKUP - -- set_fact: - output_dir: "{{ lookup('env', 'OUTPUT_DIR') }}" - -- name: make a new file to read - copy: dest={{output_dir}}/foo.txt mode=0644 content="bar" - -- name: load the file as a fact - set_fact: - foo: "{{ lookup('file', output_dir + '/foo.txt' ) }}" - -- debug: var=foo - -- name: verify file lookup - assert: - that: - - "foo == 'bar'" - - -# PASSWORD LOOKUP - -- name: remove previous password files and directory - file: dest={{item}} state=absent - with_items: - - "{{output_dir}}/lookup/password" - - "{{output_dir}}/lookup/password_with_salt" - - "{{output_dir}}/lookup" - -- name: create a password file - set_fact: - newpass: "{{ lookup('password', output_dir + '/lookup/password length=8') }}" - -- name: stat the password file directory - stat: path="{{output_dir}}/lookup" - register: result - -- name: assert the directory's permissions - assert: - that: - - result.stat.mode == '0700' - -- name: stat the password file - stat: path="{{output_dir}}/lookup/password" - register: result - -- name: assert the directory's permissions - assert: - that: - - result.stat.mode == '0600' - -- name: get password length - shell: wc -c {{output_dir}}/lookup/password | awk '{print $1}' - register: wc_result - -- debug: var=wc_result.stdout - -- name: read password - shell: cat {{output_dir}}/lookup/password - register: cat_result - -- debug: var=cat_result.stdout - -- name: verify password - assert: - that: - - "wc_result.stdout == '9'" - - "cat_result.stdout == newpass" - - "' salt=' not in cat_result.stdout" - -- name: fetch password from an existing file - set_fact: - pass2: "{{ lookup('password', output_dir + '/lookup/password length=8') }}" - -- name: read password (again) - shell: cat {{output_dir}}/lookup/password - register: cat_result2 - -- debug: var=cat_result2.stdout - -- name: verify password (again) - assert: - that: - - "cat_result2.stdout == newpass" - - "' salt=' not in cat_result2.stdout" - - - -- name: create a password (with salt) file - debug: msg={{ lookup('password', output_dir + '/lookup/password_with_salt encrypt=sha256_crypt') }} - -- name: read password and salt - shell: cat {{output_dir}}/lookup/password_with_salt - register: cat_pass_salt - -- debug: var=cat_pass_salt.stdout - -- name: fetch unencrypted password - set_fact: - newpass: "{{ lookup('password', output_dir + '/lookup/password_with_salt') }}" - -- debug: var=newpass - -- name: verify password and salt - assert: - that: - - "cat_pass_salt.stdout != newpass" - - "cat_pass_salt.stdout.startswith(newpass)" - - "' salt=' in cat_pass_salt.stdout" - - "' salt=' not in newpass" - - -- name: fetch unencrypted password (using empty encrypt parameter) - set_fact: - newpass2: "{{ lookup('password', output_dir + '/lookup/password_with_salt encrypt=') }}" - -- name: verify lookup password behavior - assert: - that: - - "newpass == newpass2" - -- name: verify that we can generate a 1st password without writing it - set_fact: - newpass: "{{ lookup('password', '/dev/null') }}" - -- name: verify that we can generate a 2nd password without writing it - set_fact: - newpass2: "{{ lookup('password', '/dev/null') }}" - -- name: verify lookup password behavior with /dev/null - assert: - that: - - "newpass != newpass2" - -# ENV LOOKUP - -- name: get HOME environment var value - shell: "echo $HOME" - register: home_var_value - -- name: use env lookup to get HOME var - set_fact: - test_val: "{{ lookup('env', 'HOME') }}" - -- debug: var=home_var_value.stdout -- debug: var=test_val - -- name: compare values - assert: - that: - - "test_val == home_var_value.stdout" - -# UNICODE LOOKUP - -# https://github.com/ansible/ansible/issues/65297 -- name: get UNICODE_VAR environment var value - shell: "echo $UNICODE_VAR" - register: unicode_var_value - -- 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" - - -# PIPE LOOKUP - -# https://github.com/ansible/ansible/issues/6550 -- name: confirm pipe lookup works with a single positional arg - debug: msg="{{ lookup('pipe', 'ls') }}" - - -# 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 }}" - -# URL Lookups - -- name: Test that retrieving a url works - set_fact: - web_data: "{{ lookup('url', 'https://gist.githubusercontent.com/abadger/9858c22712f62a8effff/raw/43dd47ea691c90a5fa7827892c70241913351963/test') }}" - -- name: Assert that the url was retrieved - assert: - that: - - "'one' in web_data" - -- name: Test that retrieving a url with invalid cert fails - set_fact: - web_data: "{{ lookup('url', 'https://{{ badssl_host }}/') }}" - ignore_errors: True - register: url_invalid_cert - -- assert: - that: - - "url_invalid_cert.failed" - - "'Error validating the server' in url_invalid_cert.msg or 'Hostname mismatch' in url_invalid_cert.msg or ( url_invalid_cert.msg is search('hostname .* doesn.t match .*'))" - -- name: Test that retrieving a url with invalid cert with validate_certs=False works - set_fact: - web_data: "{{ lookup('url', 'https://{{ badssl_host }}/', validate_certs=False) }}" - register: url_no_validate_cert - -- assert: - that: - - "'{{ badssl_host_substring }}' in web_data" - -- name: Test cartesian lookup - debug: var=item - with_cartesian: - - ["A", "B", "C"] - - ["1", "2", "3"] - register: product - -- name: Verify cartesian lookup - assert: - that: - - product.results[0]['item'] == ["A", "1"] - - product.results[1]['item'] == ["A", "2"] - - product.results[2]['item'] == ["A", "3"] - - product.results[3]['item'] == ["B", "1"] - - product.results[4]['item'] == ["B", "2"] - - product.results[5]['item'] == ["B", "3"] - - product.results[6]['item'] == ["C", "1"] - - product.results[7]['item'] == ["C", "2"] - - product.results[8]['item'] == ["C", "3"] - -# Template lookups - -# ref #18526 -- name: Test that we have a proper jinja search path in template lookup - set_fact: - hello_world: "{{ lookup('template', 'hello.txt') }}" - -- assert: - that: - - "hello_world|trim == 'Hello world!'" - - -- name: Test that we have a proper jinja search path in template lookup with different variable start and end string - vars: - my_var: world - set_fact: - hello_world_string: "{{ lookup('template', 'hello_string.txt', variable_start_string='[%', variable_end_string='%]') }}" - -- assert: - that: - - "hello_world_string|trim == 'Hello world!'" - -# Vars lookups - -- name: Test that we can give it a single value and receive a single value - set_fact: - var_host: '{{ lookup("vars", "ansible_host") }}' - -- assert: - that: - - 'var_host == ansible_host' - -- name: Test that we can give a list of values to var and receive a list of values back - set_fact: - var_host_info: '{{ query("vars", "ansible_host", "ansible_connection") }}' - -- assert: - that: - - 'var_host_info[0] == ansible_host' - - 'var_host_info[1] == ansible_connection' diff --git a/test/integration/targets/lookup_properties/aliases b/test/integration/targets/path_lookups/aliases index b59832142f..b59832142f 100644 --- a/test/integration/targets/lookup_properties/aliases +++ b/test/integration/targets/path_lookups/aliases diff --git a/test/integration/targets/lookup_paths/play.yml b/test/integration/targets/path_lookups/play.yml index 7321589bf9..7321589bf9 100644 --- a/test/integration/targets/lookup_paths/play.yml +++ b/test/integration/targets/path_lookups/play.yml diff --git a/test/integration/targets/lookup_paths/roles/showfile/tasks/main.yml b/test/integration/targets/path_lookups/roles/showfile/tasks/main.yml index 1b3805798d..1b3805798d 100644 --- a/test/integration/targets/lookup_paths/roles/showfile/tasks/main.yml +++ b/test/integration/targets/path_lookups/roles/showfile/tasks/main.yml diff --git a/test/integration/targets/lookup_paths/runme.sh b/test/integration/targets/path_lookups/runme.sh index 754150b4c7..754150b4c7 100755 --- a/test/integration/targets/lookup_paths/runme.sh +++ b/test/integration/targets/path_lookups/runme.sh diff --git a/test/integration/targets/lookup_paths/testplay.yml b/test/integration/targets/path_lookups/testplay.yml index 8bf4553275..8bf4553275 100644 --- a/test/integration/targets/lookup_paths/testplay.yml +++ b/test/integration/targets/path_lookups/testplay.yml diff --git a/test/integration/targets/templating_lookups/aliases b/test/integration/targets/templating_lookups/aliases new file mode 100644 index 0000000000..f8e28c7e46 --- /dev/null +++ b/test/integration/targets/templating_lookups/aliases @@ -0,0 +1,2 @@ +shippable/posix/group1 +skip/aix diff --git a/test/integration/targets/templating_lookups/runme.sh b/test/integration/targets/templating_lookups/runme.sh new file mode 100755 index 0000000000..3ddca11cca --- /dev/null +++ b/test/integration/targets/templating_lookups/runme.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +set -eux + +ANSIBLE_ROLES_PATH=../ UNICODE_VAR=café ansible-playbook runme.yml "$@" + +ansible-playbook template_lookup_vaulted/playbook.yml --vault-password-file template_lookup_vaulted/test_vault_pass "$@" + +ansible-playbook template_deepcopy/playbook.yml -i template_deepcopy/hosts "$@" diff --git a/test/integration/targets/templating_lookups/runme.yml b/test/integration/targets/templating_lookups/runme.yml new file mode 100644 index 0000000000..85328d2e98 --- /dev/null +++ b/test/integration/targets/templating_lookups/runme.yml @@ -0,0 +1,4 @@ +- hosts: localhost + gather_facts: no + roles: + - { role: templating_lookups } diff --git a/test/integration/targets/lookups/template_deepcopy/hosts b/test/integration/targets/templating_lookups/template_deepcopy/hosts index ecd3b9665b..ecd3b9665b 100644 --- a/test/integration/targets/lookups/template_deepcopy/hosts +++ b/test/integration/targets/templating_lookups/template_deepcopy/hosts diff --git a/test/integration/targets/lookups/template_deepcopy/playbook.yml b/test/integration/targets/templating_lookups/template_deepcopy/playbook.yml index da55c16752..da55c16752 100644 --- a/test/integration/targets/lookups/template_deepcopy/playbook.yml +++ b/test/integration/targets/templating_lookups/template_deepcopy/playbook.yml diff --git a/test/integration/targets/lookups/template_deepcopy/template.in b/test/integration/targets/templating_lookups/template_deepcopy/template.in index 77de0adf82..77de0adf82 100644 --- a/test/integration/targets/lookups/template_deepcopy/template.in +++ b/test/integration/targets/templating_lookups/template_deepcopy/template.in diff --git a/test/integration/targets/lookups/template_lookup_vaulted.yml b/test/integration/targets/templating_lookups/template_lookup_vaulted/playbook.yml index 23f32e8f41..23f32e8f41 100644 --- a/test/integration/targets/lookups/template_lookup_vaulted.yml +++ b/test/integration/targets/templating_lookups/template_lookup_vaulted/playbook.yml diff --git a/test/integration/targets/lookups/templates/vaulted_hello.j2 b/test/integration/targets/templating_lookups/template_lookup_vaulted/templates/vaulted_hello.j2 index a6e98bd8a8..a6e98bd8a8 100644 --- a/test/integration/targets/lookups/templates/vaulted_hello.j2 +++ b/test/integration/targets/templating_lookups/template_lookup_vaulted/templates/vaulted_hello.j2 diff --git a/test/integration/targets/lookups/test_vault_pass b/test/integration/targets/templating_lookups/template_lookup_vaulted/test_vault_pass index 9daeafb986..9daeafb986 100644 --- a/test/integration/targets/lookups/test_vault_pass +++ b/test/integration/targets/templating_lookups/template_lookup_vaulted/test_vault_pass 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 0000000000..5988847b85 --- /dev/null +++ b/test/integration/targets/templating_lookups/template_lookups/tasks/main.yml @@ -0,0 +1,73 @@ +# 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 }}" diff --git a/test/integration/targets/lookups/vars/main.yml b/test/integration/targets/templating_lookups/template_lookups/vars/main.yml index 4c44b1cb86..4c44b1cb86 100644 --- a/test/integration/targets/lookups/vars/main.yml +++ b/test/integration/targets/templating_lookups/template_lookups/vars/main.yml |