I'm facing a issue while executing shell script with ansible playbook.
Issue: I'm losing a connection with remote server because shell script is rebooting the server.
My Ansible playbook
- name: Handle reboot
hosts: all
become: yes
tasks:
- name: Execute the script
shell: bash testscript.sh
args:
chdir: /home/ubuntu
notify:
- Wait for server to restart
handlers:
- name: Wait for server to restart
local_action:
module: wait_for
host={{ inventory_hostname }}
port=22
delay=10
become: false
My shell script :
#!/bin/bash
echo "Performing some tasks"
echo "rebooting now"
reboot
echo "reboot completed"
echo "Performing some more tasks"
The error I'm getting while the remote server reboot
fatal: [my-ip-address]: UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: Shared connection to <my-ip-address> closed.",
"unreachable": true
}
Is it possible to handle a reboot which is done by shell script and wait for connection until the remote server is up again ?
Thanks.