# Question about force handlers

**URL:** <https://forum.ansible.com/t/question-about-force-handlers/25557>\
**Category:** Ansible Project\
**Created:** [September 21, 2017, 2:11pm UTC](https://forum.ansible.com/t/question-about-force-handlers/25557 "2017-09-21T14:11:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anfield](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@Anfield](https://forum.ansible.com/u/Anfield)\
**Post date:** [September 21, 2017, 2:11pm UTC](https://forum.ansible.com/t/question-about-force-handlers/25557/1 "2017-09-21T14:11:03Z")

</div>

Testing out the force handlers parameter in a role and it is not working for me.The first tasks fails, so I though the force handlers would force the second one to get trigger anyway

nginx.yml

> * * *
> 
> - hosts: appservers
> 
> force\_handlers: True
> 
> roles:
> 
> - { role: nginx, when: “ansible\_os\_family == ‘RedHat’”}

tasks/main.yml

> - name: Run a command that fails
> 
> shell: /bin/false
> 
> - name: Install nginx
> 
> yum:
> 
> name: nginx
> 
> state: installed
> 
> register: nginx\_installed
> 
> notify:
> 
> - restart nginx

handlers/main.yml

> - name: restart nginx  
> service:  
> name: nginx  
> state: restarted  
> register: nginx\_restarted
> - debug: var=nginx\_restarted

Output -

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [September 21, 2017, 5:49pm UTC](https://forum.ansible.com/t/question-about-force-handlers/25557/2 "2017-09-21T17:49:02Z")

</div>

> Testing out the force handlers parameter in a role and it is not working  
> for me.The first tasks fails, so I though the force handlers would force  
> the second one to get trigger anyway

As I understand the documentation it will only run the handlers that has been notified before the failed tasj. So any notify after the failed task will not trigger a handler.

> nginx.yml
> 
> ---  
> - hosts: appservers  
> &nbsp;&nbsp;&nbsp;force\_handlers: True  
> &nbsp;&nbsp;&nbsp;roles:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- { role: nginx, when: "ansible\_os\_family == 'RedHat'"}
> 
> tasks/main.yml
> 
> - name: Run a command that fails  
> &nbsp;&nbsp;&nbsp;shell: /bin/false
> 
> - name: Install nginx  
> &nbsp;&nbsp;&nbsp;yum:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: nginx  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state: installed  
> &nbsp;&nbsp;&nbsp;register: nginx\_installed  
> &nbsp;&nbsp;&nbsp;notify:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- restart nginx

Since shell task failes the yum is not run and the notify will not trigger the handler.

---

<div class="post-metadata">

**Author:** ![Anfield](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@Anfield](https://forum.ansible.com/u/Anfield)\
**Post date:** [September 21, 2017, 7:05pm UTC](https://forum.ansible.com/t/question-about-force-handlers/25557/3 "2017-09-21T19:05:30Z")

</div>

So I switched around the tasks in the task/main.yml to get this, and the notify still doesnt happen

tasks/main.yml

- name: Install nginx  
yum:  
name: nginx  
state: installed  
register: nginx\_installed  
notify:

- restart nginx

- name: Run a command that fails  
shell: /bin/false

Output -

---

<div class="post-metadata">

**Author:** ![Anfield](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@Anfield](https://forum.ansible.com/u/Anfield)\
**Post date:** [September 21, 2017, 7:22pm UTC](https://forum.ansible.com/t/question-about-force-handlers/25557/4 "2017-09-21T19:22:58Z")

</div>

Ok nevermind. This works now. I forgot to add become: yes to the main file in the last try. The task now calls the handler, despite the failure in the 2nd task.

So with the tasks/main.yml

> tasks/main.yml
> 
> - name: Install nginx
> 
> yum:
> 
> name: nginx
> 
> state: installed
> 
> register: nginx\_installed
> 
> notify:
> 
> - restart nginx
> 
> - name: Run a command that fails
> 
> shell: /bin/false

Output -
