python - Ansible - 在新终端窗口中启动 Python Flask 脚本

标签 python ansible

我有一个 Flask 应用程序,我想部署并开始使用 Ansible。我已经设置了 playbook 来安装所有需要的依赖项,但我无法让 Ansible 启动我的应用程序。我使用了 commandshell 两者都启动了 Flask 应用程序,但它们阻止了 Ansible 退出并且 Flask 不会在它自己的终端窗口中弹出,这使得很难直观地调试和查看 Flask 在做什么。

#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 脚本,以便稍后登录并查看它的运行情况:

- 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 将命令并忘掉它。

关于python - Ansible - 在新终端窗口中启动 Python Flask 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29994021/

相关文章:

python - Selenium 屏幕截图运行缓慢(Python)

python - 从列表中删除重复的数字

使用 Vagrant 机器测试时 Ansible 剧本抛出 `playbook does not exist on the guest`

Ansible ufw 模块错误 : Could not find a profile matching 'xxxxx'

ansible - 在循环中使用 ansibleignore_errors

python - 将列中的零替换为上一行中的字符串(Python/Pandas)

python - 使用 python 返回 map<string,string> 类型的 Hive 转换

python - 通过 pickle 保存 cython 扩展

postgresql - Ansible docker postgres 卷

ansible - 如果任务的结果失败,changed_when 不工作