# skip-tags doesn't work for handlers

**URL:** <https://forum.ansible.com/t/skip-tags-doesnt-work-for-handlers/17596>\
**Category:** Ansible Project\
**Created:** [February 23, 2015, 11:36am UTC](https://forum.ansible.com/t/skip-tags-doesnt-work-for-handlers/17596 "2015-02-23T11:36:07Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ivaylo\_Bratoev](https://avatars.discourse-cdn.com/v4/letter/i/f9ae1b/32.png) [@Ivaylo\_Bratoev](https://forum.ansible.com/u/Ivaylo_Bratoev)\
**Post date:** [February 23, 2015, 11:36am UTC](https://forum.ansible.com/t/skip-tags-doesnt-work-for-handlers/17596/1 "2015-02-23T11:36:07Z")

</div>

Is it expected for **ansible-playbook** with **–skip-tags** to not skip handlers tagged properly?

Let me give an example. If you have the following handler:

`

- name: NGINX reload  
service:  
name: nginx  
state: reloaded  
tags: reload

`

And you run:  
`ansible-playbook ... --skip-tags reload`

Is it expected the handler to be skipped?

For me, it is **not** expected and I would consider it bug but want to double check that before posing an issue.

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [February 23, 2015, 11:55am UTC](https://forum.ansible.com/t/skip-tags-doesnt-work-for-handlers/17596/2 "2015-02-23T11:55:14Z")

</div>

shouldn't that be :

- name: NGINX reload  
&nbsp;&nbsp;service: name=nginx state=reloaded  
&nbsp;&nbsp;tags: reload

?

---

<div class="post-metadata">

**Author:** ![Ivaylo\_Bratoev](https://avatars.discourse-cdn.com/v4/letter/i/f9ae1b/32.png) [@Ivaylo\_Bratoev](https://forum.ansible.com/u/Ivaylo_Bratoev)\
**Post date:** [February 23, 2015, 12:15pm UTC](https://forum.ansible.com/t/skip-tags-doesnt-work-for-handlers/17596/3 "2015-02-23T12:15:53Z")

</div>

Both are the same… Just a different ways to write YAML.

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [February 23, 2015, 1:04pm UTC](https://forum.ansible.com/t/skip-tags-doesnt-work-for-handlers/17596/4 "2015-02-23T13:04:16Z")

</div>

​Not exactly, both are equivalen notations that ansible parses​, the former  
being pure yaml 🙂

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 23, 2015, 2:43pm UTC](https://forum.ansible.com/t/skip-tags-doesnt-work-for-handlers/17596/5 "2015-02-23T14:43:39Z")

</div>

Handlers ignore tags, they only run when notified and always run when notified

---

<div class="post-metadata">

**Author:** ![Ivaylo\_Bratoev](https://avatars.discourse-cdn.com/v4/letter/i/f9ae1b/32.png) [@Ivaylo\_Bratoev](https://forum.ansible.com/u/Ivaylo_Bratoev)\
**Post date:** [March 5, 2015, 8:02am UTC](https://forum.ansible.com/t/skip-tags-doesnt-work-for-handlers/17596/6 "2015-03-05T08:02:17Z")

</div>

So there is not way to skip a handler through ansible-playbook… Consider that a feature request 😉

---

<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:** [June 6, 2015, 10:14am UTC](https://forum.ansible.com/t/skip-tags-doesnt-work-for-handlers/17596/7 "2015-06-06T10:14:50Z")

</div>

I would like the same feature.

I don’t know if there is another way to do what I am trying to do.  
My case of use would be to be able to use the same roles/playbooks to mantain the configuration along all my servers and for the AMI creation. In the case of an ami creation I don’t want the services to start o restart, I don’t want to execute a restart when copying the config file.

Is there any other way to do taht without skiping handlers?

---

<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:** [June 7, 2015, 10:18am UTC](https://forum.ansible.com/t/skip-tags-doesnt-work-for-handlers/17596/8 "2015-06-07T10:18:22Z")

</div>

I tried with a “when” statement on the handler definition (with a variable defined by me) but id didn’t seem to work either, the handler is executed anyway, and the AMI creation fails for that.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 7, 2015, 9:47pm UTC](https://forum.ansible.com/t/skip-tags-doesnt-work-for-handlers/17596/9 "2015-06-07T21:47:32Z")

</div>

handlers are not affected by tags in general, but they should be  
affected by when:

---

<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:** [June 8, 2015, 8:46am UTC](https://forum.ansible.com/t/skip-tags-doesnt-work-for-handlers/17596/10 "2015-06-08T08:46:21Z")

</div>

Thanks Brian,

Is there a minimum version for the “when” statment to work with handlers?  
The ansible version I am using for this test is 1.7.2

I have:

# file: roles/beaver-configure/handlers/main.yml

- name: restart beaver  
service: name=beaver.sh state=restarted  
when: flag\_not\_restart is not defined

# file: roles/beaver-configure/tasks/main.yml

- name: Copy conf beaver  
template: src=../templates/conf.j2 dest=/etc/beaver/conf group=root owner=root mode=0644  
notify: restart beaver
- name: Start a enable beaver  
service: name=beaver.sh enabled=yes state=started

I call an ansible playbook which calls the beaver role with:  
/usr/local/bin/ansible-playbook /tmp/ansible-local/php.yml --extra-vars ‘flag\_not\_restart=1’ -c local -i /tmp/ansible-local/localhost.inv

If I debug the “flag\_not\_restart” I can see it exist and is “1”.  
And yet the “restart beaver” handler is called and executed.

So, am I doing something wrong?

---

<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:** [June 8, 2015, 12:37pm UTC](https://forum.ansible.com/t/skip-tags-doesnt-work-for-handlers/17596/11 "2015-06-08T12:37:07Z")

</div>

Sorry Brian,

My bad. It works with the “when” statement on the handler.
