# Notified handler, but skipped

**URL:** <https://forum.ansible.com/t/notified-handler-but-skipped/14588>\
**Category:** Ansible Project\
**Created:** [February 18, 2014, 8:42am UTC](https://forum.ansible.com/t/notified-handler-but-skipped/14588 "2014-02-18T08:42:34Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dcodix](https://avatars.discourse-cdn.com/v4/letter/d/f6c823/32.png) [@dcodix](https://forum.ansible.com/u/dcodix)\
**Post date:** [February 18, 2014, 8:42am UTC](https://forum.ansible.com/t/notified-handler-but-skipped/14588/1 "2014-02-18T08:42:34Z")

</div>

I’m having some trouble having a handler executed. It is notified but skipped. Is there any particular reason why a handler is notified but yet skipped? I mean, from my point of view, if a handler is notified means something changed and it needs to be notified and executed no matter what still if it is only executed once at the end of the play, but why should it ever be skipped?

I am using ansible 1.4.3 on a ScientificLinux 6.5 .

I’m using conditional roles and the same handler exist in previous skipped roles:

_- hosts: all_  
_roles:_  
_- id\_target_  
_- common_  
_- { role: nginx-install, when: var == ‘2’ }_  
_- { role: nginx-config, when: varp == ‘2’ }_  
_- { role: kibana-central, when: var == ‘3’ }_  
_- { role: elasticsearch-install, when: var == ‘1’ }_  
_- { role: elasticsearch-config, when: var == ‘1’ }_  
_- logstash-base-shippers_

The role “elasticsearch-config” have a handler to restart elasticsearch. While running the play “var” == 1, so at the configuration change the handler should be notified, and it is, and applied , but it is not.  
The same handler exist on the roles “kibana-central” , which is skipped and “elasticsearch-install”.

This is what I get:  
_[…]_

_TASK: [java-install | Install OpenJDK] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*_  
_changed: [localhost]_

_TASK: [elasticsearch-install | Install Elasticsearch] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*_  
_changed: [localhost]_

_TASK: [elasticsearch-install | Ensure ElasticSearch is running] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*_

_ok: [localhost]_

_TASK: [elasticsearch-config | Copy elasticsearch.yml] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*_  
_changed: [localhost]_

_TASK: [java-install | Install OpenJDK] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*_  
_ok: [localhost]_

_TASK: [logstash-install | Install Logstash] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*_  
_changed: [localhost]_

_[…]_

_NOTIFIED: [elasticsearch-install | restart elasticsearch] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*_  
_skipping: [localhost]_

_NOTIFIED: [supervisor-install | restart supervisord] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*_  
_changed: [localhost]_

_NOTIFIED: [logstash-base-shippers | reload supervisord] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*_  
_changed: [localhost]_

_PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*_  
_localhost : ok=38 changed=21 unreachable=0 failed=0_

Note:

_NOTIFIED: [elasticsearch-install | restart elasticsearch] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*_  
_skipping: [localhost]_

Thanks!

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [February 18, 2014, 12:22pm UTC](https://forum.ansible.com/t/notified-handler-but-skipped/14588/2 "2014-02-18T12:22:40Z")

</div>

Given you have a “when” above, there’s a 99.99999% chance that’s what’s happening.

If you tag a role with “when”, all the tasks in it are applied with the same condition.

None of the tasks would fire, or the handler.

If you want to define a common handler, don’t define it with a “when” condition.

It may be that you are overriding a handler with the same name in one of those roles.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [February 18, 2014, 12:23pm UTC](https://forum.ansible.com/t/notified-handler-but-skipped/14588/3 "2014-02-18T12:23:28Z")

</div>

The other possibility is there is a “creates=” or “removes=” on a handler that used a command/shell module.

---

<div class="post-metadata">

**Author:** ![dcodix](https://avatars.discourse-cdn.com/v4/letter/d/f6c823/32.png) [@dcodix](https://forum.ansible.com/u/dcodix)\
**Post date:** [February 19, 2014, 8:30am UTC](https://forum.ansible.com/t/notified-handler-but-skipped/14588/4 "2014-02-19T08:30:49Z")

</div>

Thanks Michael,

I supposed it was that (the when), but yet it seems strange to me the fact that a handler can be notified and yet skipped.  
Anyway, I changed the play and I like it much more.  
I just moved all handlers to one separate file and included that file at the start of the play. Now not only works perfectly but also I think is a better aproach.

So that was caused by the “when”.  
I am using "when"s because I want to have only one playbook and apply the roles always depending on the machine type. Is there any other way to do this?

Thanks again.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [February 19, 2014, 1:04pm UTC](https://forum.ansible.com/t/notified-handler-but-skipped/14588/5 "2014-02-19T13:04:38Z")

</div>

"I am using “when"s because I want to have only one playbook and apply the roles always depending on the machine type. Is there any other way to do this?”

Yep! Use groups in that one playbook, and have more than one play:

- hosts: common  
roles:

- common

- hosts: webservers  
roles:

- webservers

- hosts: dbservers  
roles:

- dbservers

This is much cleaner on output as well.

---

<div class="post-metadata">

**Author:** ![dcodix](https://avatars.discourse-cdn.com/v4/letter/d/f6c823/32.png) [@dcodix](https://forum.ansible.com/u/dcodix)\
**Post date:** [February 20, 2014, 11:28am UTC](https://forum.ansible.com/t/notified-handler-but-skipped/14588/6 "2014-02-20T11:28:20Z")

</div>

I am using the groups aproach in some cases, but I can’t use it in pull-mode, can I? The playbook I wrote (with the "when"s) is to be used in pull-mode.

Thanks Michael.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [February 20, 2014, 1:11pm UTC](https://forum.ansible.com/t/notified-handler-but-skipped/14588/7 "2014-02-20T13:11:50Z")

</div>

I’d recommend just using push for 99.547% of everyone out there.

You not only get much better logging output, but can do higher levels of orchestration, and we’ve got plenty of folks using it in very large infrastructures.

Alternatively, you can set up different repos for each of your projects and check out common role content in a known location.

---

<div class="post-metadata">

**Author:** ![dcodix](https://avatars.discourse-cdn.com/v4/letter/d/f6c823/32.png) [@dcodix](https://forum.ansible.com/u/dcodix)\
**Post date:** [February 24, 2014, 11:55am UTC](https://forum.ansible.com/t/notified-handler-but-skipped/14588/8 "2014-02-24T11:55:07Z")

</div>

Yes, different repos sounds good, but yet it might be a bit more work maintaining the code. Anyway I’ll give it a try.

Is there any way to deal with autoscaling in a push mode? If I am using pull mode is only because of the autoscaling…

Thanks Michael.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [February 24, 2014, 1:06pm UTC](https://forum.ansible.com/t/notified-handler-but-skipped/14588/9 "2014-02-24T13:06:08Z")

</div>

“Is there any way to deal with autoscaling in a push mode? If I am using pull mode is only because of the autoscaling…”

Tower has an excellent autoscaling callbacks feature for this.

The node can phone out and say “configure me”, and it will reach out and configure just that node.

It can be enabled and disabled on a per-job-template basis.
