Skip to content

Instantly share code, notes, and snippets.

@guinslym
Last active June 30, 2020 02:25
Show Gist options
  • Save guinslym/621dac62c755a93bf6b89164a59dd2af to your computer and use it in GitHub Desktop.
Save guinslym/621dac62c755a93bf6b89164a59dd2af to your computer and use it in GitHub Desktop.
## my box VMs ##
[DigitialOceanExample]
PPP.PPP.PPP.PPP (redacted by author)
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "<h1 style='color:blue'>Hello There!</h1>"
if __name__ == "__main__":
app.run(host='0.0.0.0')
---
- hosts: DigitialOceanExample
become: yes
tasks:
- name: Update apt-get repo and cache
apt:
update_cache: yes
force_apt_get: yes
cache_valid_time: 3600
- name: Install a list of packages
apt:
pkg:
- python3-pip
- python3-dev
- build-essential
- libssl-dev
- libffi-dev
- python3-setuptools
- python3-venv
- name: ensure a directory exists or create it
file:
path: /myproject
state: directory
- name: Manually create the initial virtualenv
command:
cmd: python3 -m venv /myproject/myprojectenv
creates: "/myproject/myprojectenv"
- name: "install python packages with the local instance of pip"
shell: "/myproject/myprojectenv/bin/pip3 install wheel flask gunicorn"
- name: copy file to server
copy:
src: "{{ item }}"
dest: /myproject
loop:
- ./myproject.py
- name: Install ufw
apt:
name: ufw
update_cache: true
- name: "Allow port 5000"
shell: "ufw allow 5000"
- name: copy file to server
copy:
src: ./wsgi.py
dest: /myproject
- name: "starting gunicorn"
shell: "/myproject/myprojectenv/bin/gunicorn --preload --bind 0.0.0.0:5000 wsgi:app"
become: yes
from myproject import app
if __name__ == "__main__":
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment