Ansible - Start Python Flask Script in New Terminal Window

亡梦爱人 提交于 2019-12-10 16:24:41

问题


I have a Flask app that I'd like to deploy and start using Ansible. I've already got my playbook setup to install all the dependencies needed but I'm having trouble getting Ansible to start my application. I've used command and shell both of which do startup the Flask app, but they block Ansible from exiting and Flask doesn't popup in it's own terminal window, which makes it difficult to visually debug and see what Flask is doing.

#Current playbook; both command and shell act the same way
  tasks:
  - command: python3 /home/user/Desktop/Flask/app.py
  - shell: python3 /home/user/Desktop/Flask/app.py

Q: How can I have Ansible startup a Flask script in it's own terminal window?



回答1:


If you have gnu screen installed on this system then you can use it to background tasks. I use this to run a shell script asynchronously as the deploy user so that I can log in later and see how it's doing:

- name: Invoke reset script
  command: /usr/bin/screen -d -m sudo -u deploy /usr/local/bin/do-reset.sh -i -y reset 
  async: True
  poll: 0

The -d -m parameters tell screen to start up in detached mode, and the async and poll settings tell Ansible to background the command and forget about it.



来源:https://stackoverflow.com/questions/29994021/ansible-start-python-flask-script-in-new-terminal-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!