run background job in the shell or script module

Hi all,

I want to launch a script as a background job by using "&".
First, I try the shell module but it doesn't work (means run as a
foreground job).

Please read about async mode here:

http://www.ansibleworks.com/docs/playbooks_async.html

it works.
Thank you!

2013/10/17 4:51 “Michael DeHaan” <michael@ansibleworks.com>:

I have a similar problem, and I read the docs, but I must be not seeing something obvious. Here is a fragment of a yaml file (the entire file is here):

  • name: Launch project
    command: (sleep 2; /bin/echo “Of course your realize that this means war” > $home/nohup.out)
    async: 15

poll: 0

There is no output from that step when run with -vv. What am I missing?

async: 15 will set a “time to live” for 15 seconds to the task.

Poll: 0 means “fire and forget, I don’t want any output”.

Sounds like you might want to do poll: 5 or so.

It also sounds like your project might benefit from a service init script, and then you can just use the service module.

I just want to kick off a background process. I don’t want any output.
I thought that Service only pertained to system services. Can I use them for background tasks also?

Thanks,

Mike

So contradictory statements:

“There is no output from that step when run with -vv. What am I missing?”

“I just want to kick off a background process. I don’t want any output.”

Which do you want and what are you getting versus what you are expecting?

“I thought that Service only pertained to system services. Can I use them for background tasks also?”

Yes, you can write system init scripts to do basically anything.

You might also be interested in something like supervisor, which we also have a module for.

I defined a system service and it works. Thank you!