Run a blocking node.js server script in the background through ansible

Hi there,

I’m trying to do something with ansible that sounds easy/common enough. Somewhere in my playbook, after setting up my reverse proxies, static directories, and mysql, I’d like to kick off my node.js app. The typical way I would do this manually is by running:

npm start &

“npm start” runs server.js, which starts my server. The ampersand runs everything in the background.

However, it appears that the “&” doesn’t work for ansible. The playbook pauses at this point and never returns. How do I run a blocking script with ansible?

Thanks,
Jacob

Well, generally I’d expect you would NOT want to run these kinds of things through the login shell and would have a proper init script, or configure something akin to supervisor. What happens if you reboot your server? Etc? You’d want something there to restart it.

What you are experiencing is a script that is failing to daemonize properly.

Should you want to background a task though, you can do it as follows:

http://docs.ansible.com/playbooks_async.html