Skip to content

Instantly share code, notes, and snippets.

@drgarcia1986
Last active June 22, 2019 13:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save drgarcia1986/386a7546fa9c8ba47f39 to your computer and use it in GitHub Desktop.
Save drgarcia1986/386a7546fa9c8ba47f39 to your computer and use it in GitHub Desktop.
Hello World with Ansible and Vagrant
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return '<h1>Hello From Vagrant</h1>'
if __name__ == '__main_':
app.run()
---
- hosts: all
sudo: true
tasks:
- name: download get-pip.py
get_url: url=https://bootstrap.pypa.io/get-pip.py dest=/tmp/get-pip.py
- name: install pip
command: python /tmp/get-pip.py
- name: install gunicorn and flask
pip: name={{ item }}
with_items:
- gunicorn
- flask
- name: copy app file to host
copy: src=app.py dest=~/app.py
- name: run server
command: gunicorn app:app -D -b 0.0.0.0:8000 chdir=~/
$ vagrant up --provision
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network "forwarded_port", guest: 8000, host: 8000
config.vm.provision :ansible do |ansible|
ansible.playbook = "playbook.yml"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment