Command run: sudo ansible-playbook site.yml --connection=local

Distributor ID: Ubuntu
Description:    Ubuntu 18.04 LTS
Release:        18.04
Codename:       bionic

ansible 2.5.5

I'm encountering this error only on my first run through after I change the following variable in the following file:


ntpserver: pool.ntp.org

TASK [common : Configure NTP file] ************************************************************************************************************** ERROR! The requested handler 'restart ntp' was not found in either the main handlers list nor in the listening handlers list

On my second run through, I'm having no issues:

TASK [common : Configure NTP file] ************************************************************************************************************** ok: [] => {"changed": false, "checksum": "cc9e1a2d8777588fa4675e52f7ca7e352b23188a", "dest": "/etc/ntp.conf", "gid": 0, "group": "root", "mode": "0644", "owner": "root", "path": "/etc/ntp.conf", "size": 139, "state": "file", "uid": 0}

The folder and file structure I'm using is as follows:



- name: Restart NTP
  service: name=ntpd state=restarted`


- name: Install NTP
  apt: name=ntp state=present
  tags: ntp

- name: Configure NTP file
  template: src=ntp.conf.j2 dest=/etc/ntp.conf
  tags: ntp
  notify: restart ntp

- name: Install common packages
  apt: name={{ item }} state=present
    - fail2ban
    - ranger

- name: Start the NTP service
  service: name=ntp state=started enabled=yes
  tags: ntp

- name: Upgrade all packages to the latest version
  become: true
    upgrade: yes
    update_cache: yes
    cache_valid_time: 86400 # one-day

3 Answers 3


The name of the handler "Restart NTP" does not match the handler notified "restart ntp". This is the reason of the error.

On the second run the configuration file /etc/ntp.conf did not change ("changed": false). Therefor the handler was not notified, was not looked for, and no error was reported.


I just found out the hard way. handlers only works with include_tasks not import_tasks .

The error message is rather missdirecting. I went all in adjusting indentation, syntax check and all . Finally I recreate the whole playbook but still fail. Finally switch to include_tasks then it works.



Ansible is case sensitive, hence a != A

Therefore, the correct code should look like this:

- name: Configure NTP file
  template: src=ntp.conf.j2 dest=/etc/ntp.conf
  tags: ntp
  notify: Restart NTP
  • That seems to be identical to what has been suggested 2 years earlier. Can you elaborate the difference? Apr 12, 2022 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.