Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handlers executed repeatedly #19647

Closed
sdarwin opened this issue Dec 22, 2016 · 1 comment · Fixed by #19655
Closed

handlers executed repeatedly #19647

sdarwin opened this issue Dec 22, 2016 · 1 comment · Fixed by #19655
Labels
affects_2.2 This issue/PR affects Ansible v2.2 affects_2.3 This issue/PR affects Ansible v2.3 bug This issue/PR relates to a bug. P2 Priority 2 - Issue Blocks Release

Comments

@sdarwin
Copy link

sdarwin commented Dec 22, 2016

ISSUE TYPE
  • Bug Report
COMPONENT NAME

handlers

ANSIBLE VERSION
ansible 2.3.0 (devel 5f0815d7f4) last updated 2016/12/22 19:01:55 (GMT +000)
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides

this is the latest devel branch from "git pull"
CONFIGURATION
OS / ENVIRONMENT

Ubuntu 14.04.1 , Centos 7.1

SUMMARY

Handlers should only be triggered once, per the documentation, but they are triggered more than once.

"These ‘notify’ actions are triggered at the end of each block of tasks in a play, and will only be triggered once even if notified by multiple different tasks. For instance, multiple resources may indicate that apache needs to be restarted because they have changed a config file, but apache will only be bounced once to avoid unnecessary restarts."

STEPS TO REPRODUCE

create a role, as follows:

test/tasks/main.yml:
---
- shell: echo testing
  notify: handler1

- shell: echo testing
  notify: handler1

- shell: echo testing
  notify: handler1
  
test/handlers/main.yml
---
- name: handler1
  shell: echo "1" >> /tmp/test.txt
  
test/test.yml:
---
    - hosts: all
      remote_user: ansible
      become: true
      roles:
        - { role: 'test' }

run the playbook:
cd test
ansible-playbook test.yml

EXPECTED RESULTS

/tmp/test.txt would contain a single "1"

ACTUAL RESULTS

/tmp/test.txt has three "1" values in it, corresponding to the handler running three times.

ansible-playbook test.yml

PLAY [all] *********************************************************************************************************************

TASK [Gathering Facts] *********************************************************************************************************
ok: [localhost]

TASK [test : command] **********************************************************************************************************
GOT A NOTIFY
TRYING TO SEND NOTIFICATION TO HANDLER: handler1
changed: [localhost]

TASK [test : command] **********************************************************************************************************
GOT A NOTIFY
TRYING TO SEND NOTIFICATION TO HANDLER: handler1
changed: [localhost]

TASK [test : command] **********************************************************************************************************
GOT A NOTIFY
TRYING TO SEND NOTIFICATION TO HANDLER: handler1
changed: [localhost]

RUNNING HANDLER [test : handler1] **********************************************************************************************
changed: [localhost]
changed: [localhost]
changed: [localhost]

PLAY RECAP *********************************************************************************************************************
localhost                  : ok=7    changed=6    unreachable=0    failed=0

@ansibot ansibot added affects_2.3 This issue/PR affects Ansible v2.3 bug_report needs_triage Needs a first human triage before being processed. labels Dec 22, 2016
@nitzmahone nitzmahone added affects_2.2 This issue/PR affects Ansible v2.2 P2 Priority 2 - Issue Blocks Release and removed needs_triage Needs a first human triage before being processed. labels Dec 22, 2016
@nitzmahone
Copy link
Member

nitzmahone commented Dec 22, 2016

Verified broken in devel and on 2.2.1- should be addressed before next RC (including an integration test).

nitzmahone added a commit to nitzmahone/ansible that referenced this issue Dec 23, 2016
Fixes ansible#19647
Adds integration test to catch multiple handler notifications
nitzmahone added a commit that referenced this issue Dec 23, 2016
Fixes #19647
Adds integration test to catch multiple handler notifications
nitzmahone added a commit that referenced this issue Dec 23, 2016
Fixes #19647
Adds integration test to catch multiple handler notifications
(cherry picked from commit c249567)
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.2 This issue/PR affects Ansible v2.2 affects_2.3 This issue/PR affects Ansible v2.3 bug This issue/PR relates to a bug. P2 Priority 2 - Issue Blocks Release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants