From a3b58fb67c98e9f4c81beb73bebb616295d0803f Mon Sep 17 00:00:00 2001 From: Sloane Hertel <19572925+s-hertel@users.noreply.github.com> Date: Tue, 29 Oct 2024 11:32:17 -0400 Subject: Add a test using ignore_errors as a variable (#84175) * Add a regression test for https://github.com/ansible/ansible/issues/32384 --- test/integration/targets/ignore_errors/meta/main.yml | 2 -- test/integration/targets/ignore_errors/runme.sh | 11 +++++++++++ .../targets/ignore_errors/test_ignore_errors.yml | 4 ++++ .../targets/ignore_errors/test_ignore_errors_false.yml | 18 ++++++++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) delete mode 100644 test/integration/targets/ignore_errors/meta/main.yml create mode 100755 test/integration/targets/ignore_errors/runme.sh create mode 100644 test/integration/targets/ignore_errors/test_ignore_errors.yml create mode 100644 test/integration/targets/ignore_errors/test_ignore_errors_false.yml diff --git a/test/integration/targets/ignore_errors/meta/main.yml b/test/integration/targets/ignore_errors/meta/main.yml deleted file mode 100644 index 07faa21776..0000000000 --- a/test/integration/targets/ignore_errors/meta/main.yml +++ /dev/null @@ -1,2 +0,0 @@ -dependencies: - - prepare_tests diff --git a/test/integration/targets/ignore_errors/runme.sh b/test/integration/targets/ignore_errors/runme.sh new file mode 100755 index 0000000000..efdf1edd7a --- /dev/null +++ b/test/integration/targets/ignore_errors/runme.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +set -eux + +ansible-playbook -i ../../inventory test_ignore_errors.yml "$@" + +if ansible-playbook -i ../../inventory test_ignore_errors_false.yml "$@" > out.txt; then + echo 'Playbook expected to fail succeeded' + exit 1 +fi +# The first task should fail and not be ignored +grep out.txt -e 'ok=0' | grep 'ignored=0' | grep 'failed=1' diff --git a/test/integration/targets/ignore_errors/test_ignore_errors.yml b/test/integration/targets/ignore_errors/test_ignore_errors.yml new file mode 100644 index 0000000000..7092048d47 --- /dev/null +++ b/test/integration/targets/ignore_errors/test_ignore_errors.yml @@ -0,0 +1,4 @@ +- hosts: all + tasks: + - include_tasks: + file: tasks/main.yml diff --git a/test/integration/targets/ignore_errors/test_ignore_errors_false.yml b/test/integration/targets/ignore_errors/test_ignore_errors_false.yml new file mode 100644 index 0000000000..76ca9d697d --- /dev/null +++ b/test/integration/targets/ignore_errors/test_ignore_errors_false.yml @@ -0,0 +1,18 @@ +- name: "Test case for https://github.com/ansible/ansible/issues/32384" + hosts: all + gather_facts: no + vars: + ignore_assertion_errors: false + tasks: + - name: Test using a variable with ignore_errors that evaluates to false + assert: + that: item < 2 + msg: "{{ item }} isn't < 2" + ignore_errors: "{{ ignore_assertion_errors }}" + with_items: + - 1 + - 2 + + - name: Fail if the previous task doesn't end the play + fail: + msg: Previous task was expected to fail -- cgit v1.2.3