ansibleguy.infra_django_apache

Django Logo

Ansible Role - Python3 Django

This Ansible role helps you set up one or more Django applications on a Linux server using Apache2 as the web server.

Buy me a coffee

Molecule Test Status YamlLint Test Status PyLint Test Status Ansible-Lint Test Status Ansible Galaxy

Molecule Logs: Short, Full

Tested on:

  • Debian 11

Installation

To install the role, use the following commands:

# For the latest version
ansible-galaxy role install git+https://github.com/ansibleguy/infra_django_apache

# From Galaxy
ansible-galaxy install ansibleguy.infra_django_apache

# To install in a custom role path
ansible-galaxy install ansibleguy.infra_django_apache --roles-path ./roles

# Install dependencies from the requirements file
ansible-galaxy install -r requirements.yml

Usage

If you need a simple Ansible user interface, check out my Ansible WebUI.

Configuration

You need to set up your instances by configuring the 'mariadb' section!

django:
  sites:
    niceApp:
      domain: 'django.ansibleguy.net'
      project: 'super'  # name of the directory containing 'settings.py' 
      
      sync_code:  # syncs local code to the remote server
        enabled: true
        src: '/home/ansibleguy/code/niceApp'
        static_src: '/home/ansibleguy/code/niceApp_static'
      
      venv: '/var/lib/niceApp'

      python_modules:
        present: ['netaddr', 'pycryptodome']
      
      env_pythonpath: ['/var/lib/myOtherApp']  # adds this to Django's PYTHONPATH

      ssl:
        mode: 'letsencrypt'

      letsencrypt:
        email: '[email protected]'

You may want to use 'ansible-vault' to encrypt your passwords:

ansible-vault encrypt_string

Execution

To run the playbook/role, use:

ansible-playbook -K -D -i inventory/hosts.yml django.yml --ask-vault-pass

There are useful tags you can use:

  • base => only basic configuration; instances will not be affected
  • sites
  • config
  • db
  • sync => only sync local code to remote host (if enabled)
  • django => skip starting sub-roles for Apache and/or MariaDB

For debugging errors, set the 'debug' variable at runtime:

ansible-playbook -K -D -i inventory/hosts.yml playbook.yml -e debug=yes

Functionality

  • Package Installation

    • Minimum Ansible dependencies
  • Configuration

    • Configures Apache using THIS role

    • Supports MySQL or PostgreSQL

    • Default options:

      • MariaDB database using THIS role
    • Opt-out features:

      • Database backup service
      • Special Apache configuration (can be added in the 'django' section)
      • Running 'collectstatic'
    • Default Settings:

      • Uses a self-signed certificate
      • Default database is MariaDB (installed automatically)
      • Uses a Python virtual environment
      • A database migration script created in the virtual environment directory

Information

  • Note: This role only works on Debian-based systems.

  • Note: You can enable or disable most of the role's features.

    For all options, check the default configuration file!

  • Warning: Not all settings you enter will be checked, invalid configurations could break the role!

Informazioni sul progetto

Role to deploy one or multiple django sites using apache2 to host them

Installa
ansible-galaxy install ansibleguy.infra_django_apache
Licenza
other
Download
1.9k
Proprietario
[email protected] | GPG: https://badges.ansibleguy.net/public.gpg