Ansible-在新的终端窗口中启动Python Flask脚本 [英] Ansible - Start Python Flask Script in New Terminal Window
问题描述
我有一个Flask应用,我想对其进行部署并开始使用Ansible.我已经设置好了剧本来安装所需的所有依赖项,但是我无法让Ansible启动我的应用程序.我曾经使用command
和shell
来启动Flask应用程序,但是它们阻止Ansible退出,并且Flask不会在其自己的终端窗口中弹出,这使得很难进行视觉调试并查看Flask是什么正在做.
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
问:如何在自己的终端窗口中让Ansible启动Flask脚本?
推荐答案
如果您具有 gnu屏幕安装在该系统上,然后就可以使用它执行后台任务.我使用它以deploy
用户的身份异步运行Shell脚本,以便稍后登录并查看其运行情况:
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
-d -m
参数告诉屏幕以分离模式启动,而async
和poll
设置告诉Ansible后台执行该命令,而忽略它.
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.
这篇关于Ansible-在新的终端窗口中启动Python Flask脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!