This repository holds an Ansible role
that is installable using ansible-galaxy
. This role contains
tasks used to install and set up a Django web app. It exists
primarily to support the Caktus Django project template.
This Ansible role is released under the BSD License. See the LICENSE file for more details.
If you think you've found a bug or are interested in contributing to this project check out tequila-django on Github.
Development sponsored by Caktus Consulting Group, LLC.
Create an ansible.cfg
file in your project directory to tell
Ansible where to install your roles (optionally, set the
ANSIBLE_ROLES_PATH
environment variable to do the same thing, or
allow the roles to be installed into /etc/ansible/roles
)
[defaults] roles_path = deployment/roles/
Create a requirements.yml
file in your project's deployment
directory. It is recommended to include tequila-common, which sets up
the project directory structure and users, and also geerlingguy/nodejs
to install nodejs and any front-end packages that your project
requires
--- # file: deployment/requirements.yml - src: geerlingguy.nodejs version: 4.1.2 name: nodejs - src: https://github.com/caktus/tequila-common version: v0.8.0 - src: https://github.com/caktus/tequila-django version: v0.9.3
Run ansible-galaxy
with your requirements file
$ ansible-galaxy install -r deployment/requirements.yml
or, alternatively, run it directly against the url
$ ansible-galaxy install git+https://github.com/caktus/tequila-django
The project then should have access to the tequila-django
role in
its playbooks.
The following variables are used by the tequila-django
role:
project_name
requiredenv_name
requireddomain
requiredadditional_domains
default: empty listis_web
default:false
(required: one ofis_web
oris_worker
set totrue
)is_worker
default:false
python_version
default:"2.7"
root_dir
default:"/var/www/{{ project_name }}"
source_dir
default:"{{ root_dir }}/src"
venv_dir
default:"{{ root_dir }}/env"
ssh_dir
default:"/home/{{ project_name }}/.ssh"
requirements_file
default:"{{ source_dir }}/requirements/{{ env_name }}.txt"
requirements_extra_args
default:""
use_newrelic
default:false
new_relic_license_key
required if use_newrelic is truecloud_staticfiles
default:false
gunicorn_version
optionalgunicorn_num_workers
requiredgunicorn_num_threads
optional (note: gunicorn sets this at1
if--threads=...
is not given)project_user
default:"{{ project_name }}"
project_settings
default:"{{ project_name }}.settings.deploy"
secret_key
requireddb_name
default:"{{ project_name }}_{{ env_name }}"
db_user
default:"{{ project_name }}_{{ env_name }}"
db_host
default:'localhost'
db_port
default:5432
db_password
requiredcache_host
optionalbroker_host
optionalbroker_password
optionalcelery_worker_extra_args
default:"--loglevel=INFO"
static_dir
default:"{{ root_dir }}/public/static"
media_dir
default:"{{ root_dir }}/public/media"
log_dir
default:"{{ root_dir }}/log"
repo
required: dict containing url and branchsource_is_local
default:false
github_deploy_key
required if source_is_local is falselocal_project_dir
required if source_is_localextra_env
default: empty dict
The extra_env
variable is a dict of keys and values that is
desired to be injected into the environment as variables, via the
envfile.j2
template.
Note that if source_is_local
is set to false, a Github checkout
key needs to be provided in the environment secrets file, and that key
needs to be added to the repo's settings within Github.
Alternatively, if source_is_local
is set to true, the user's local
checkout of the repo is rsynced into the environment, with a few
exclusions (.pyc files, the .git directory, the .env file, and the
node_modules directory).
The cloud_staticfiles
variable is to allow for the case where the
Django static files are being collected to an external service, such
as S3. In that case, we don't want to be running collectstatic
on
every web instance, since they'll be getting in each other's way.
This variable set to true
causes the collectstatic
task to be
run only once.
You can turn on SSH pipelining (http://docs.ansible.com/ansible/latest/intro_configuration.html#pipelining) to speed up ansible commands (by minimizing SSH operations). Add the following to your project's ansible.cfg file
[ssh_connection] pipelining = True
Warning: this will cause deployments to break if securetty
is used in your server's
/etc/sudoers
file.
See geerlingguy/nodejs for the expected Ansible configuration variables for that role.