Skip to content

Handlers don't execute handlers in included #13485

Description

@galiev

When I include a file in a handler, the tasks in the included file are not executed in ansible 2.0.
Playbook redis.yml:

---
- hosts: redis
  gather_facts: true
  vars:
    os_firewall_use_firewalld: false
    port_open: "{{ redis_port|default(6379) }}"
  tasks:
    - include: roles/firewall/tasks/firewall_open_port.yml
  handlers:
    - include: roles/firewall/handlers/main.yml

roles/firewall/handlers/main.yml

- name: save iptables
  shell: service iptables save

roles/firewall/tasks/firewall_open_port.yml

- include: iptables/iptables_open_port.yml
  when: not os_firewall_use_firewalld

For ansible 1.9.4:
roles/firewall/tasks/iptables/iptables_open_port.yml

- name: Open port
  shell: iptables -A INPUT -m conntrack --ctstate NEW -p tcp --dport "{{ port_open }}" -j ACCEPT
  notify:
    - save iptables

For ansible 2.0:
roles/firewall/tasks/iptables/iptables_open_port.yml

- name: Open port 
  iptables:
    chain: INPUT
    ctstate: NEW
    protocol: tcp
    destination_port: "{{ port_open }}"
    jump: ACCEPT
  notify:
    - save iptables

Result:

ansible --version
ansible 1.9.4
  configured module search path = None
PLAY [redis] ****************************************************************** 

GATHERING FACTS *************************************************************** 
ok: [redis-01-transport.shire.local]
ok: [redis-02-transport.shire.local]

TASK: [Open port] ********************************************* 
changed: [redis-01-transport.shire.local]
changed: [redis-02-transport.shire.local]

NOTIFIED: [save iptables] ***************************************************** 
changed: [redis-01-transport.shire.local]
changed: [redis-02-transport.shire.local]

PLAY RECAP ******************************************************************** 
redis-01-transport.shire.local : ok=3    changed=2    unreachable=0    failed=0   
redis-02-transport.shire.local : ok=3    changed=2    unreachable=0    failed=0   
 ansible --version
ansible 2.0.0
  config file = /home/rino/ansible/ansible.cfg
  configured module search path = Default w/o overrides
PLAY ***************************************************************************

TASK [setup] *******************************************************************
ok: [redis-01-transport.shire.local]
ok: [redis-02-transport.shire.local]

TASK [include] *****************************************************************
included: /home/rino/ansible/roles/firewall/tasks/firewall_open_port.yml for redis-01-transport.shire.local, redis-02-transport.shire.local

TASK [include] *****************************************************************
included: /home/rino/ansible/playbooks/../roles/firewall/tasks/iptables/iptables_open_port.yml for redis-02-transport.shire.local, redis-01-transport.shire.local

TASK [Open port] **********************************************************
changed: [redis-01-transport.shire.local]
changed: [redis-02-transport.shire.local]

PLAY RECAP *********************************************************************
redis-01-transport.shire.local : ok=4    changed=1    unreachable=0    failed=0   
redis-02-transport.shire.local : ok=4    changed=1    unreachable=0    failed=0

When I replace in playbook:

  handlers:
    - include: roles/firewall/handlers/main.yml

to

handlers:
  - name: save iptables
    shell: /usr/libexec/iptables/iptables.init save

it's work well. It's bug or my mistake?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue/PR relates to a bug.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions