Skip to content

Commit

Permalink
Parser errors from within includes should not be rescueable
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrizek committed Nov 1, 2021
1 parent e84d660 commit 8eaa345
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 4 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/73657-include-parser-error-fail.yml
@@ -0,0 +1,2 @@
bugfixes:
- Parser errors from within includes should not be rescueable (https://github.com/ansible/ansible/issues/73657)
5 changes: 4 additions & 1 deletion lib/ansible/plugins/strategy/__init__.py
Expand Up @@ -945,7 +945,8 @@ def _load_included_file(self, included_file, iterator, is_handler=False):
# first processed, we do so now for each host in the list
for host in included_file._hosts:
self._tqm._stats.increment('ok', host.name)

except AnsibleParserError:
raise
except AnsibleError as e:
if isinstance(e, AnsibleFileNotFound):
reason = "Could not find or access '%s' on the Ansible Controller." % to_text(e.file_name)
Expand Down Expand Up @@ -1061,6 +1062,8 @@ def _do_handler_run(self, handler, handler_name, iterator, play_context, notifie
)
if not result:
break
except AnsibleParserError:
raise
except AnsibleError as e:
for host in included_file._hosts:
iterator.mark_host_failed(host)
Expand Down
4 changes: 3 additions & 1 deletion lib/ansible/plugins/strategy/free.py
Expand Up @@ -34,7 +34,7 @@
import time

from ansible import constants as C
from ansible.errors import AnsibleError
from ansible.errors import AnsibleError, AnsibleParserError
from ansible.playbook.included_file import IncludedFile
from ansible.plugins.loader import action_loader
from ansible.plugins.strategy import StrategyBase
Expand Down Expand Up @@ -257,6 +257,8 @@ def run(self, iterator, play_context):
)
else:
new_blocks = self._load_included_file(included_file, iterator=iterator)
except AnsibleParserError:
raise
except AnsibleError as e:
for host in included_file._hosts:
iterator.mark_host_failed(host)
Expand Down
5 changes: 3 additions & 2 deletions lib/ansible/plugins/strategy/linear.py
Expand Up @@ -32,7 +32,7 @@
'''

from ansible import constants as C
from ansible.errors import AnsibleError, AnsibleAssertionError
from ansible.errors import AnsibleError, AnsibleAssertionError, AnsibleParserError
from ansible.executor.play_iterator import IteratingStates, FailedStates
from ansible.module_utils._text import to_text
from ansible.playbook.block import Block
Expand Down Expand Up @@ -382,7 +382,8 @@ def run(self, iterator, play_context):
else:
all_blocks[host].append(noop_block)
display.debug("done iterating over new_blocks loaded from include file")

except AnsibleParserError:
raise
except AnsibleError as e:
for host in included_file._hosts:
self._tqm._failed_hosts[host.name] = True
Expand Down
8 changes: 8 additions & 0 deletions test/integration/targets/include_import/issue73657.yml
@@ -0,0 +1,8 @@
- hosts: localhost
gather_facts: no
tasks:
- block:
- include_tasks: issue73657_tasks.yml
rescue:
- debug:
msg: SHOULD_NOT_EXECUTE
2 changes: 2 additions & 0 deletions test/integration/targets/include_import/issue73657_tasks.yml
@@ -0,0 +1,2 @@
- wrong.wrong.wrong:
parser: error
4 changes: 4 additions & 0 deletions test/integration/targets/include_import/runme.sh
Expand Up @@ -135,3 +135,7 @@ cat out.txt
test "$(grep out.txt -ce 'In imported playbook')" = 2
test "$(grep out.txt -ce 'In imported tasks')" = 3
test "$(grep out.txt -ce 'In imported role')" = 3

# https://github.com/ansible/ansible/issues/73657
ansible-playbook issue73657.yml 2>&1 | tee issue73657.out
test "$(grep -c 'SHOULD_NOT_EXECUTE' issue73657.out)" = 0

0 comments on commit 8eaa345

Please sign in to comment.