Error: The requested handler was not found

1,385 views
Skip to first unread message

Shlomit Afgin

unread,
Nov 16, 2017, 5:48:27 AM11/16/17
to Ansible Project


I have ansible 2.5. the ymal file have:

- name: Make sure file1.conf update
  copy:
    src: file1.conf
    dest: /tmp/file1.conf
  tags: copy-file1
  notify:
  - cat file1

  handlers:
    - name: cat file1
      command: cat /tmp/file1.conf > /tmp/dates

when I run ansible-playbook I get:

ERROR! The requested handler 'cat file1' was not found in either the main handlers list nor in the listening handlers list

Any ideas?
Thanks

Kai Stian Olstad

unread,
Nov 16, 2017, 5:58:45 AM11/16/17
to ansible...@googlegroups.com
On 16.11.2017 11:48, Shlomit Afgin wrote:
> I have ansible 2.5. the ymal file have:
>
> - name: Make sure file1.conf update
> copy:
> src: file1.conf
> dest: /tmp/file1.conf
> tags: copy-file1
> notify:
> - cat file1
>
> handlers:
> - name: cat file1
> command: cat /tmp/file1.conf > /tmp/dates

Is this the complete file? Is it a playbook?
If so, you are missing a lot of things.


> when I run ansible-playbook I get:
>
> ERROR! The requested handler 'cat file1' was not found in either the
> main
> handlers list nor in the listening handlers list

You handlers: is indented incorrect, it should be at the same level as
the tasks:


--
Kai Stian Olstad

Shlomit Afgin

unread,
Nov 16, 2017, 9:03:18 AM11/16/17
to Ansible Project


The file contain this yml lines is  roles/basic/tasks/main.yml. (start with ---)
I run it with command:  'ansible-playbook   site.yml'
In site.yml it's have:
---                           
- hosts: cns  
  roles:                                                           
  - basic

hosts define in /etc/ansible/hosts.
Do I still have things missing?

Thanks a lot.

Kai Stian Olstad

unread,
Nov 16, 2017, 9:13:59 AM11/16/17
to ansible...@googlegroups.com
On Thursday, 16 November 2017 15.03.18 CET Shlomit Afgin wrote:
>
> The file contain this yml lines is roles/basic/tasks/main.yml. (start with
> ---)
> I run it with command: 'ansible-playbook site.yml'
> In site.yml it's have:
> ---
> - hosts: cns
> roles:
> - basic
>
> hosts define in /etc/ansible/hosts.
> Do I still have things missing?

When you are using roles, handlers goes in a separate directory called handles.
So you need to move your handler to roles/basic/handlers/main.yml.


--
Kai Stian Olstad

Shlomit Afgin

unread,
Nov 16, 2017, 9:18:12 AM11/16/17
to Ansible Project
Thanks a lot! Your questions help me solve the problem. 

The solution is to move the handler part to  roles/basic/handlers/main.yml
without the 'handlers:' label.

Thanks again
Reply all
Reply to author
Forward
0 new messages