Ansible - 在新的终端窗口中启动 Python Flask 脚本 [英] Ansible - Start Python Flask Script in New Terminal Window

查看:29
本文介绍了Ansible - 在新的终端窗口中启动 Python Flask 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Flask 应用程序,我想部署它并开始使用 Ansible.我已经设置好剧本来安装所需的所有依赖项,但是我无法让 Ansible 启动我的应用程序.我使用了 commandshell 两者都可以启动 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 screen 安装在此系统上,然后您可以使用它来执行后台任务.我使用它以 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 参数告诉屏幕以分离模式启动,asyncpoll 设置告诉 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