diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 16:04:21 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 16:04:21 +0000 |
commit | 8a754e0858d922e955e71b253c139e071ecec432 (patch) | |
tree | 527d16e74bfd1840c85efd675fdecad056c54107 /test/integration/targets/parsing | |
parent | Initial commit. (diff) | |
download | ansible-core-upstream/2.14.3.tar.xz ansible-core-upstream/2.14.3.zip |
Adding upstream version 2.14.3.upstream/2.14.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/integration/targets/parsing')
15 files changed, 330 insertions, 0 deletions
diff --git a/test/integration/targets/parsing/aliases b/test/integration/targets/parsing/aliases new file mode 100644 index 0000000..1d28bdb --- /dev/null +++ b/test/integration/targets/parsing/aliases @@ -0,0 +1,2 @@ +shippable/posix/group5 +context/controller diff --git a/test/integration/targets/parsing/bad_parsing.yml b/test/integration/targets/parsing/bad_parsing.yml new file mode 100644 index 0000000..953ec07 --- /dev/null +++ b/test/integration/targets/parsing/bad_parsing.yml @@ -0,0 +1,12 @@ +- hosts: testhost + + # the following commands should all parse fine and execute fine + # and represent quoting scenarios that should be legit + + gather_facts: False + + roles: + + # this one has a lot of things that should fail, see makefile for operation w/ tags + + - { role: test_bad_parsing } diff --git a/test/integration/targets/parsing/good_parsing.yml b/test/integration/targets/parsing/good_parsing.yml new file mode 100644 index 0000000..b68d911 --- /dev/null +++ b/test/integration/targets/parsing/good_parsing.yml @@ -0,0 +1,9 @@ +- hosts: testhost + + # the following commands should all parse fine and execute fine + # and represent quoting scenarios that should be legit + + gather_facts: False + + roles: + - { role: test_good_parsing, tags: test_good_parsing } diff --git a/test/integration/targets/parsing/roles/test_bad_parsing/tasks/main.yml b/test/integration/targets/parsing/roles/test_bad_parsing/tasks/main.yml new file mode 100644 index 0000000..f1b2ec6 --- /dev/null +++ b/test/integration/targets/parsing/roles/test_bad_parsing/tasks/main.yml @@ -0,0 +1,60 @@ +# test code for the ping module +# (c) 2014, Michael DeHaan <michael@ansible.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/>. + +# the following tests all raise errors, to use them in a Makefile, we run them with different flags, as +# otherwise ansible stops at the first one and we want to ensure STOP conditions for each + +- set_fact: + test_file: "{{ output_dir }}/ansible_test_file" # FIXME, use set tempdir + test_input: "owner=test" + bad_var: "{{ output_dir }}' owner=test" + chdir: "mom chdir=/tmp" + tags: common + +- file: name={{test_file}} state=touch + tags: common + +- name: remove touched file + file: name={{test_file}} state=absent + tags: common + +- name: include test that we cannot insert arguments + include: scenario1.yml + tags: scenario1 + +- name: include test that we cannot duplicate arguments + include: scenario2.yml + tags: scenario2 + +- name: include test that we can't do this for the shell module + include: scenario3.yml + tags: scenario3 + +- name: include test that we can't go all Little Bobby Droptables on a quoted var to add more + include: scenario4.yml + tags: scenario4 + +- name: test that a missing/malformed jinja2 filter fails + debug: msg="{{output_dir|badfiltername}}" + tags: scenario5 + register: filter_fail + ignore_errors: yes + +- assert: + that: + - filter_fail is failed diff --git a/test/integration/targets/parsing/roles/test_bad_parsing/tasks/scenario1.yml b/test/integration/targets/parsing/roles/test_bad_parsing/tasks/scenario1.yml new file mode 100644 index 0000000..8a82fb9 --- /dev/null +++ b/test/integration/targets/parsing/roles/test_bad_parsing/tasks/scenario1.yml @@ -0,0 +1,4 @@ +- name: test that we cannot insert arguments + file: path={{ test_file }} {{ test_input }} + failed_when: False # ignore the module, just test the parser + tags: scenario1 diff --git a/test/integration/targets/parsing/roles/test_bad_parsing/tasks/scenario2.yml b/test/integration/targets/parsing/roles/test_bad_parsing/tasks/scenario2.yml new file mode 100644 index 0000000..c3b4b13 --- /dev/null +++ b/test/integration/targets/parsing/roles/test_bad_parsing/tasks/scenario2.yml @@ -0,0 +1,4 @@ +- name: test that we cannot duplicate arguments + file: path={{ test_file }} owner=test2 {{ test_input }} + failed_when: False # ignore the module, just test the parser + tags: scenario2 diff --git a/test/integration/targets/parsing/roles/test_bad_parsing/tasks/scenario3.yml b/test/integration/targets/parsing/roles/test_bad_parsing/tasks/scenario3.yml new file mode 100644 index 0000000..a228f70 --- /dev/null +++ b/test/integration/targets/parsing/roles/test_bad_parsing/tasks/scenario3.yml @@ -0,0 +1,4 @@ +- name: test that we can't do this for the shell module + shell: echo hi {{ chdir }} + failed_when: False + tags: scenario3 diff --git a/test/integration/targets/parsing/roles/test_bad_parsing/tasks/scenario4.yml b/test/integration/targets/parsing/roles/test_bad_parsing/tasks/scenario4.yml new file mode 100644 index 0000000..2845adc --- /dev/null +++ b/test/integration/targets/parsing/roles/test_bad_parsing/tasks/scenario4.yml @@ -0,0 +1,4 @@ +- name: test that we can't go all Little Bobby Droptables on a quoted var to add more + file: "name={{ bad_var }}" + failed_when: False + tags: scenario4 diff --git a/test/integration/targets/parsing/roles/test_bad_parsing/vars/main.yml b/test/integration/targets/parsing/roles/test_bad_parsing/vars/main.yml new file mode 100644 index 0000000..1aaeac7 --- /dev/null +++ b/test/integration/targets/parsing/roles/test_bad_parsing/vars/main.yml @@ -0,0 +1,2 @@ +--- +output_dir: . diff --git a/test/integration/targets/parsing/roles/test_good_parsing/tasks/main.yml b/test/integration/targets/parsing/roles/test_good_parsing/tasks/main.yml new file mode 100644 index 0000000..d225c0f --- /dev/null +++ b/test/integration/targets/parsing/roles/test_good_parsing/tasks/main.yml @@ -0,0 +1,217 @@ +# test code for the ping module +# (c) 2014, Michael DeHaan <michael@ansible.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/>. + +# various tests of things that should not cause parsing problems + +- set_fact: + test_input: "a=1 a=2 a=3" + +- set_fact: + multi_line: | + echo old + echo mcdonald + echo had + echo a + echo farm + +- shell: echo "dog" + register: result + +- assert: + that: + result.cmd == 'echo "dog"' + +- shell: echo 'dog' + register: result + +- assert: + that: + result.cmd == 'echo \'dog\'' + +- name: a quoted argument is not sent to the shell module as anything but a string parameter + shell: echo 'dog' 'executable=/usr/bin/python' + register: result + +- debug: var=result.cmd + +- assert: + that: + result.cmd == "echo 'dog' 'executable=/usr/bin/python'" + +- name: it is valid to pass multiple key=value arguments because the shell doesn't check key=value arguments + shell: echo quackquack=here quackquack=everywhere + register: result + +- assert: + that: + result.cmd == 'echo quackquack=here quackquack=everywhere' + +- name: the same is true with quoting + shell: echo "quackquack=here quackquack=everywhere" + register: result + +- assert: + that: + result.cmd == 'echo "quackquack=here quackquack=everywhere"' + +- name: the same is true with quoting (B) + shell: echo "quackquack=here" "quackquack=everywhere" + register: result + +- name: the same is true with quoting (C) + shell: echo "quackquack=here" 'quackquack=everywhere' + register: result + +- name: the same is true with quoting (D) + shell: echo "quackquack=here" 'quackquack=everywhere' + register: result + +- name: the same is true with quoting (E) + shell: echo {{ test_input }} + register: result + +- assert: + that: + result.cmd == "echo a=1 a=2 a=3" + +- name: more shell duplicates + shell: echo foo=bar foo=bar + register: result + +- assert: + that: + result.cmd == "echo foo=bar foo=bar" + +- name: raw duplicates, noop + raw: env true foo=bar foo=bar + +- name: multi-line inline shell commands (should use script module but hey) are a thing + shell: "{{ multi_line }}" + register: result + +- debug: var=result + +- assert: + that: + result.stdout_lines == [ 'old', 'mcdonald', 'had', 'a', 'farm' ] + +- name: passing same arg to shell command is legit + shell: echo foo --arg=a --arg=b + failed_when: False # just catch the exit code, parse error is what I care about, but should register and compare result + register: result + +- assert: + that: + # command shouldn't end in spaces, amend test once fixed + - result.cmd == "echo foo --arg=a --arg=b" + +- name: test includes with params + include: test_include.yml fact_name=include_params param="{{ test_input }}" + +- name: assert the include set the correct fact for the param + assert: + that: + - include_params == test_input + +- name: test includes with quoted params + include: test_include.yml fact_name=double_quoted_param param="this is a param with double quotes" + +- name: assert the include set the correct fact for the double quoted param + assert: + that: + - double_quoted_param == "this is a param with double quotes" + +- name: test includes with single quoted params + include: test_include.yml fact_name=single_quoted_param param='this is a param with single quotes' + +- name: assert the include set the correct fact for the single quoted param + assert: + that: + - single_quoted_param == "this is a param with single quotes" + +- name: test includes with quoted params in complex args + include: test_include.yml + vars: + fact_name: complex_param + param: "this is a param in a complex arg with double quotes" + +- name: assert the include set the correct fact for the params in complex args + assert: + that: + - complex_param == "this is a param in a complex arg with double quotes" + +- name: test variable module name + action: "{{ variable_module_name }} msg='this should be debugged'" + register: result + +- name: assert the task with variable module name ran + assert: + that: + - result.msg == "this should be debugged" + +- name: test conditional includes + include: test_include_conditional.yml + when: false + +- name: assert the nested include from test_include_conditional was not set + assert: + that: + - nested_include_var is undefined + +- name: test omit in complex args + set_fact: + foo: bar + spam: "{{ omit }}" + should_not_omit: "prefix{{ omit }}" + +- assert: + that: + - foo == 'bar' + - spam is undefined + - should_not_omit is defined + +- name: test omit in module args + set_fact: > + yo=whatsup + eggs="{{ omit }}" + default_omitted="{{ not_exists|default(omit) }}" + should_not_omit_1="prefix{{ omit }}" + should_not_omit_2="{{ omit }}suffix" + should_not_omit_3="__omit_place_holder__afb6b9bc3d20bfeaa00a1b23a5930f89" + +- assert: + that: + - yo == 'whatsup' + - eggs is undefined + - default_omitted is undefined + - should_not_omit_1 is defined + - should_not_omit_2 is defined + - should_not_omit_3 == "__omit_place_holder__afb6b9bc3d20bfeaa00a1b23a5930f89" + +- name: Ensure module names are stripped of extra spaces (local_action) + local_action: set_fact b="b" + register: la_set_fact_b + +- name: Ensure module names are stripped of extra spaces (action) + action: set_fact c="c" + register: la_set_fact_c + +- assert: + that: + - b == "b" + - c == "c" diff --git a/test/integration/targets/parsing/roles/test_good_parsing/tasks/test_include.yml b/test/integration/targets/parsing/roles/test_good_parsing/tasks/test_include.yml new file mode 100644 index 0000000..4ba5035 --- /dev/null +++ b/test/integration/targets/parsing/roles/test_good_parsing/tasks/test_include.yml @@ -0,0 +1 @@ +- set_fact: "{{fact_name}}='{{param}}'" diff --git a/test/integration/targets/parsing/roles/test_good_parsing/tasks/test_include_conditional.yml b/test/integration/targets/parsing/roles/test_good_parsing/tasks/test_include_conditional.yml new file mode 100644 index 0000000..070888d --- /dev/null +++ b/test/integration/targets/parsing/roles/test_good_parsing/tasks/test_include_conditional.yml @@ -0,0 +1 @@ +- include: test_include_nested.yml diff --git a/test/integration/targets/parsing/roles/test_good_parsing/tasks/test_include_nested.yml b/test/integration/targets/parsing/roles/test_good_parsing/tasks/test_include_nested.yml new file mode 100644 index 0000000..f1f6fcc --- /dev/null +++ b/test/integration/targets/parsing/roles/test_good_parsing/tasks/test_include_nested.yml @@ -0,0 +1,2 @@ +- name: set the nested include fact + set_fact: nested_include_var=1 diff --git a/test/integration/targets/parsing/roles/test_good_parsing/vars/main.yml b/test/integration/targets/parsing/roles/test_good_parsing/vars/main.yml new file mode 100644 index 0000000..ea7a0b8 --- /dev/null +++ b/test/integration/targets/parsing/roles/test_good_parsing/vars/main.yml @@ -0,0 +1,2 @@ +--- +variable_module_name: debug diff --git a/test/integration/targets/parsing/runme.sh b/test/integration/targets/parsing/runme.sh new file mode 100755 index 0000000..022ce4c --- /dev/null +++ b/test/integration/targets/parsing/runme.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -eux + +ansible-playbook bad_parsing.yml -i ../../inventory -vvv "$@" --tags prepare,common,scenario5 +ansible-playbook good_parsing.yml -i ../../inventory -v "$@" |