Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add django prefix to all variables #13

Merged
merged 1 commit into from
Mar 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ Both `Django` and `celery` are installed and set up as `systemd` services.
Some of the more important variables are briefly described below. You can see all variables by looking at the `defaults/main.yml` file.

```yml
system_user: "django_app" # name of the user that will own the django installation
django_system_user: "django_app" # name of the user that will own the django installation

python_source_version: "3.6" # the python verion to user
python_version: "python3.6" # the python version to use with pip commands
django_python_source_version: "3.6" # the python verion to user
django_python_version: "python3.6" # the python version to use with pip commands

git_url: "https://github.com/moshthepitt/django-template3.git" # the git repo of your django app which we are installing
django_git_url: "https://github.com/moshthepitt/django-template3.git" # the git repo of your django app which we are installing

local_settings_path: "path to /local_settings.py" # Path to the Django settings file
django_local_settings_path: "path to /local_settings.py" # Path to the Django settings file
django_settings_module: "template3.settings" # Django settings module
wsgi_module: "template3.wsgi:application" # Django wsgi module
django_wsgi_module: "template3.wsgi:application" # Django wsgi module
```

You can look at `tests/test.yml` for examples of how to use these variables.
Expand Down
138 changes: 69 additions & 69 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,65 +1,65 @@
# user
system_user: "django"
system_group: "www-data"
system_user_home: "/home/{{ system_user }}"
django_system_user: "django"
django_system_group: "www-data"
django_system_user_home: "/home/{{ django_system_user }}"

# git
git_url:
git_version: "master"
git_key:
git_key_filename: "id_ed25519"
remove_git_key: True
django_git_url:
django_git_version: "master"
django_git_key:
django_git_key_filename: "id_ed25519"
django_remove_git_key: True

# system-wide dependencies
python_source_version: "3.6"
python_version: "python3.6" # or python3.x
system_wide_dependencies:
django_python_source_version: "3.6"
django_python_version: "python3.6" # or python3.x
django_system_wide_dependencies:
- build-essential
- git
- python3.6-dev

# service
service_name: "{{ system_user }}"
service_type: "notify"
service_restart: "on-failure"
service_group: "{{ system_group }}"
service_unit_after: "network.target"
service_install_wantedby: "multi-user.target"
pid_socks_dir: "/var/run/{{ service_name }}"
manage_services: False
django_service_name: "{{ django_system_user }}"
django_service_type: "notify"
django_service_restart: "on-failure"
django_service_group: "{{ django_system_group }}"
django_service_unit_after: "network.target"
django_service_install_wantedby: "multi-user.target"
django_pid_socks_dir: "/var/run/{{ django_service_name }}"
django_manage_services: False

env_name: "prod"
codebase_path: "{{ system_user_home }}/app"
versioned_path: "{{ codebase_path }}-versioned"
checkout_path: "{{ versioned_path }}/{{ ansible_date_time['epoch'] }}"
venv_path: "{{ system_user_home }}/.virtualenvs/{{ system_user }}"
log_path: "/var/log/{{ service_name }}"
pid_file: "{{ pid_socks_dir }}/{{ service_name }}.pid"
proxy_read_timeout: "300s"
django_env_name: "prod"
django_codebase_path: "{{ django_system_user_home }}/app"
django_versioned_path: "{{ django_codebase_path }}-versioned"
django_checkout_path: "{{ django_versioned_path }}/{{ ansible_date_time['epoch'] }}"
django_venv_path: "{{ django_system_user_home }}/.virtualenvs/{{ django_system_user }}"
django_log_path: "/var/log/{{ django_service_name }}"
django_pid_file: "{{ django_pid_socks_dir }}/{{ django_service_name }}.pid"
django_proxy_read_timeout: "300s"

# Python packages
recreate_virtual_env: False
django_recreate_virtual_env: False

## pipenv
use_pipenv: False
django_use_pipenv: False

## pip
use_regular_old_pip: True
pip_paths:
- "{{ checkout_path }}/requirements.txt"
django_use_regular_old_pip: True
django_pip_paths:
- "{{ django_checkout_path }}/requirements.txt"

## other pip packages not in requirements files
pip_packages:
django_pip_packages:
- celery
- uwsgi

