run background job in the shell or script module

8,503 views
Skip to first unread message

shirou

unread,
Oct 16, 2013, 9:54:22 AM10/16/13
to ansible...@googlegroups.com
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).

---
- hosts: localhost
tasks:
- name: sleepy
shell: nohup sleep 10 &

Second, I try to use script module using this script

#!/usr/bin/env sh
nohup sleep 10 &

and playbook is

---
- hosts: localhost
tasks:
- name: sleepy
script: sleepy.sh

However, it run as a foreground job.

I type this line which is shown by the -vvv option.

chmod +x /home/spam/.ansible/tmp/ansible-1381930427.99-115271615480671/sleepy.sh;
/home/spam/.ansible/tmp/ansible-1381930427.99-115271615480671/sleepy.sh

and it works well.

Could you tell me how to run a background job on the script or shell module?

I am using ansible 1.4 on the Ubuntu 12.10, python 2.7.3

Thank you.
WAKAYAMA Shirou

Michael DeHaan

unread,
Oct 16, 2013, 3:51:06 PM10/16/13
to ansible...@googlegroups.com



--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Michael DeHaan <mic...@ansibleworks.com>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/

shirou

unread,
Oct 17, 2013, 11:28:50 AM10/17/13
to ansible...@googlegroups.com

it works.
Thank you!

2013/10/17 4:51 "Michael DeHaan" <mic...@ansibleworks.com>:

Michael Slinn

unread,
Nov 25, 2013, 1:38:33 PM11/25/13
to ansible...@googlegroups.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?

Michael DeHaan

unread,
Nov 25, 2013, 7:57:03 PM11/25/13
to ansible...@googlegroups.com
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.




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Mike Slinn

unread,
Nov 25, 2013, 7:57:34 PM11/25/13
to ansible...@googlegroups.com
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

Michael DeHaan

unread,
Nov 25, 2013, 8:08:21 PM11/25/13
to ansible...@googlegroups.com
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.





--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Michael Slinn

unread,
Nov 25, 2013, 9:19:41 PM11/25/13
to ansible...@googlegroups.com
I defined a system service and it works. Thank you!
Reply all
Reply to author
Forward
0 new messages