Ansible role to deploy a Django app to Plesk.
Add the role django-deploy.
(passed as extra variables):
- project: Django project name, will also be used as virtualenv name.
(passed as extra variables):
- loaddata: Set to- truein order to load data from- conf.data.
- flush: Set to- truein order to flush data before- loaddata. Depends on- loaddatavariable to be- true.
- newrelic: New Relic license key. Omit to skip New Relic. Recommended to add a default in playbook.
- exclude: Additional pattern to exclude from sync, eg.- media/.
- loglevel: Explicitly define an Apache log level, eg.- loglevel=info.
(better to keep in configuration file as shown in examples):
- conf: A dictionary to help organize variables, containing:
- conf.app_name: The application name (human description), used in New Relic too.
- conf.domain_name: Domain name to be used in Apache conf. Omit to skip configure Apache in Plesk.
- conf.dev_path: The local path of the project, eg ~/workspace/python/myproject.
- conf.host_path: The remote path, where the wsgi index script lies, eg /var/www/vhosts/subscription/domain.
- conf.host_user: The remote user to whom to transfer ownership after operations.
- conf.vhost_conf_path: The remote path, where the apache configuration override (- vhost.conf) is located.
- conf.name: The application name (machine name), the same as the Python app. Default:- {{ project }}
- conf.python_version: The python version to install (major.minor), default:- 3.5.
- conf.virtualenv_dir: Virtualenvs home directory, default to vars' respective option.
- conf.compile_msgs: Set to- truein order to compile i18n messages.
- conf.memcached: Set to- truein order to clear cache.
- conf.data: A list of the dump files to load data from, eg- [project, auth], omit to skip loaddata. Depends on- loaddatavariable to be- true.
- conf.limit_request_body: The maximum upload size allowed to Apache. Default: 10MB.
- conf.wsgi_script: The wsgi script, default:- index.wsgi.
- conf.wsgi_threads: If set mod_wsgi runs in daemon mode (recommended 3-25).
The following are used only for daemon mode:
- conf.wsgi_processes: If set mod_wsgi runs in multi-process mode (integer).
- conf.wsgi_inactivity_timeout: Set only for small traffic sites to reset process and reclaim memory (eg. 300).
- conf.wsgi_max_requests: Set to let process restart after n seconds. Useful if process memory grows large.
- conf.wsgi_restart_interval: Similar to the above. Only available for mod_wsgi>=v4.5.12.
- conf.wsgi_graceful_timeout: If any of the above two are set, the number of seconds to expect no requests to restart.
- conf.wsgi_queue_timeout: If large request queues, drop requests after that many seconds.
- ansible_user_id: The user id with access to mysql and mysql database.
- virtualenv_dir: Virtualenvs home directory. Set to- falseto disable virtualenv. Default:- /var/virtualenvs.
- django_settings: The Django settings module (.py) to run manage.py from, default:- settings_live.
- plesk_server_group: Plesk server group, default:- psaserv.
- plesk_account_group: Plesk account group, default:- psacln.
- sync_opts: Additional options for rsync. Default: exclude- .*.
See the folder examples/:
- django_deploy.yml: playbook example
- django_sites.yml: configuration example
- 
Check that project path in dev as specified in configuration is valid and has wsgi script Checks that there is a valid local path specified in django_sites.ymland anindex.wsgiexists. Avoids deploying wrong files.
- 
Check if gulp file exists So that to execute next step. 
- 
Execute gulp Execute gulp --productionlocally.
- 
Set Python executable Auxiliary task which sets a variable with the Python executable. 
- 
Make virtualenv Create a virtualenv if it does not exist. 
- 
Check New Relic conf file in source Otherwise create from template. 
- 
Configure New Relic If newrelicis defined configures New Relic.
- 
Open ownership Open the target directory ownership to allow file copy. 
- 
Build sync options Combine the default sync_optsvariable with theexcludeoption.
- 
Sync files Syncs files to target directory. ⚠️ Make sure that you have synced back user uploaded files inmediawith manualrsyncor useexclude.
- 
Upgrade pip Upgrades pip, setup, wheel. 
- 
Install pip requirements Install requirements.txtin virtualenv.
- 
Set Django admin executable Auxiliary task which sets a variable with the Django admin executable. 
- 
Set Django admin settings Auxiliary task which sets a variable with the custom settings file (default django_settingsvariable).
- 
Migrate Runs migrations. 
- 
Flush data Flushes data if loaddataandflushare both true.
- 
Load data Loads data if loaddatais true.
- 
Collect static Runs collect static. 
- 
Compile messages 
Compiles i18n messages if compile_msgs is true.
- Clear cache
Clears cache if memcached is true.
- 
Post deployment script Runs an optional post_script.
- 
Close ownership to Plesk account group Reset target directory ownership to the appropriate Plesk permissions. 
- 
Close ownership to Plesk server group Reset target directory ownership to the appropriate Plesk permissions. 
- 
Touch WSGI script Update the timestamp. If WSGI daemon mode it causes restart of the process at next request. 
- 
Configure Apache 
Configure Apache to execute the wsgi script using the provided template file.
Only executes if a domain_name is provided.
If the configuration changes, causes Plesk to reconfigure the domain in the end (notifies handler).
If the configuration changes, causes Apache to restart in the end (notifies handler).