Issue 1:
ISSUE TYPE

Bug Report

COMPONENT NAME

handlers

ANSIBLE VERSION

2.2.1.0

CONFIGURATION

OS / ENVIRONMENT

N/A

SUMMARY

Handlers with include statement are called multipled times (as many times as notify).

STEPS TO REPRODUCE

- name: Testing notify handler with include
hosts: blue
become: True
tasks:
- command: id
notify: restart test
- command: id
notify: restart test
- command: id
notify: restart test
- command: id
notify: restart test
handlers:
- name: restart test
include: tasks/restart_test.yml

And the restart_test.yml:

- name: Restart test (we use NTP)
service: name=ntp state=restarted

Output

ansible-playbook test-restart.yml

PLAY [Testing notify handler with include] *************************************

TASK [setup] *******************************************************************
ok: [host01]

TASK [command] *****************************************************************
changed: [host01]

TASK [command] *****************************************************************
changed: [host01]

TASK [command] *****************************************************************
changed: [host01]

TASK [command] *****************************************************************
changed: [host01]

RUNNING HANDLER [Restart test (we use NTP)] ************************************
changed: [host01]
changed: [host01]
changed: [host01]
changed: [host01]

PLAY RECAP *********************************************************************
host01 : ok=9 changed=8 unreachable=0 failed=0

EXPECTED RESULTS

Handler should be executed only once.

ACTUAL RESULTS

Handler being call as many times as notify

Issue 2:
ISSUE TYPE

Bug Report

COMPONENT NAME

handlers

ANSIBLE VERSION

ansible 2.2.0.0
config file = /home/duck/project/ansible.cfg
configured module search path = Default w/o overrides

This is RC2.

CONFIGURATION

only the roles path is modified.

OS / ENVIRONMENT

Running on Debian unstable and managing CentOS 7.

SUMMARY

To chain multiple actions in a handler I include a file, and this leads to the handler being fired multiple times.

STEPS TO REPRODUCE

I used an include as suggested workaround for #14270.

My handler defined in handlers/main.yml:

- name: restart networkd
include: apply_config.yml

The apply_config.yml file contains:

- name: reboot
# workaround for https://github.com/ansible/ansible/issues/14413
shell: "nohup bash -c 'sleep 2 && shutdown -r now' &"
async: 0
poll: 0
ignore_errors: true

- name: waiting for server to be up
local_action:
module: wait_for
host: "{{ ansible_host | default(inventory_hostname) }}"
port: 22
state: started
delay: 5
timeout: 600
become: no

# ensure the facts are updated
- setup:

EXPECTED RESULTS

Several changes (during roles tasks) call this trigger, but it should only be executed once.

ACTUAL RESULTS

As you can see it is executed 5 times and breaks playbook execution:

TASK [networkd : enable networkd] **********************************************
changed: [myhost.mydom.tld]

RUNNING HANDLER [networkd : reboot] ********************************************
fatal: [myhost.mydom.tld]: UNREACHABLE! => {"changed": false, "msg": "SSH Error: data could not be sent to the remote host. Make sure this host can be reached over ssh", "unreachable": true}
fatal: [myhost.mydom.tld]: UNREACHABLE! => {"changed": false, "msg": "SSH Error: data could not be sent to the remote host. Make sure this host can be reached over ssh", "unreachable": true}
fatal: [myhost.mydom.tld]: UNREACHABLE! => {"changed": false, "msg": "SSH Error: data could not be sent to the remote host. Make sure this host can be reached over ssh", "unreachable": true}
changed: [myhost.mydom.tld]
fatal: [myhost.mydom.tld]: UNREACHABLE! => {"changed": false, "msg": "SSH Error: data could not be sent to the remote host. Make sure this host can be reached over ssh", "unreachable": true}

RUNNING HANDLER [networkd : waiting for server to be up] ***********************
ok: [myhost.mydom.tld -> 192.168.57.10]
ok: [myhost.mydom.tld -> 192.168.57.10]
ok: [myhost.mydom.tld -> 192.168.57.10]
ok: [myhost.mydom.tld -> 192.168.57.10]
ok: [myhost.mydom.tld -> 192.168.57.10]

RUNNING HANDLER [networkd : setup] *********************************************
ok: [myhost.mydom.tld]
ok: [myhost.mydom.tld]
ok: [myhost.mydom.tld]
ok: [myhost.mydom.tld]
ok: [myhost.mydom.tld]
to retry, use: --limit @/home/duck/OSAS/community-cage-infra-ansible/playbooks/deploy.retry