简体   繁体   中英

How to stop a running python script by Ansible?

In the node1 host, there is a Python script py_script.py :

import time

while True:

    print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))

    time.sleep(1)

then in my ansible host, I can use the ansible to start the script:

ansible node1 -m shell -a 'python py_script.py &'

then it will start running.

but how can I stop it?

It seems like you should have systemd manage your script or have some other kind of service.

If you do not want that, you can use pkill to kill this script:
pkill -f "python py_script.py"
This will kill all processes with the command python py_script.py .

You can do ansible node1 -m shell -a 'pkill -f "python py_script.py"'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM