Ansible Handler: force_handlers: true and meta: flush_handlers
Hi Pals!
Ansible Handler: force_handlers: true and meta: flush_handlers
Photo by Micah Carlson on Unsplash
Hi Pals!
Good day to you all. Welcome you all in one of important concepts in Ansible. Before proceeding further, I assume you are familiar with Ansible Handler. If not, lets quickly understand it in one line.
Handlers- It is special task that only executed or triggered when an specific event occured or we can say when notified by other tasks. Generally, It is executed at the end of all task but not always. We will see this here.
Now, Let’s understand both features.
force_handlers: true
This ensures handlers run even if the play fails. E.g-
- hosts: web
force_handlers: true
tasks:
- name: Update nginx config
template:
src: nginx.conf.j2
dest: /etc/nginx/nginx.conf
notify: restart nginx
- name: Let suppose this Fails
command: /bin/false
handlers:
- name: restart nginx
service:
name: nginx
state: restarted
If we see execution flow- Without force_handlers, handler would not run.
Update nginx config → handler notified
↓
Next task fails
↓
Handler STILL runs
meta: flush_handlers
This forces handlers to run immediately instead of waiting until the end of the play. E.g-
tasks:
- name: Update nginx config
template:
src: nginx.conf.j2
dest: /etc/nginx/nginx.conf
notify: restart nginx
- meta: flush_handlers
- name: Deploy application
command: ./deploy.sh
If we see execution flow- Normally handlers run after all tasks finish but this forces them to run mid-play.
Update config
↓
Handler notified
↓
flush_handlers executes
↓
nginx restarts immediately
↓
Next tasks run
Now lets clear some more difference between them.
- Purpose: force_handlers: true — Ensure handlers run even if play fails. meta: flush_handlers — Run handlers immediately.
- Scope: force_handlers: true — Play level meta: flush_handlers — Task level
- Execution time: force_handlers: true — At the end of play meta: flush_handlers — Mid of play, When flush_handlers is reached
So, In short keep this in mind. force_handlers → ensures handlers run even on failure flush_handlers → runs handlers immediately
Thanks for checking it. See you in next post.
메타데이터
- post_id
- 094da802acf6
- slug
- ansible-handler-force-handlers-true-and-meta-flush-handlers-094da802acf6
- url
- https://medium.com/@aishwaryprakash98/ansible-handler-force-handlers-true-and-meta-flush-handlers-094da802acf6
- canonical_url
- https://medium.com/@aishwaryprakash98/ansible-handler-force-handlers-true-and-meta-flush-handlers-094da802acf6
- author_url
- https://medium.com/@aishwaryprakash98
- status
- ok
- fetched_at
- 2026-08-03 17:15:07