-
Notifications
You must be signed in to change notification settings - Fork 23.7k
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
meta: flush_handlers. Wrong conditional behaviour #77616
Comments
Files identified in the description:
If these files are incorrect, please update the |
This behaviour was also considered by #41313 (and many others). #41313, being considered a feature request, was closed after an inactivity period. But, any way I think of it, I can't rationalize this being a request for a new feature but a true bug, so I'm opening this one so it can be reconsidered. |
Thanks a lot to @bcoca and others for considering this behaviour a bug instead of just a feature request this time. Let's hope this helps in attracting attention/focus towards its resolution. WORKAROUND: After re-reading the long comment history from #41313, I added to my repository another two test cases offering a suitable workaround valid at least for some cases, if not most: the brief of it is "put your 'flush_handlers' task within a dynamic include". Also: I also re-read current meta module documentation and tested other meta tasks. Much to my surprise some of them honor when clauses while some don't. |
@jmnavarrol it was not our intention to classify this as a bug, it is not, the One of the reason we added 'attributes' is to have a finer detail about behavior and interactions in the documentation |
Summary
meta: flush_handlers does the wrong thing when conditionally invoked.
No matter the surrounding conditions, meta: flush_handlers gets run whenever ansible interpreter finds it.
Most notably, it doesn't honor conditionals, either straight away (i.e.: with a when clause attached to the task), or by means of conditional inclusion (be it by means of role or include_tasks, etc.)
Issue Type
Bug ReportFeature Request
Component Name
ansible-playbook
Ansible Version
Configuration
OS / Environment
Ubuntu Bionic, running Ansible on a virtualenv (but don't think this is that relevant in this case)
Steps to Reproduce
I set a repository at jmnavarrol/ansible-issue-flush-handlers to showcase this bug.
The playbook below calls flush_handlers with a when condition guaranteed to always evaluate to false (when: 1 == 2) so it should obviously never be triggered (see my ansible playbook).
Expected Results
Since the when condition will always be false, the flush_handlers task shouldn't be triggered and the handler task should be run the last, after all the other playbook's tasks, so run order should be:
As a general matter, the expectation is twofold:
Actual Results
NOTES:
But please pay attention that, in this case, flush_handlers not honoring conditionals is not only "incomplete behaviour" but that the already, currently implemented behaviour, is the wrong one (so this should not be considered a feature request but a bug).
Given the above, and after thinking about it for long, I reckon that completely eliminating flush_handlers would produce a better outcome than current behaviour. So bad I think it is.Since I think I found a workaround quite possibly valid for a lot of cases, I changed my mind: I consider current behaviour plus workaround being superior to not having flush_handlers at all (See #77616 (comment)).Of course, I don't want for flush_handlers to be taken away, since its intended behaviour is a very much needed one, but for flush_handlers to work as it should.
Code of Conduct
The text was updated successfully, but these errors were encountered: