ERROR! The requested handler 'Reboot host' was not found

Hello,

I have a weired issue and I have no idea what could be the issue. Ansible-lint did report nothing.

$ pipenv run ansible-playbook plays_prod/70_update_homelab.yml

PLAY [Update Proxmox Cluster] ******************************************************************************************

TASK [Gathering Facts] *************************************************************************************************
ok: [pve1]

TASK [Run updates] *****************************************************************************************************
ERROR! The requested handler 'Reboot host' was not found in either the main handlers list nor in the listening handlers list

# code: language=ansible

- name: Update Proxmox Cluster
  hosts: proxmox_nodes, &managed
  gather_facts: true
  serial: 1

  module_defaults:
    group/community.general.proxmox:
      api_host: "{{ proxmox_api_host }}"
      api_user: "{{ proxmox_api_user }}"
      api_token_id: "{{ proxmox_api_token_id }}"
      api_token_secret: "{{ proxmox_api_token_secret }}"
      validate_certs: true

    ansible.builtin.shell:
      executable: /bin/bash  # ansible-lint expects the pipefail option, which is available in bash only

  tasks:
    - name: Run updates
      ansible.builtin.apt:
        upgrade: dist
        update_cache: true
      register: result
      changed_when: true  # For testing the handler
      notify: Reboot host

  handlers:
    - name: Reboot host
      block:
        - name: Check HA status
          ansible.builtin.command:
            cmd: ha-manager status
          register: result
          failed_when: "'maintenance mode' in result.stdout"
          changed_when: false

        - name: Enable maintainance mode
          ansible.builtin.command:
            cmd: ha-manager crm-command node-maintenance enable {{ inventory_hostname_short }}
          changed_when: false

        - name: Wait for maintainance mode
          ansible.builtin.shell:
            cmd: |
              set -o pipefail
              ha-manager status | grep '^lrm {{ inventory_hostname_short }}'
          register: result
          until: "'maintenance mode' in result.stdout"
          retries: 60
          delay: 5
          changed_when: false

        - name: Wait for guest migration
          ansible.builtin.shell:
            cmd: |
              set -o pipefail
              ha-manager status | grep '^service'
          register: result
          until: inventory_hostname_short not in result.stdout
          retries: 60
          delay: 5
          changed_when: false

        - name: Reboot
          when: "'/var/run/reboot-required' is file"
          ansible.builtin.reboot:
            reboot_timeout: 600

        - name: Deactivate maintenance mode
          ansible.builtin.command:
            cmd: ha-manager crm-command node-maintenance disable {{ inventory_hostname_short }}
          changed_when: false

        - name: Wait for maintenance mode deactivation
          ansible.builtin.shell:
            cmd: |
              set -o pipefail
              ha-manager status | grep '^lrm {{ inventory_hostname_short }}'
          register: result
          until: "('idle' in result.stdout) or ('active' in result.stdout)"
          retries: 60
          delay: 5
          changed_when: false

# ... two more plays, without handlers

This was working until last week. I have no idea what changed in between (According to git, I only updated the “hosts” line, but it worked before I commited)

Maybe anyone have an idea…

Thanks a lot!
Thomas

block cannot be used as a handler. You would need to include all tasks within the “Reboot host” block into a separate file and have a handler like below to achieve such functionality:

handlers:
  - name: Reboot host
    include_tasks: reboot_host_tasks.yml
1 Like