Issue 1:
ISSUE TYPE

Bug Report

COMPONENT NAME

core

ANSIBLE VERSION

ubuntu 16.04 package:

ansible 2.0.0.2
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides

CONFIGURATION

nothing i know off

OS / ENVIRONMENT

ubuntu 16.04

SUMMARY

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.

STEPS TO REPRODUCE

first call this playbook with "tag_a". everything is executed, which is expected:

ansible-playbook /etc/ansible/test.yml -vvvv -e target=test --tags tag_a

call this playbook with "tag_b". now the handler should not be executed, because it is missing tag_b:

ansible-playbook /etc/ansible/test.yml -vvvv -e target=test --tags tag_b

---
- hosts: "{{ target | default('test') }}"
strategy: free
roles:
- { role: test }

tasks/main.yml:

---
- name: do something
debug: msg="done"
notify: restart some service
changed_when: True
tags:
- tag_a
- tag_b

handler/main.yml:

---
- name: restart some service
debug: msg="restarting..."
tags:
- tag_a

EXPECTED RESULTS

in ansible 1.9, only the "do something" task was executed, but not the handler, if playbook was called with "--tags tag_b".

i would expect that tags are working on handlers as well, because it might be necessary to exclude some of those.

ACTUAL RESULTS

handler get executed even though tag_b is not assigned.

# 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] *******************************************************************
<192.168.1.190> ESTABLISH SSH CONNECTION FOR USER: None
<192.168.1.190> 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 && mkdir -p "$( echo $HOME/.ansible/tmp/ansible-tmp-1463148481.29-105122005378320 )" && echo "$( echo $HOME/.ansible/tmp/ansible-tmp-1463148481.29-105122005378320 )" )'
<192.168.1.190> PUT /tmp/tmpdAUJCD TO /root/.ansible/tmp/ansible-tmp-1463148481.29-105122005378320/setup
<192.168.1.190> 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]'
<192.168.1.190> ESTABLISH SSH CONNECTION FOR USER: None
<192.168.1.190> 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/" > /dev/null 2>&1'
ok: [test]

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

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

PLAY RECAP *********************************************************************
test : ok=3 changed=1 unreachable=0 failed=0

Issue 2:
SUMMARY

Handlers should respect skip-tags. Currently they do not.

ISSUE TYPE

Feature Idea

COMPONENT NAME

lib/ansible/playbook/taggable.py

ADDITIONAL INFORMATION

- hosts: localhost
gather_facts: false
handlers:
- name: debug_handler
debug:
msg: handler
tags:
- handlers
tasks:
- command: "true"
notify:
- debug_handler

$ ansible-playbook --skip-tags handlers playbook.yml
PLAY [localhost] *****************************************************************************************************************************************************************************************************************************

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

RUNNING HANDLER [debug_handler] **************************************************************************************************************************************************************************************************************
ok: [localhost] => {
"msg": "handler"
}

PLAY RECAP ***********************************************************************************************************************************************************************************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=0