Ansible install and run flask server

Viewed 1093

I want to use Ansible to configure my project on localhost. The idea behind it is to give user the ansible playbook, and once the user directly runs the playbook it should clone my git repo, install python modules using pip in virtualenv and run the python file.

I was able to git clone, and install the python modules in virtualenv. But if I run my Python app i.e its a Flask server in development mode, the Ansible script gets blocked i.e. its a blocking call. I want it to end and have the Flask server running. Because once the server is up, I want to have another nodes JS server running too doing the same process as above.

In short I want Ansible to install few modules and run couple of servers on my localhost.

I have done this much so far:

  - hosts: local
  connection: local
  tasks:
  - name: Install Virtual Env
    pip:
      name: virtualenv
  - name: Install Python Modules
    pip: 
      requirements: "{{playbook_dir}}/requirements.txt"
      virtualenv: "{{playbook_dir}}/myenv"
      virtualenv_python: python3.6
  - name: Run Flask App
    shell: "{{playbook_dir}}/myenv/bin/python /app.py"

The above playbook is what I am using right now. The ansible script just stops after running the app.py because it is a blocking call as it runs the server. I want to add stuff below that to run my other node.js server.

0 Answers
Related