# Django
local_settings_path:
django_local_settings_path:
django_init_commands:
- migrate --noinput
- collectstatic --noinput
static_path: "/var/www/static/"
media_path: "/var/www/media/"
django_static_path: "/var/www/static/"
django_media_path: "/var/www/media/"
django_settings_module:

## Django settings
Expand All @@ -83,9 +83,9 @@ django_settings:
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
}
}
STATIC_ROOT: "'{{ static_path }}'"
STATIC_ROOT: "'{{ django_static_path }}'"
STATIC_URL: "'/static/'"
MEDIA_ROOT: "'{{ media_path }}'"
MEDIA_ROOT: "'{{ django_media_path }}'"
MEDIA_URL: "'/media/'"
EMAIL_BACKEND: "'django.core.mail.backends.console.EmailBackend'"
EMAIL_HOST: "'localhost'"
Expand All @@ -94,40 +94,40 @@ django_settings:
ALLOWED_HOSTS: "[]"
DEBUG: True
## python statements included at the top of settings file
top_python_statements:
django_top_python_statements:
- import os
## python statements included at the bottom of settings file
bottom_python_statements:
django_bottom_python_statements:

# wsgi
wsgi_module:
wsgi_processes: 3
wsgi_harakiri: 240
wsgi_max_requests: 5000
wsgi_http:
wsgi_socket: "{{ pid_socks_dir }}/{{ service_name }}.sock"
wsgi_chmod_socket: 777
wsgi_user: "{{ system_user }}"
wsgi_group: "www-data"
wsgi_vacuum: True
wsgi_master: True
wsgi_logto: "{{ log_path }}/uwsgi_{{ service_name }}.log"
wsgi_virtualenv: "{{ venv_path }}"
wsgi_static_map: "/static={{ static_path }}"
wsgi_buffer_size: 8192
wsgi_env: "HTTPS=on"
wsgi_stats: "{{ pid_socks_dir }}/{{ service_name }}_stats.sock"
wsgi_enable_threads: False
wsgi_memory_report: False
django_wsgi_module:
django_wsgi_processes: 3
django_wsgi_harakiri: 240
django_wsgi_max_requests: 5000
django_wsgi_http:
django_wsgi_socket: "{{ django_pid_socks_dir }}/{{ django_service_name }}.sock"
django_wsgi_chmod_socket: 777
django_wsgi_user: "{{ django_system_user }}"
django_wsgi_group: "www-data"
django_wsgi_vacuum: True
django_wsgi_master: True
django_wsgi_logto: "{{ django_log_path }}/uwsgi_{{ django_service_name }}.log"
django_wsgi_virtualenv: "{{ django_venv_path }}"
django_wsgi_static_map: "/static={{ django_static_path }}"
django_wsgi_buffer_size: 8192
django_wsgi_env: "HTTPS=on"
django_wsgi_stats: "{{ django_pid_socks_dir }}/{{ django_service_name }}_stats.sock"
django_wsgi_enable_threads: False
django_wsgi_memory_report: False

# celery
enable_celery: True
celery_app:
celeryd_nodes: "{{ service_name }}"
celeryd_service_name: "celeryd-{{ service_name }}"
celerybeat_service_name: "celerybeat-{{ service_name }}"
celeryd_opts: "--time-limit=300 --concurrency=8"
celeryd_log_level: "INFO"
celerybeat_log_level: "INFO"
celeryd_pid_file:
celery_beat_pid_file:
django_enable_celery: True
django_celery_app:
django_celeryd_nodes: "{{ django_service_name }}"
django_celeryd_service_name: "celeryd-{{ django_service_name }}"
django_celerybeat_service_name: "celerybeat-{{ django_service_name }}"
django_celeryd_opts: "--time-limit=300 --concurrency=8"
django_celeryd_log_level: "INFO"
django_celerybeat_log_level: "INFO"
django_celeryd_pid_file:
django_celery_beat_pid_file:
14 changes: 7 additions & 7 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
- name: reload systemctl
command: systemctl daemon-reload
when:
- manage_services == True
- django_manage_services == True

- name: restart_service
service:
name: "{{ service_name }}"
name: "{{ django_service_name }}"
state: restarted
when:
- manage_services == True
- django_manage_services == True

