In an Ansible task, what is the proper way to run a script in the background?

Say I want to run a script in the background after my Ansible run finishes. Which of these two options is the correct way?

Option 1: Run a nohup on the Ansible task itself

`

  • name:Run a script in the background
    command: nohup myscript.sh 2>&1 &
    `

where myscript.sh does something (anything) but has no nohup calls.

Option 2: Put the nohup in the script itself?

`

  • name: Run a script in the background
    command: ./myscript.sh
    `

and myscript.sh has in it the nohup

myscript.sh

nodup do_something 2>&1 &

Or option three: use async:. http://docs.ansible.com/ansible/latest/playbooks_async.html

If the script is something you want to run and exit after performing its tall, I think async is the most idiomatic. If the script is more like a daemon, having nohup in the script feels right to me but I can’t think of a reason either would be better.
-Toshio

Thanks, I didn’t know about async, but it’s NOT what I want since I do want the script to run as a daemon indeed.

I would say none of them.
Create a init file for you init system and start the program with the service module.

Thanks. I’ll also look at synchronized application.

Sorry, I meant supervisord as another means to start a deamon.