From 532e3ea3ec4a5113e5af487cfad327e91b211177 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Tue, 4 Mar 2025 07:17:01 -0800 Subject: [PATCH] test: error handling in include_role (#84737) Signed-off-by: Abhijeet Kasurde --- test/integration/targets/roles/75240.yml | 11 +++++++++++ .../targets/roles/roles/error_handler/tasks/main.yml | 8 ++++++++ test/integration/targets/roles/runme.sh | 3 +++ 3 files changed, 22 insertions(+) create mode 100644 test/integration/targets/roles/75240.yml create mode 100644 test/integration/targets/roles/roles/error_handler/tasks/main.yml diff --git a/test/integration/targets/roles/75240.yml b/test/integration/targets/roles/75240.yml new file mode 100644 index 00000000000..b7c59717425 --- /dev/null +++ b/test/integration/targets/roles/75240.yml @@ -0,0 +1,11 @@ +--- +- hosts: all + gather_facts: no + tasks: + - block: + - name: Setup + fail: + rescue: + - name: "Error handler" + include_role: + name: "error_handler" diff --git a/test/integration/targets/roles/roles/error_handler/tasks/main.yml b/test/integration/targets/roles/roles/error_handler/tasks/main.yml new file mode 100644 index 00000000000..8fcb9e323ad --- /dev/null +++ b/test/integration/targets/roles/roles/error_handler/tasks/main.yml @@ -0,0 +1,8 @@ +--- +- name: Check if we get correct failed_task details + assert: + that: + - ansible_failed_task.name == "Setup" + - ansible_failed_task.action == "fail" + vars: + ansible_connection: local diff --git a/test/integration/targets/roles/runme.sh b/test/integration/targets/roles/runme.sh index 607de510029..77f488fd3d5 100755 --- a/test/integration/targets/roles/runme.sh +++ b/test/integration/targets/roles/runme.sh @@ -61,3 +61,6 @@ done [ "$(ansible localhost -m meta -a end_role 2>&1 | grep -c "ERROR! Cannot execute 'end_role' from outside of a role")" = "1" ] [ "$(ansible-playbook end_role_handler_error.yml 2>&1 | grep -c "ERROR! Cannot execute 'end_role' from a handler")" = "1" ] + +# include_role should work in rescue, even if error is from magic variable templating +ansible-playbook 75240.yml -i ../../inventory "$@"