- name: restart_celery
service:
name: "{{ item }}"
state: restarted
with_items:
- "{{ celeryd_service_name }}"
- "{{ celerybeat_service_name }}"
- "{{ django_celeryd_service_name }}"
- "{{ django_celerybeat_service_name }}"
when:
- enable_celery == True
- manage_services == True
- django_enable_celery == True
- django_manage_services == True
2 changes: 1 addition & 1 deletion meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ dependencies:
- role: ANXS.python
become: true
become_user: "root"
python_source_version: "{{ python_source_version }}"
python_source_version: "{{ django_python_source_version }}"
tags:
- python
8 changes: 4 additions & 4 deletions tasks/celery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
- name: Copy celeryd default script
template:
src: templates/etc/default/celeryd.j2
dest: /etc/default/celeryd-{{ system_user }}
dest: /etc/default/celeryd-{{ django_system_user }}
mode: 0644

- name: Copy celerybeat default script
template:
src: templates/etc/default/celerybeat.j2
dest: /etc/default/celerybeat-{{ system_user }}
dest: /etc/default/celerybeat-{{ django_system_user }}
mode: 0644

- name: Copy celeryd upstart script
template:
src: "etc/systemd/celeryd.service.j2"
dest: "/etc/systemd/system/{{ celeryd_service_name }}.service"
dest: "/etc/systemd/system/{{ django_celeryd_service_name }}.service"
mode: 0644
notify:
- reload systemctl
Expand All @@ -23,7 +23,7 @@
- name: Copy celerybeat upstart script
template:
src: "etc/systemd/celerybeat.service.j2"
dest: "/etc/systemd/system/{{ celerybeat_service_name }}.service"
dest: "/etc/systemd/system/{{ django_celerybeat_service_name }}.service"
mode: 0644
notify:
- reload systemctl
Expand Down
4 changes: 2 additions & 2 deletions tasks/cleanup.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
- name: Get previous app deploy listing
shell: ls -tr1 chdir={{ versioned_path }}
shell: ls -tr1 chdir={{ django_versioned_path }}
register: versioned_list

- name: Remove extra files from app directroy
file:
path: "{{ versioned_path }}/{{ versioned_list.stdout_lines[item|int] }}"
path: "{{ django_versioned_path }}/{{ versioned_list.stdout_lines[item|int] }}"
state: absent
with_sequence: start=0 end={{ versioned_list.stdout_lines|length - 10 }}
ignore_errors: yes
40 changes: 20 additions & 20 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,49 @@
- name: Run Django init commands
django_manage:
command: "{{ item }}"
app_path: "{{ checkout_path }}"
virtualenv: "{{ venv_path }}"
app_path: "{{ django_checkout_path }}"
virtualenv: "{{ django_venv_path }}"
with_items: "{{ django_init_commands }}"
become_user: "{{ system_user }}"
become_user: "{{ django_system_user }}"

- name: Changing static folder permission
file:
path: "{{ static_path }}"
owner: "{{ system_user }}"
group: "{{ system_group }}"
path: "{{ django_static_path }}"
owner: "{{ django_system_user }}"
group: "{{ django_system_group }}"
mode: 0755
when:
- static_path is defined
- static_path is not none
- django_static_path is defined
- django_static_path is not none

- name: Changing mediafolder permission
file:
path: "{{ media_path }}"
owner: "{{ system_user }}"
group: "{{ system_group }}"
path: "{{ django_media_path }}"
owner: "{{ django_system_user }}"
group: "{{ django_system_group }}"
mode: 0755
when:
- media_path is defined
- media_path is not none
- django_media_path is defined
- django_media_path is not none

- name: Make the new codebase current
file:
src: "{{ checkout_path }}"
dest: "{{ codebase_path }}"
src: "{{ django_checkout_path }}"
dest: "{{ django_codebase_path }}"
state: link
force: yes
owner: "{{ system_user }}"
group: "{{ system_group }}"
owner: "{{ django_system_user }}"
group: "{{ django_system_group }}"
notify:
- restart_service
- restart_celery

- name: Copy uwsgi.ini
template:
src: uwsgi.ini.j2
dest: "{{ checkout_path }}/uwsgi.ini"
dest: "{{ django_checkout_path }}/uwsgi.ini"
mode: 0644
owner: "{{ system_user }}"
group: "{{ system_group }}"
owner: "{{ django_system_user }}"
group: "{{ django_system_group }}"
notify:
- restart_service
Loading