Track failures in the includes results to avoid special handling of include errors (#53688)

* Make include_role/include_tasks work with any_errors_fatal v2

Fixes #50897

Co-authored-by: Matt Martz <matt@sivel.net>

* Add failed to results in free strategy too

* Fix

* Avoid duplicating results

* ci_complete

Co-authored-by: Matt Martz <matt@sivel.net>
pull/76875/head
Martin Krizek 4 years ago committed by GitHub
parent f501b579e5
commit 3816815db0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- Make include_role/include_tasks work with any_errors_fatal (https://github.com/ansible/ansible/issues/50897)

@ -43,6 +43,7 @@ class IncludedFile:
self._task = task
self._hosts = []
self._is_role = is_role
self._results = []
def add_host(self, host):
if host not in self._hosts:
@ -212,6 +213,7 @@ class IncludedFile:
try:
inc_file.add_host(original_host)
inc_file._results.append(res)
except ValueError:
# The host already exists for this include, advance forward, this is a new include
idx += pos + 1

@ -970,6 +970,9 @@ class StrategyBase:
else:
reason = to_text(e)
for r in included_file._results:
r._result['failed'] = True
# mark all of the hosts including this file as failed, send callbacks,
# and increment the stats for this host
for host in included_file._hosts:

@ -260,6 +260,9 @@ class StrategyModule(StrategyBase):
except AnsibleParserError:
raise
except AnsibleError as e:
for r in included_file._results:
r._result['failed'] = True
for host in included_file._hosts:
iterator.mark_host_failed(host)
display.warning(to_text(e))

@ -339,7 +339,6 @@ class StrategyModule(StrategyBase):
variable_manager=self._variable_manager
)
include_failure = False
if len(included_files) > 0:
display.debug("we have included files to process")
@ -385,11 +384,13 @@ class StrategyModule(StrategyBase):
except AnsibleParserError:
raise
except AnsibleError as e:
for r in included_file._results:
r._result['failed'] = True
for host in included_file._hosts:
self._tqm._failed_hosts[host.name] = True
iterator.mark_host_failed(host)
display.error(to_text(e), wrap_text=False)
include_failure = True
continue
# finally go through all of the hosts and append the

@ -0,0 +1,19 @@
- hosts: testhost,testhost2
gather_facts: no
any_errors_fatal: yes
tasks:
- name: EXPECTED FAILURE include_role that doesn't exist
include_role:
name: 'non-existant-role'
when:
- inventory_hostname == 'testhost2'
- test_name == 'test_include_role'
- name: EXPECTED FAILURE include_tasks that don't exist
include_tasks: non-existant.yml
when:
- inventory_hostname == 'testhost2'
- test_name == 'test_include_tasks'
- debug:
msg: 'any_errors_fatal_this_should_never_be_reached'

@ -5,14 +5,14 @@ ansible-playbook -i inventory "$@" play_level.yml| tee out.txt | grep 'any_error
res=$?
cat out.txt
if [ "${res}" -eq 0 ] ; then
exit 1
exit 1
fi
ansible-playbook -i inventory "$@" on_includes.yml | tee out.txt | grep 'any_errors_fatal_this_should_never_be_reached'
res=$?
cat out.txt
if [ "${res}" -eq 0 ] ; then
exit 1
exit 1
fi
set -ux
@ -20,4 +20,18 @@ set -ux
ansible-playbook -i inventory "$@" always_block.yml | tee out.txt | grep 'any_errors_fatal_always_block_start'
res=$?
cat out.txt
exit $res
if [ "${res}" -ne 0 ] ; then
exit 1
fi
set -ux
for test_name in test_include_role test_include_tasks; do
ansible-playbook -i inventory "$@" -e test_name=$test_name 50897.yml | tee out.txt | grep 'any_errors_fatal_this_should_never_be_reached'
res=$?
cat out.txt
if [ "${res}" -eq 0 ] ; then
exit 1
fi
done

Loading…
Cancel
Save