cchurch.django
Django
This guide helps you set up and update a Django project using Ansible. You need Ansible version 2.8 or newer.
Requirements
- If you are using
become
(which means using a different user thanansible_user
), make sure the necessary OS packages (likesudo
) are installed. - The Django project must be on the target host before using this role (you can use tools like Git, rsync, etc. to copy it).
- You must install the necessary OS and Python packages for your project, including Django. You might find the cchurch.virtualenv role helpful for creating a virtual environment and installing packages.
Role Variables
You can customize this role using the following variables:
django_app_path
: Directory where your Django project is stored (required).django_user
: User to use for running Django commands (default isansible_user
).django_directories
: List of directories to create for the project (default is[]
). You can specify just the name or provide details likepath
,owner
,group
, andmode
.django_settings_templates
: List of custom settings templates to install (default is[]
).django_settings
: Path to the Django settings module for commands (default isomit
).django_virtualenv
: Directory of the virtual environment to activate (default isomit
).django_pre_commands
: Extra commands to run before main commands (default is[]
).django_main_commands
: Main Django commands to run (default is[{"command": "migrate", "run_once": true}, "collectstatic"]
).django_post_commands
: Extra commands to run after the main commands (default is[]
).django_run_once_host
: Hostname for commands that run only once (default points to the first host in the play).
You can define each command in django_main_commands
as either a simple string or a hash with options (e.g., skip
, run_once
).
Example Playbook
Here's an example playbook to set up and update a Django project and notify when changes are made:
- hosts: all
vars:
django_app_path: ~/src
django_virtualenv: ~/env
django_settings_templates:
- src: local_settings.py.j2
dest: ~/src/myproj/local_settings.py
django_settings: myproj.settings
django_pre_commands:
- command: test
failfast: yes
- validate
django_post_commands:
- command: loaddata
fixtures: defaults.json
roles:
- role: cchurch.django
handlers:
- name: django project updated
debug:
msg: "Django project in {{ django_app_path }} was updated!"
listen: django updated
License
BSD
Author Information
Chris Church (cchurch)
Installa
ansible-galaxy install cchurch.django
Licenza
other
Download
3.3k
Proprietario
Python/Django/Ansible, will code for sweet tea and beer.