After playing around some more I'll see if I can answer my own question. * notify is contained within the scope of a play * a role within a playbook constitutes a single play * notify does not propagate outside the play and will not be picked up by handlers outside of the play (i.e., role) * role dependencies will not allow you to propagate the notify across roles - it behaves as two separate, autonomous plays * handler names are global but the notify to invoke them is local to the role
I can move the handler to the role and it will execute. I would need to copy the handler to each role that could invoke it or include the other role handlers file within each role that needs it. I tried the include directive in the handlers file within the role so I didn't have to copy code across multiple roles -- didn't work for me, probably a relative path issue on my part. I think my best bet is to use post_tasks: within the playbook and execute the refresh regardless of the change state in each respective role. Please feel free to correct me if I've stated things incorrectly. On Friday, July 24, 2015 at 2:08:01 PM UTC-5, rmullinnix wrote: > > I probably have something structured wrong or it's something simple - but > I'm stuck trying to get handlers added to a playbook via include to fire. > The handlers from roles that are listed in the playbook fire correctly, > but the include ones do not. And the task with the notify has a changed: > true. > > Running ansible-playbook 2.0.0 (last pull on 7/18) on SLES > > Here's the playbook > --- > # This Playbook deploys the components for the webserver > # Apache, consului and kibana > > # setup and deploy apache > - hosts: webservers > become: yes > > roles: > - role: common > - role: apache > - role: consului > - role: kibana > > handlers: > - include: roles/consul/handlers/main.yml > - include: roles/consul-template/handlers/main.yml > > I'm using consul and consul-template to hold the config variables for the > components. I push a change to a consul-template file and expect the > handler 'refresh consultemplate' to run, but it does not. > > Here is the roles/consul-template/handlers/main.yml file > --- > # file: roles/consul-template/handlers/main.yml > - name: refresh consultemplate > shell: 'kill -1 $(cat /var/run/consul-template.pid)' > > - name: install consultemplate > command: /sbin/insserv -f consul-template > > - name: restart consultemplate > service: name=consul-template state=restarted > > And the task in the roles/kibana/tasks/main.yml with the notify > - name: Add consul-template ctmpl file > copy: src=kibana.ctmpl dest=/etc/consul-template/ctmpl/kibana.ctmpl > notify: refresh consultemplate > > > And the run > TASK [kibana : kibana : Add consul-template ctmpl file] > ************************* > changed: [XXXXXX] > > TASK [kibana : kibana : Add apache mod_proxy to connect to consul] > ************** > changed: [XXXXXX] > > RUNNING HANDLER [apache : restart apache] > *************************************** > changed: [XXXXXX] > > PLAY RECAP > ********************************************************************** > XXXXXX : ok=29 changed=8 unreachable=0 failed=0 > > So the handler I have in roles/apache/handlers/main.yml works correctly. > It's just the include handlers where the associated role is not in the > playbook > > Any help would be appreciated. > > > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c3921721-896d-431a-9e70-3b0d5d44d286%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
