Ansible playbooks to deploy a Django project
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Ansible playbooks used to deploy a Django project on a remote server. This playbook assumes the remote server to be debian based. I used it to deploy project on a Digital Ocean droplet.

Also checkout my post for more detailed description.


  • Ansible installed on your local system.
  • Passwordless setup for a user with sudo privilleges.
  • A Django project copied onto the remote server.
  • For simplicity I am using SQLite as my back-end database.
  • A custom domain pointing to your cloud server(Optional). This domain name is used while setting up Nginx.


  • Install necessary packages.
    • System packages
    • Python packages
  • Setup Django.
    • Create a virtualenv.
    • Install packages from requirements.txt file.
    • Create db models.
    • Collect static files.
  • Setup Gunicorn.
    • Customize the conf file.
    • Copy the gunicorn.conf file to the remote server.
    • Restart gunicorn server.
  • Setup Nginx.
    • Customize the Nginx conf file.
    • Copy the Nginx config file to the remote server.
    • Restart Nginx server.


Clone the repo. Make sure the prerequisities are met.

  • Modify ansible.cfg.
  • Provide IP address in hosts file.

Finally run the playbook as shown below.

$ git clone --recursive
$ cd Ansible-Django
$ ansible-playbook -s deploy.yml


  • A new role for setting up data stores like MySQL, Postgres etc.
  • Check how to run the playbook in sudo mode through ansible.cfg
  • Clone a Git repository instead of assuming it's already present on the remote server

Finally go to your domain and see your django app working.