Reputation: 65
I have a fresh install of Ansible 2.9.17 and everything works great except handlers :-/
For some reason my ~roles/myservice/handlers/main.yml are not loaded UNLESS I include: the handlers: after every hosts: line in my main.yml files.
example:
handlers:
- import_tasks: ../handlers/main.yml
I can do this but I find specifying the "same handler" again and again per host: entry annoying. This cant be the best practice of ansible to do it this way. Anyone else experience this issue before? There must be a config I'm missing...
~/roles/myservice/
├── handlers
│ └── main.yml
├── tasks
└── main.yml
- name: restart myservice
service:
name: myservice
state: restarted
become: yes
listen: restart myservice
- name: Installing myservice
become: yes
become_user: root
yum:
name: myservice.rpm
notify:
- restart myservice
$ ansible-playbook -i hosts roles/myservice/tasks/main.yml --limit myservice
PLAY [myservice] ***********************************************************************************************************************************************************************
TASK [Gathering Facts] ********************************************************************************************************************************************************************************************* ok: [myservice]
TASK [Install myservice.] ************************************************************************************************************************************************************************************** ok: [myservice]
TASK [Gathering Facts] ********************************************************************************************************************************************************************************************* ok: [myservice]
TASK [Installing myservice] ******************************************************************************************************************************** ERROR! The requested handler 'restart myservice' was not found in either the main handlers list nor in the listening handlers list
Upvotes: 0
Views: 2056
Reputation: 1954
You are executing the main.yml
file as a playbook, you need to create a playbook that executes the role
- name: Playbook
gather_facts: false
hosts: all
roles:
- myservice
Upvotes: 3