Remote execution of a script never exits but times out

I am writing a task in a playbook which will execute a shell script on a remote server. But for some reason it never exits and hangs and then finally times out. When I run the script directly on the remote server, there are no errors. Here is the snippet of the task.

  • name: Run a script
    shell: sh /tmp/setup.sh
    become: yes

The shell script setup.sh is below. What can I do to fix this?

The very last line of that script is to tail the log file forever. As such, the script never finishes.

Looking at the script, I’m questioning why you wouldn’t turn it into a playbook and individual tasks instead of running that script.