playbook executes but hangs when executing remote python script

60 views
Skip to first unread message

richard kappler

unread,
Dec 21, 2015, 3:57:40 PM12/21/15
to Ansible Project
I need to stop and then start a python script on numerous remote servers. I set up a vm in our test environment to walk through this. The 'remote server' has a simple python script (test.py) in /test directory:

#!/usr/bin/env python


while True:
   
print "running\n"



my playbook has a hosts file:

[servers]
192.168.2.31

which is the IP of the 'remote host' in the test environment.

I have tried the playbook several ways, using shell, script and command to execute test.py, shell and script didn't work, command did but then the playbook hangs:

---
- name: test stop and start test.py
  hosts
: servers
  tasks
:

   
- name: kill pyscript
      shell
: pkill -f test.py

   
- name: start script
      command
: python /test/test/py

This works, sort of but not really :-) test.py gets killed, sure enough, and "start script" in the playbook executes, but then ansible just sits there, Ho-Ho-Ho-ing me. 


TASK
: [start script] *****************************************

For oooh long time until I give up and Control-C it.

It is executing though, because when I go to the 'remote server' test.py is indeed running.

What the heck am I missing????

Matt Martz

unread,
Dec 21, 2015, 5:39:58 PM12/21/15
to ansible...@googlegroups.com
What are you trying to achieve?  Ansible waits until the script exits before moving on.  Your python script appears that it will never exit.

I think what you are looking for is "fire and forget" functionality?  

If so, you can achieve that by using async and poll.  A poll value of 0 will allow the fire and forget.  See http://docs.ansible.com/ansible/playbooks_async.html

--
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.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/fc1b637b-460c-4a0d-9249-001e47008a76%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net

richard kappler

unread,
Dec 22, 2015, 9:32:58 AM12/22/15
to ansible...@googlegroups.com
That is exactly what I was looking for, thanks! As far as what I was looking for, you were correct in that it is fire and forget, this script runs constantly, we just need to be able to shut it down occassionaly for various reasons, then restart it. I must have missed the bit in the docs that say ansible waits for the completion/output of tasks. Makes sense now. Thanks again Matt!

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/EXxZdKpUuaw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.

To post to this group, send email to ansible...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

All internal models of the world are approximate. ~ Sebastian Thrun

Reply all
Reply to author
Forward
0 new messages