TASK [reboot_host_normal : Reboot host] ************************* changed: [x.x.x.x] TASK [reboot_host_normal : set_fact] **************************** ok: [x.x.x.x] TASK [reboot_host_normal : set_fact] ***************************** ok: [x.x.x.x] TASK


tasks file for reboot_host

Reboot a node

  • name: Reboot host
    shell: ( sleep 5 && /sbin/shutdown -r now “Reboot triggered by Ansible” & )
    async: 1
    poll: 0
    ignore_errors: true
    become: true
    register: host_reboot

  • set_fact:
    role_name1: “{{ role_path | basename }}”
    register_out: “{{ host_reboot }}”

  • set_fact:
    register_out_log: “{{ register_out }}”

  • name: Display hosts being rebooted
    debug:
    msg: “Waiting for host <{{ inventory_hostname }}> to reboot”
    when: host_reboot.changed

  • name: Wait for host to boot
    wait_for_connection:
    connect_timeout: 20
    sleep: 5
    delay: 5
    timeout: 600
    ignore_errors: yes
    when: host_reboot is changed
    register: wait_for_host_to_boot

  • name: Debug wait for reboot
    debug:
    msg: “{{ wait_for_host_to_boot }}”

  • name: Verify ssh connection to host
    local_action: wait_for
    args:
    host: “{{ inventory_hostname }}”
    port: 22
    delay: 5
    sleep: 1
    connect_timeout: 5
    timeout: 600
    search_regex: OpenSSH
    become: false
    when: wait_for_host_to_boot is succeeded
    register: host_ssh_test

  • name: Get host’s name to verify host is running
    command: hostname
    register: hostname_output
    when: host_ssh_test is succeeded

  • name: Display host’s name
    debug:
    msg: “Host <{{ hostname_output.stdout_lines[0] }}> has rebooted”
    when: hostname_output.changed

after executing this task it is continuously hanged at TASK [reboot_host_normal : Wait for host to boot]
plz help me how to come out after 10 mins waiting time.

do you really expect anybody to attempt to decipher the mess spread over title and body which hasn’t even a modicum of formatting on it?

1 Like

Actually my task is hanged here. How to over come from this.
Actually this in properindentation in my plabook. At the time of copy pasting time indentation is missing.

Instead of reinventing wheels and shell pipes, why not use the reboot module and be done with it?
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/reboot_module.html

You can use triple backticks (```) on the line before and after a block of YAML to preserve the format:

- name: Wait for host to boot
  wait_for_connection:
    connect_timeout: 20
    sleep: 5
    delay: 5
    timeout: 600
  ignore_errors: yes
  when: host_reboot is changed
  register: wait_for_host_to_boot

Not sure if this is the issue you’re experiencing, but if you’re using interpreter discovery, wait_for_connection uses the original discovered interpreter after reboot, instead of trying to rediscover it. If the previous interpreter no longer exists, that would cause a timeout (also reported as an issue here wait_for_connection does not discover new python interpreter after reboot · Issue #82804 · ansible/ansible · GitHub).