Ansible error during server reboot

Hi I’m getting below error during sw upgrade of a server using Ansible. Remote machine is linux server. Note that the reboot is not initiated by Ansible. At the end of the sw upgrade the server reboot automatically (application initiated reboot). Can anybody help?

fatal: [192.168.1.131]: UNREACHABLE! => {“changed”: false, “msg”: “Failed to connect to the host via ssh: Shared connection to ****(server IP) closed.\r\n”, “unreachable”: true}

Script.

- hosts: remote_server 
  remote_user: ansible
  become: yes
  become_method: sudo
  connection: ssh
  gather_facts: yes
  vars:
     ansible_ssh_host: **** (host IP) 
     ansible_ssh_port: 22 
  tasks:
  - name: Install SW version xxx
    ....
    ....

  - name: waiting for server to reboot
    wait_for: host="{{ ansible_ssh_host | default(inventory_hostname) }}" port={{ ansible_ssh_port | default(22) }} search_regex=OpenSSH delay=60 timeout=300 
    connection: local
    sudo: false  

  - shell: uptime
    register: output
  - debug: msg=" {{ output.stdout }} "

not seen any reboot command after

- name: Install SW version xxx

The host reboots as part of “Install SW version xxx”

Thanks
Arnab

Hi I'm getting below error during sw upgrade of a server using Ansible.
Remote machine is linux server. Note that the reboot is not initiated by
Ansible. At the end of the sw upgrade the server reboot automatically
(application initiated reboot). Can anybody help?

The best option is to check if it's possible to turn off automatic reboot and then do the reboot in Ansible.
If that's not possible this might be a gussing game.

fatal: [192.168.1.131]: UNREACHABLE! => {"changed": false, "msg": "Failed
to connect to the host via ssh: Shared connection to ****(server IP)
closed.\r\n", "unreachable": true}

Script.

- hosts: remote_server
  remote_user: ansible
  become: yes
  become_method: sudo
  connection: ssh
  gather_facts: yes
  vars:
     ansible_ssh_host: **** (host IP)
     ansible_ssh_port: 22
  tasks:
  - name: Install SW version xxx
    ....

Check out fire and forget
http://docs.ansible.com/ansible/latest/user_guide/playbooks_async.html

poll must be 0 and async must be a value higher than the time it take to execute task "Install SW version xxx"

  - name: waiting for server to reboot
    wait_for: host="{{ ansible_ssh_host | default(inventory_hostname)
}}" port={{ ansible_ssh_port | default(22) }} search_regex=OpenSSH
delay=60 timeout=300
    connection: local
    sudo: false

I recommend using wait_for_connection because this one check if Ansible is able to run on remote before it goes to the next task.
But in either case the delay must be greater than the time to execute task "Install SW version xxx".

So timing is essential but if you get them right it should work.