Handlers called but not working

16 views
Skip to first unread message

Leam Hall

unread,
Oct 18, 2018, 10:01:55 AM10/18/18
to Ansible Project
In the ansible output it says:

  META:  ran handlers

For this role handlers/main.yml is:

- name: restart_and_enable_httpd
  service:
    name:     httpd
    state:    restarted
    enabled:  true

This is Ansible 2.6 on RHEL 6. httpd is installed earlier in the process but at the end it is not running nor is it turned on per checkconfig. 

What am I missing, besides a brain, a clue, and a life?

Thanks!

Leam

Kai Stian Olstad

unread,
Oct 18, 2018, 11:37:43 AM10/18/18
to ansible...@googlegroups.com
On Thursday, 18 October 2018 16.01.55 CEST Leam Hall wrote:
> In the ansible output it says:
>
> META: ran handlers

This indicates that it run all the handler that was notified so that mean not necessarily all the handlers.


> For this role handlers/main.yml is:
>
> - name: restart_and_enable_httpd
> service:
> name: httpd
> state: restarted
> enabled: true
>
>
> This is Ansible 2.6 on RHEL 6. httpd is installed earlier in the process but at the end it is not running nor is it turned on per checkconfig.

Did you add a notify on this install task?


--
Kai Stian Olstad


Leam Hall

unread,
Oct 18, 2018, 11:47:23 AM10/18/18
to ansible...@googlegroups.com
On Thu, Oct 18, 2018 at 11:37 AM Kai Stian Olstad <ansible-pr...@olstad.com> wrote:
On Thursday, 18 October 2018 16.01.55 CEST Leam Hall wrote:
> In the ansible output it says:
>
>   META:  ran handlers

This indicates that it run all the handler that was notified so that mean not necessarily all the handlers.


Ah, good to know! There are 4 places where the handler is called, which was another question.  


> For this role handlers/main.yml is:
>
> - name: restart_and_enable_httpd
>   service:
>     name:     httpd
>     state:    restarted
>     enabled:  true
>
>
> This is Ansible 2.6 on RHEL 6. httpd is installed earlier in the process but at the end it is not running nor is it turned on per checkconfig.

Did you add a notify on this install task?

Yes, with the note that I actually fixed the handler names to match.  

# tasks/main.yml

- include: install_httpd.yml

- include: cat1.yml
  when: apache_cat1 | bool
  notify: restart_httpd

- include: cat2.yml
  when: apache_cat2 | bool
  notify: restart_httpd
- include: cat3.yml
  when: apache_cat3 | bool
  notify: restart_httpd

 

Kai Stian Olstad

unread,
Oct 18, 2018, 11:56:15 AM10/18/18
to ansible...@googlegroups.com
On Thursday, 18 October 2018 17.47.02 CEST Leam Hall wrote:
> Yes, with the note that I actually fixed the handler names to match.
>
> # tasks/main.yml
>
> - include: install_httpd.yml
>
> - include: cat1.yml
> when: apache_cat1 | bool
> notify: restart_httpd

include has only ok and failed status and not changed.
It's the changed that trigger a notify, so you need to have the notify on the install task instead.

--
Kai Stian Olstad


Leam Hall

unread,
Oct 18, 2018, 2:12:04 PM10/18/18
to ansible...@googlegroups.com
Kai, thanks! I made the restart a playbook of it's own since everything else could be optioned out at some point in time. 

Leam 
Reply all
Reply to author
Forward
0 new messages