-
Notifications
You must be signed in to change notification settings - Fork 24k
show example of async handlers or make it clear that they cannot be run async #84924
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
Comments
Files identified in the description: If these files are incorrect, please update the |
It should work, but Here's an example: - hosts: localhost
gather_facts: no
handlers:
- name: Run handler
command: sleep 9
async: 10
poll: 0
register: handler_async_result
tasks:
- name: Cause handler to run
command: /bin/true
notify: Run handler
- name: Flush handler before ending playbook
meta: flush_handlers
- name: Wait for slow handler to finish
async_status:
jid: "{{ handler_async_result.ansible_job_id }}"
register: job_result
until: job_result.finished
retries: 5
delay: 2
- name: Cleanup results file
async_status:
jid: "{{ handler_async_result.ansible_job_id }}"
mode: cleanup A handler is a type of task, so task keywords are available (with the exception of Here's the documentation for I can open a pull request against https://github.com/ansible/ansible-documentation to improve the documentation if you have suggestions. |
@dberardo-com This Issue is waiting for your response. Please respond or the Issue will be closed. |
I will try to create a reproducible example,. But for the time being I have switched to use the raw: module which is faster in this case ... However I am having issues starting async jobs there since async is not supported in Ansible and the use of "&" to strat the command seems not to work either as the process is killed after the ssh connection is closed ... What would be the best way to start a raw command asynchronously? |
this is due to the connection ending and closing the terminal, any attached process will end. You need to detach before this happens. One simple way to do this is to prefix your command with |
Summary
i am trying to restart a service in an handler that takes quite some time to restart. so i want to do it with async/poll: 0 . but the handler task is currently waiting on the service to restart, ignoring the poll = 0 option.
Issue Type
Documentation Report
Component Name
handler
Ansible Version
$ ansible --version
Configuration
OS / Environment
linux
Additional Information
.
Code of Conduct
The text was updated successfully, but these errors were encountered: