Coder Social home page Coder Social logo

ansible-playbook-pythonapp's Introduction

Sample ansible to deploy a python app using virtualenv and pip

based on https://github.com/bee-keeper/aws-ansible-django-deployment

Vagrant playbook available.

Required

You will need to install Ansible
If you want to test in Vagrant, you will need to install Vagrant

You can test the playbook using Vagrant

$vagrant up

Once vagrant vm is built you can re-run playbook using

$vargrant provision

Run the play book

$ ansible-playbook -i your-inventory.ini --private-key=/Users/mark/.ssh/gg_rsa --user=mconlin vagrant-main.yml

You can run commands inside the venv by using the full path to it.
This is not super elegant and Ansible has a built in command for Django management commands that be better in some cases.

Run python inside virtual env

- name: Run a python command inside the venv
  command: "{{ virtualenv_path }}/bin/python api-install-test.py"
  args:
    chdir: "{{ git_root }}"

Use the command wrapper in this repository venv_exec.j2 to execute commands inside a virtual env (eg. you are using make commands to run Django manage.py tasks)

- name: execute command inside virtualenv using wrapper
  command: "{{ virtualenv_path }}/execwrapper make clean"
  args:
    chdir: "{{ git_root }}"

Check the playbooks results inside vagrant

mark@mecmbp ~/workspace/ansible/poc-python-playbook (master *) $ vagrant ssh
Welcome to Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-36-generic x86_64)
.....
Last login: Sun Mar 27 01:52:27 2016 from 10.0.2.2
vagrant@vagrant-ubuntu-trusty-64:~$ cd /webapps/myapplication/myapplication/

vagrant@vagrant-ubuntu-trusty-64:/webapps/myapplication/myapplication$ . venv/bin/activate
(venv) vagrant@vagrant-ubuntu-trusty-64:/webapps/myapplication/myapplication$ pip install -r requirements.txt
Requirement already satisfied (use --upgrade to upgrade): Flask==0.10.1 in ./venv/lib/python2.7/site-packages (from -r requirements.txt (line 1))
Requirement already satisfied (use --upgrade to upgrade): Jinja2==2.7.2 in ./venv/lib/python2.7/site-packages (from -r requirements.txt (line 2))
Requirement already satisfied (use --upgrade to upgrade): MarkupSafe==0.19 in ./venv/lib/python2.7/site-packages (from -r requirements.txt (line 3))
Requirement already satisfied (use --upgrade to upgrade): Werkzeug==0.9.4 in ./venv/lib/python2.7/site-packages (from -r requirements.txt (line 4))
Requirement already satisfied (use --upgrade to upgrade): itsdangerous==0.24 in ./venv/lib/python2.7/site-packages (from -r requirements.txt (line 5))
Requirement already satisfied (use --upgrade to upgrade): wsgiref==0.1.2 in /usr/lib/python2.7 (from -r requirements.txt (line 6))

ansible-playbook-pythonapp's People

Contributors

meconlin avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.