-
Notifications
You must be signed in to change notification settings - Fork 24k
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 don't execute handlers in included #13485
Comments
Can confirm the issue on ansible 2.1.0 on Centos 6.6.
File roles/x/handlers/main.yml:
File roles/x/handlers/mysql.yml:
File roles/x/tasks/main.yml:
Not only the handler is not triggered, it does not throw any error if it does not exist. |
We're also seeing this after upgrading from Ansible 1.9.4 to 2.0.0-0.7.rc2 on OS X 10.11. |
Can you test devel or the stable-2.0 branch? This should be resolved. |
Thank you for replay. Name : ansible
Version : 2.1.0
Release : 0.git201512180409.a391d6f.stable20.el7.centos Playbook test.yml: ---
- hosts: lb
gather_facts: false
remote_user: root
tasks:
- include: roles/test/tasks/main.yml
handlers:
- include: roles/test/handlers/main.yml
- name: restart chrony
service:
name: chronyd
state: restarted roles/test/tasks/main.yml - name: Debug
command: /bin/true
notify:
- sshd restart
- restart chrony roles/test/handlers/main.yml - name: sshd restart
service:
name: sshd
state: restarted Result: $ ansible-playbook test.yml -vv
Using /home/rino/ansible/ansible.cfg as config file
1 plays in test.yml
PLAY ***************************************************************************
TASK [include] *****************************************************************
included: /home/rino/ansible/roles/test/tasks/main.yml for lb-transport.shire.local
TASK [Debug] *******************************************************************
NOTIFIED HANDLER sshd restart
NOTIFIED HANDLER restart chrony
changed: [lb-transport.shire.local] => {"changed": true, "cmd": ["/bin/true"], "delta": "0:00:00.003088", "end": "2015-12-18 11:21:55.788825", "rc": 0, "start": "2015-12-18 11:21:55.785737", "stderr": "", "stdout": "", "stdout_lines": [], "warnings": []}
RUNNING HANDLER [restart chrony] ***********************************************
changed: [lb-transport.shire.local] => {"changed": true, "name": "chronyd", "state": "started"}
PLAY RECAP *********************************************************************
lb-transport.shire.local : ok=3 changed=2 unreachable=0 failed=0 it's didn't work out. |
Checked it on the devel branch - [still does not work if the handler is in another file which is included in the role's handlers/main.yml file]:
File playbook.yml: - name: apply common configuration to all nodes
hosts: 127.0.0.1
connection: local
remote_user: vagrant
roles:
- common File roles/common/handlers/main.yml: - include: test.yml File roles/common/handlers/test.yml: - name: test handler
debug: msg="Yay" File roles/common/tasks/main.yml: - name: test task
command: /bin/true
notify: test handler Ansible output:
As you can see here, ansible indeed tries to notify the handler "test handler" but somehow it does not get included. If I move the handler from test.yml directly to main.yml it will get triggered successfully. |
I'm running into the same problem in If I put the handler in |
This is currently documented in the 2.0 known issues. This is a consequence of the fact that includes are now dynamic and not processed ahead of time, so Ansible doesn't know about tasks inside an include it hasn't processed yet. |
@jimi-c: could you please point to the document containing the known issues for 2.0? Such usage (
If handlers are not executed after all tasks complete, services will not be restarted and will stay running with old configuration. This can be a security risk and Ansible won't even warn about it. |
Is there a workaround for this? I have opted to keep all my handlers centrally and include them in playbooks for use in playbooks, and in roles. But now the only workaround seems to be that I re-define every handler inline in every playbook that needs them. Or is there another workaround besides downgrading back to 1.9? |
no workaround yet, we are working on a fix for v2 |
* if a Handler.get_name() is 'include', load and parse the file * Fixes ansible#13485
When is this issue going to be fixed? Seems fairly major for people that separated handlers from playbooks. |
Was very happy that finally includes are dynamic, and then I stumbled into this. Btw, wouldn't it be better to have an "include" that works as it used to in 1.9, and a "run" that would be evaluated dynamically? |
I've noticed that this works in the 2.0.0.1 branch. |
I'm gonna have to stick with Salt until this mess is sorted out. Trying to achieve any sense of composability with Ansible remains a nightmare. |
Any updates on this? |
haven't seen any comments on my pull request that should fix this: #14650 |
Just for reference: as @jimi-c wrote in #14650, the PR won't be included because there is an idea how to fix the issue with handlers in a different way, as discussed in the thread https://groups.google.com/forum/#!topic/ansible-devel/9aJaoVeRdOg |
For the project I'm working on, we really need the structured includes. I'm working around this issue for the time being in our codebase by moving the original handlers/main.yml to handlers/rightMain.yml and then using a script to generate the handlers/main.yml file:
Obviously this is a WFMYMMV scenario, but I've attached this here in the hope that it will help someone. |
👍 |
@alexmarkley yep, we're doing exactly the same with includes in our playbooks :( |
The static includes feature was merged in, and should resolve this for all use-cases (unless you're doing includes in a handler that does a loop). Is anyone still seeing this as an issue on the devel branch? |
it appears to work for me... @jimi-c can you add an integration test to prevent regression? I can open a pull request with the tests I had written if you want them. |
@d3matt yes please. I'll go ahead and close this out now though. Thanks! |
This appears to be broken again... bisected to:
:040000 040000 7094f976b8efdef066f8b960a8604fdd5774c1a5 49e2fc6154f45d8d57ad196b34eb5b37c7617ca1 M lib |
Confirmed this is broken again in 2.0.2.0 Edit: This is visible because EPEL has upgraded their Ansible version from 1.9.x to 2.0.2.0, which has this issue. If you're coming here because your playbooks have suddenly stopped working, the resolution (if you're on CentOS or RHEL) is this:
I've created a bugzilla ticket - https://bugzilla.redhat.com/show_bug.cgi?id=1336266 - that links here to reduce future confusion. |
This is not broken again, it was fixed in devel and included in the stable-2.1 branch, so it will be included in the 2.1 release. |
100% sure it's currently broken on devel and stable-2.1. I see NOTIFIED HANDLER , but it never runs. Matt On Sun, May 15, 2016 at 9:59 PM, James Cammarata notifications@github.com
|
Did you add "static: yes" per https://groups.google.com/d/msg/ansible-devel/9aJaoVeRdOg/B4TvRTLgCAAJ ? |
Interesting... until 438ed70, you didn't need to add static: yes to get included handlers to work... |
Should this be documented if |
This is broken in 2.1.1.0? So if I had a some_role/tasks/main.yml
What should I do? |
Hello, FYI, the install of 2.1.2.0 broke pretty much all my handlers called in included files. tasks/main.yml:
tasks/foo.yml
handlers/main.yml
I've the following error: ERROR! The requested handler 'bar' was not found in the main handlers list Rémi |
I have exactly the same problem as @darkweaver87 with |
I have the same issue in Without cat roles/dgate-deploy/tasks/main.yml: ---
- include: tasks/create_service_user.yml
- include: tasks/create_service_dirs.yml
with_items:
- "{{service_install_dir}}"
- "/etc/{{service_name}}"
- include: tasks/copy_files.yml
with_items:
- src: "../dgate-{{service_version}}-fat.jar"
dst: "{{service_install_dir}}"
- src: "../{{dgate_conf}}"
dst: "/etc/{{service_name}}/"
- src: "../dgate.jceks"
dst: "{{service_install_dir}}"
notify:
- "restart {{service_name}}"
- include: tasks/create_service_script.yml
notify:
- "restart {{service_name}}"
- include: tasks/create_service_default.yml
notify:
- "restart {{service_name}}"
- stat:
path: "/etc/init/{{service_name}}.conf"
register: service_script
- include: tasks/start_service.yml
when:
service_script.stat.exists == True cat roles/dgate-deploy/handlers/main.yml: - include: handlers/restart_service.yml
when:
service_script.stat.exists == True cat handlers/restart_service.yml: - name: "restart {{service_name}}"
service:
name: "{{service_name}}"
state: restarted
Without any handlers trigger. |
Do you have "handler_includes_static = True" in your ansible.cfg? |
@nirik Thanks, but I can't find this config in configuration. But it's still not working. I've already set
in Also, I've tried modify $ cat roles/dgate-deploy/handlers/main.yml ---
#- include: handlers/restart_service.yml
- name: restart dgate
service:
name: dgate
state: restarted
when:
service_script.stat.exists == True |
Sorry, it's my fault. I find the reason: #6094
|
ansible/ansible#13485. Moved to main.yml. Removed unused handlers and its include files. Signed-off-by: Mariano Barcia <mariano.barcia@gmail.com>
Including handlers works beautifully for me in Ansible 2.2.1.0. Make sure you have |
When I include a file in a handler, the tasks in the included file are not executed in ansible 2.0.
Playbook redis.yml:
roles/firewall/handlers/main.yml
roles/firewall/tasks/firewall_open_port.yml
For ansible 1.9.4:
roles/firewall/tasks/iptables/iptables_open_port.yml
For ansible 2.0:
roles/firewall/tasks/iptables/iptables_open_port.yml
Result:
When I replace in playbook:
to
it's work well. It's bug or my mistake?
The text was updated successfully, but these errors were encountered: