<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">core</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<p dir="auto">ubuntu 16.04 package:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.0.0.2
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides"><pre class="notranslate"><code class="notranslate">ansible 2.0.0.2
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">nothing i know off</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">ubuntu 16.04</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">when executing a playbook with a tag (--tags), i would assume, that only tasks with this tag gets executed. in ansible 1.9 this was also true for handlers, but the behavior changed. in ansible 2.x handlers get called even though they don't have this tag assigned. the documentation is not telling, if this behavior is a new feature or bug.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<ol dir="auto">
<li>first call this playbook with "tag_a". everything is executed, which is expected:</li>
</ol>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible-playbook /etc/ansible/test.yml -vvvv -e target=test --tags tag_a"><pre class="notranslate"><code class="notranslate">ansible-playbook /etc/ansible/test.yml -vvvv -e target=test --tags tag_a
</code></pre></div>
<ol dir="auto">
<li>call this playbook with "tag_b". now the handler should not be executed, because it is missing tag_b:</li>
</ol>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible-playbook /etc/ansible/test.yml -vvvv -e target=test --tags tag_b"><pre class="notranslate"><code class="notranslate">ansible-playbook /etc/ansible/test.yml -vvvv -e target=test --tags tag_b
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
---
- hosts: &quot;{{ target | default('test') }}&quot;
  strategy: free
  roles:
    - { role: test }"><pre class="notranslate"><code class="notranslate">
---
- hosts: "{{ target | default('test') }}"
  strategy: free
  roles:
    - { role: test }
</code></pre></div>
<p dir="auto">tasks/main.yml:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
---
- name: do something
  debug: msg=&quot;done&quot;
  notify: restart some service
  changed_when: True
  tags:
    - tag_a
    - tag_b"><pre class="notranslate"><code class="notranslate">
---
- name: do something
  debug: msg="done"
  notify: restart some service
  changed_when: True
  tags:
    - tag_a
    - tag_b
</code></pre></div>
<p dir="auto">handler/main.yml:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
---
- name: restart some service
  debug: msg=&quot;restarting...&quot;
  tags:
    - tag_a"><pre class="notranslate"><code class="notranslate">
---
- name: restart some service
  debug: msg="restarting..."
  tags:
    - tag_a
</code></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">in ansible 1.9, only the "do something" task was executed, but not the handler, if playbook was called with "--tags tag_b".<br>
i would expect that tags are working on handlers as well, because it might be necessary to exclude some of those.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<p dir="auto">handler get executed even though tag_b is not assigned.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# ansible-playbook /etc/ansible/test.yml -vvvv -e target=test --tags tag_b
Using /etc/ansible/ansible.cfg as config file
Loaded callback default of type stdout, v2.0
1 plays in /etc/ansible/test.yml

PLAY ***************************************************************************

TASK [setup] *******************************************************************
&lt;192.168.1.190&gt; ESTABLISH SSH CONNECTION FOR USER: None
&lt;192.168.1.190&gt; SSH: EXEC ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o Port=1221 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r -tt 192.168.1.190 '( umask 22 &amp;&amp; mkdir -p &quot;$( echo $HOME/.ansible/tmp/ansible-tmp-1463148481.29-105122005378320 )&quot; &amp;&amp; echo &quot;$( echo $HOME/.ansible/tmp/ansible-tmp-1463148481.29-105122005378320 )&quot; )'
&lt;192.168.1.190&gt; PUT /tmp/tmpdAUJCD TO /root/.ansible/tmp/ansible-tmp-1463148481.29-105122005378320/setup
&lt;192.168.1.190&gt; SSH: EXEC sftp -b - -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o Port=1221 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r '[192.168.1.190]'
&lt;192.168.1.190&gt; ESTABLISH SSH CONNECTION FOR USER: None
&lt;192.168.1.190&gt; SSH: EXEC ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o Port=1221 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r -tt 192.168.1.190 'LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /root/.ansible/tmp/ansible-tmp-1463148481.29-105122005378320/setup; rm -rf &quot;/root/.ansible/tmp/ansible-tmp-1463148481.29-105122005378320/&quot; &gt; /dev/null 2&gt;&amp;1'
ok: [test]

TASK [test : do something] *****************************************************
task path: /etc/ansible/roles/test/tasks/main.yml:3
NOTIFIED HANDLER restart some service
ok: [test] =&gt; {
    &quot;msg&quot;: &quot;done&quot;
}

RUNNING HANDLER [test : restart some service] **********************************
ok: [test] =&gt; {
    &quot;msg&quot;: &quot;restarting...&quot;
}

PLAY RECAP *********************************************************************
test                      : ok=3    changed=1    unreachable=0    failed=0"><pre class="notranslate"><code class="notranslate"># ansible-playbook /etc/ansible/test.yml -vvvv -e target=test --tags tag_b
Using /etc/ansible/ansible.cfg as config file
Loaded callback default of type stdout, v2.0
1 plays in /etc/ansible/test.yml

PLAY ***************************************************************************

TASK [setup] *******************************************************************
&lt;192.168.1.190&gt; ESTABLISH SSH CONNECTION FOR USER: None
&lt;192.168.1.190&gt; SSH: EXEC ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o Port=1221 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r -tt 192.168.1.190 '( umask 22 &amp;&amp; mkdir -p "$( echo $HOME/.ansible/tmp/ansible-tmp-1463148481.29-105122005378320 )" &amp;&amp; echo "$( echo $HOME/.ansible/tmp/ansible-tmp-1463148481.29-105122005378320 )" )'
&lt;192.168.1.190&gt; PUT /tmp/tmpdAUJCD TO /root/.ansible/tmp/ansible-tmp-1463148481.29-105122005378320/setup
&lt;192.168.1.190&gt; SSH: EXEC sftp -b - -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o Port=1221 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r '[192.168.1.190]'
&lt;192.168.1.190&gt; ESTABLISH SSH CONNECTION FOR USER: None
&lt;192.168.1.190&gt; SSH: EXEC ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o Port=1221 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r -tt 192.168.1.190 'LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /root/.ansible/tmp/ansible-tmp-1463148481.29-105122005378320/setup; rm -rf "/root/.ansible/tmp/ansible-tmp-1463148481.29-105122005378320/" &gt; /dev/null 2&gt;&amp;1'
ok: [test]

TASK [test : do something] *****************************************************
task path: /etc/ansible/roles/test/tasks/main.yml:3
NOTIFIED HANDLER restart some service
ok: [test] =&gt; {
    "msg": "done"
}

RUNNING HANDLER [test : restart some service] **********************************
ok: [test] =&gt; {
    "msg": "restarting..."
}

PLAY RECAP *********************************************************************
test                      : ok=3    changed=1    unreachable=0    failed=0
</code></pre></div>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">Handlers should respect skip-tags. Currently they do not.</p>
<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Feature Idea</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">lib/ansible/playbook/taggable.py</p>
<h5 dir="auto">ADDITIONAL INFORMATION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- hosts: localhost
  gather_facts: false
  handlers:
    - name: debug_handler
      debug:
        msg: handler
      tags:
        - handlers
  tasks:
    - command: &quot;true&quot;
      notify:
        - debug_handler"><pre class="notranslate"><code class="notranslate">- hosts: localhost
  gather_facts: false
  handlers:
    - name: debug_handler
      debug:
        msg: handler
      tags:
        - handlers
  tasks:
    - command: "true"
      notify:
        - debug_handler
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ ansible-playbook --skip-tags handlers playbook.yml
PLAY [localhost] *****************************************************************************************************************************************************************************************************************************

TASK [command] *******************************************************************************************************************************************************************************************************************************
changed: [localhost]

RUNNING HANDLER [debug_handler] **************************************************************************************************************************************************************************************************************
ok: [localhost] =&gt; {
    &quot;msg&quot;: &quot;handler&quot;
}

PLAY RECAP ***********************************************************************************************************************************************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0"><pre class="notranslate"><code class="notranslate">$ ansible-playbook --skip-tags handlers playbook.yml
PLAY [localhost] *****************************************************************************************************************************************************************************************************************************

TASK [command] *******************************************************************************************************************************************************************************************************************************
changed: [localhost]

RUNNING HANDLER [debug_handler] **************************************************************************************************************************************************************************************************************
ok: [localhost] =&gt; {
    "msg": "handler"
}

PLAY RECAP ***********************************************************************************************************************************************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0
</code></pre></div>