New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Block with rescue stops next plays and end playbook successfully on some errors #73657
Comments
Files identified in the description: If these files are incorrect, please update the |
An incorrect module name is a syntax error. Rescue does not apply to syntax errors, but we'll look into a but further just to make sure this isn't a bug. |
I don't mind too much the playbook stopping if there is a syntax error (although it's not what I want too), but there are some aspects that makes it clearly a bug:
It should either stop the current play immediately and fail (not what I want, but I would be ok with it), or rescue and continue all the next plays (which is what I want). But it does neither one nor the other, it continues the play, don't run the next plays (stops abruptly at the end of the play), and ends the execution partially with a success status. |
|
Since this is a parsing error the play execution should not continue and we should probably mimic the behavior of diff --git a/lib/ansible/plugins/strategy/__init__.py b/lib/ansible/plugins/strategy/__init__.py
index eaa7c0cb20..96910301b1 100644
--- a/lib/ansible/plugins/strategy/__init__.py
+++ b/lib/ansible/plugins/strategy/__init__.py
@@ -954,7 +954,8 @@ class StrategyBase:
# 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)
diff --git a/lib/ansible/plugins/strategy/free.py b/lib/ansible/plugins/strategy/free.py
index 7e0406984d..653291b327 100644
--- a/lib/ansible/plugins/strategy/free.py
+++ b/lib/ansible/plugins/strategy/free.py
@@ -34,7 +34,7 @@ DOCUMENTATION = '''
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
@@ -255,6 +255,8 @@ class StrategyModule(StrategyBase):
)
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)
diff --git a/lib/ansible/plugins/strategy/linear.py b/lib/ansible/plugins/strategy/linear.py
index d22f03e9f0..a345cf1f77 100644
--- a/lib/ansible/plugins/strategy/linear.py
+++ b/lib/ansible/plugins/strategy/linear.py
@@ -32,7 +32,7 @@ DOCUMENTATION = '''
'''
~
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 PlayIterator
from ansible.module_utils.six import iteritems
from ansible.module_utils._text import to_text
@@ -383,7 +383,8 @@ class StrategyModule(StrategyBase):
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 Then the error is fatal:
|
About number 1, the fact that is dynamic is exactly the reason that makes me expect it to not error the entire execution. With an import task I would probably receive an error before the playbook start executing (I have not tested, but I guess it what happens). If I have tasks at the final play that destroy any resource created at the beginning, I would expect it to run if some task included in the middle of the execution gave a syntax error (inside the task, after the resources were already created in previous steps), but had a That said, I would still be ok if it failed immediately and returned an error (solve 2 and 3). |
* Parser errors from within includes should not be rescueable * Also fixes unit tests Fixes #73657
…73722) * Parser errors from within includes should not be rescueable * Also fixes unit tests Fixes ansible#73657
SUMMARY
Depending on the error that occurs when a block with rescue catches it, the play execution stops, and the playbook ends successfuly, but the next plays don't run. I was able to simulate it using
include_tasks
, but the task inside use a module with a wrong name (that can be provided by a user, so not something that I have control, because it might not be me running the play, the user may include and run custom tasks).This is not a problem if the module with wrong name is in the main playbook file, because the playbook fails at compilation time, but when lazily loaded through an
include_tasks
, the task fails, therescue
(wrapping theinclude_tasks
) catches the error successfully, but the next plays don't run, and the playbook ends successfuly.ISSUE TYPE
COMPONENT NAME
block
ANSIBLE VERSION
CONFIGURATION
(
ansible-config dump --only-changed
outputs nothing)OS / ENVIRONMENT
Ubuntu 18.04 (docker container)
STEPS TO REPRODUCE
hosts.yml:
playbook.yml:
Works:
test.yml (gives an error, but works as expected):
Outputs:
Bug:
test.yml (gives an error, stops the next plays, ends the playbook successfully, as explained above):
Outputs:
EXPECTED RESULTS
The same as in the case that works.
ACTUAL RESULTS
Stop the next plays, even after being rescued, and end the playbook successfully (if I run
ansible-playbook playbook.yml && echo "success" || echo "error"
it gives an error (due to thefail
task at the end) in the 1st case (that works), but success in the 2nd, and don't run the 2nd play).The text was updated successfully, but these errors were encountered: