Skip to content

Commit 9b1bafd

Browse files
authoredMar 29, 2019
Merge pull request #13 from onaio/django-prefix
Add django prefix to all variables
2 parents ebd2aa2 + 1d85057 commit 9b1bafd

18 files changed

+265
-265
lines changed
 

‎README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ Both `Django` and `celery` are installed and set up as `systemd` services.
1818
Some of the more important variables are briefly described below. You can see all variables by looking at the `defaults/main.yml` file.
1919

2020
```yml
21-
system_user: "django_app" # name of the user that will own the django installation
21+
django_system_user: "django_app" # name of the user that will own the django installation
2222

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

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

28-
local_settings_path: "path to /local_settings.py" # Path to the Django settings file
28+
django_local_settings_path: "path to /local_settings.py" # Path to the Django settings file
2929
django_settings_module: "template3.settings" # Django settings module
30-
wsgi_module: "template3.wsgi:application" # Django wsgi module
30+
django_wsgi_module: "template3.wsgi:application" # Django wsgi module
3131
```
3232
3333
You can look at `tests/test.yml` for examples of how to use these variables.

‎defaults/main.yml

+69-69
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,65 @@
11
# user
2-
system_user: "django"
3-
system_group: "www-data"
4-
system_user_home: "/home/{{ system_user }}"
2+
django_system_user: "django"
3+
django_system_group: "www-data"
4+
django_system_user_home: "/home/{{ django_system_user }}"
55

66
# git
7-
git_url:
8-
git_version: "master"
9-
git_key:
10-
git_key_filename: "id_ed25519"
11-
remove_git_key: True
7+
django_git_url:
8+
django_git_version: "master"
9+
django_git_key:
10+
django_git_key_filename: "id_ed25519"
11+
django_remove_git_key: True
1212

1313
# system-wide dependencies
14-
python_source_version: "3.6"
15-
python_version: "python3.6" # or python3.x
16-
system_wide_dependencies:
14+
django_python_source_version: "3.6"
15+
django_python_version: "python3.6" # or python3.x
16+
django_system_wide_dependencies:
1717
- build-essential
1818
- git
1919
- python3.6-dev
2020

2121
# service
22-
service_name: "{{ system_user }}"
23-
service_type: "notify"
24-
service_restart: "on-failure"
25-
service_group: "{{ system_group }}"
26-
service_unit_after: "network.target"
27-
service_install_wantedby: "multi-user.target"
28-
pid_socks_dir: "/var/run/{{ service_name }}"
29-
manage_services: False
22+
django_service_name: "{{ django_system_user }}"
23+
django_service_type: "notify"
24+
django_service_restart: "on-failure"
25+
django_service_group: "{{ django_system_group }}"
26+
django_service_unit_after: "network.target"
27+
django_service_install_wantedby: "multi-user.target"
28+
django_pid_socks_dir: "/var/run/{{ django_service_name }}"
29+
django_manage_services: False
3030

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

4040
# Python packages
41-
recreate_virtual_env: False
41+
django_recreate_virtual_env: False
4242

4343
## pipenv
44-
use_pipenv: False
44+
django_use_pipenv: False
4545

4646
## pip
47-
use_regular_old_pip: True
48-
pip_paths:
49-
- "{{ checkout_path }}/requirements.txt"
47+
django_use_regular_old_pip: True
48+
django_pip_paths:
49+
- "{{ django_checkout_path }}/requirements.txt"
5050

5151
## other pip packages not in requirements files
52-
pip_packages:
52+
django_pip_packages:
5353
- celery
5454
- uwsgi
5555

5656
# Django
57-
local_settings_path:
57+
django_local_settings_path:
5858
django_init_commands:
5959
- migrate --noinput
6060
- collectstatic --noinput
61-
static_path: "/var/www/static/"
62-
media_path: "/var/www/media/"
61+
django_static_path: "/var/www/static/"
62+
django_media_path: "/var/www/media/"
6363
django_settings_module:
6464

6565
## Django settings
@@ -83,9 +83,9 @@ django_settings:
8383
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
8484
}
8585
}
86-
STATIC_ROOT: "'{{ static_path }}'"
86+
STATIC_ROOT: "'{{ django_static_path }}'"
8787
STATIC_URL: "'/static/'"
88-
MEDIA_ROOT: "'{{ media_path }}'"
88+
MEDIA_ROOT: "'{{ django_media_path }}'"
8989
MEDIA_URL: "'/media/'"
9090
EMAIL_BACKEND: "'django.core.mail.backends.console.EmailBackend'"
9191
EMAIL_HOST: "'localhost'"
@@ -94,40 +94,40 @@ django_settings:
9494
ALLOWED_HOSTS: "[]"
9595
DEBUG: True
9696
## python statements included at the top of settings file
97-
top_python_statements:
97+
django_top_python_statements:
9898
- import os
9999
## python statements included at the bottom of settings file
100-
bottom_python_statements:
100+
django_bottom_python_statements:
101101

102102
# wsgi
103-
wsgi_module:
104-
wsgi_processes: 3
105-
wsgi_harakiri: 240
106-
wsgi_max_requests: 5000
107-
wsgi_http:
108-
wsgi_socket: "{{ pid_socks_dir }}/{{ service_name }}.sock"
109-
wsgi_chmod_socket: 777
110-
wsgi_user: "{{ system_user }}"
111-
wsgi_group: "www-data"
112-
wsgi_vacuum: True
113-
wsgi_master: True
114-
wsgi_logto: "{{ log_path }}/uwsgi_{{ service_name }}.log"
115-
wsgi_virtualenv: "{{ venv_path }}"
116-
wsgi_static_map: "/static={{ static_path }}"
117-
wsgi_buffer_size: 8192
118-
wsgi_env: "HTTPS=on"
119-
wsgi_stats: "{{ pid_socks_dir }}/{{ service_name }}_stats.sock"
120-
wsgi_enable_threads: False
121-
wsgi_memory_report: False
103+
django_wsgi_module:
104+
django_wsgi_processes: 3
105+
django_wsgi_harakiri: 240
106+
django_wsgi_max_requests: 5000
107+
django_wsgi_http:
108+
django_wsgi_socket: "{{ django_pid_socks_dir }}/{{ django_service_name }}.sock"
109+
django_wsgi_chmod_socket: 777
110+
django_wsgi_user: "{{ django_system_user }}"
111+
django_wsgi_group: "www-data"
112+
django_wsgi_vacuum: True
113+
django_wsgi_master: True
114+
django_wsgi_logto: "{{ django_log_path }}/uwsgi_{{ django_service_name }}.log"
115+
django_wsgi_virtualenv: "{{ django_venv_path }}"
116+
django_wsgi_static_map: "/static={{ django_static_path }}"
117+
django_wsgi_buffer_size: 8192
118+
django_wsgi_env: "HTTPS=on"
119+
django_wsgi_stats: "{{ django_pid_socks_dir }}/{{ django_service_name }}_stats.sock"
120+
django_wsgi_enable_threads: False
121+
django_wsgi_memory_report: False
122122

123123
# celery
124-
enable_celery: True
125-
celery_app:
126-
celeryd_nodes: "{{ service_name }}"
127-
celeryd_service_name: "celeryd-{{ service_name }}"
128-
celerybeat_service_name: "celerybeat-{{ service_name }}"
129-
celeryd_opts: "--time-limit=300 --concurrency=8"
130-
celeryd_log_level: "INFO"
131-
celerybeat_log_level: "INFO"
132-
celeryd_pid_file:
133-
celery_beat_pid_file:
124+
django_enable_celery: True
125+
django_celery_app:
126+
django_celeryd_nodes: "{{ django_service_name }}"
127+
django_celeryd_service_name: "celeryd-{{ django_service_name }}"
128+
django_celerybeat_service_name: "celerybeat-{{ django_service_name }}"
129+
django_celeryd_opts: "--time-limit=300 --concurrency=8"
130+
django_celeryd_log_level: "INFO"
131+
django_celerybeat_log_level: "INFO"
132+
django_celeryd_pid_file:
133+
django_celery_beat_pid_file:

‎handlers/main.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
- name: reload systemctl
33
command: systemctl daemon-reload
44
when:
5-
- manage_services == True
5+
- django_manage_services == True
66

77
- name: restart_service
88
service:
9-
name: "{{ service_name }}"
9+
name: "{{ django_service_name }}"
1010
state: restarted
1111
when:
12-
- manage_services == True
12+
- django_manage_services == True
1313

1414
- name: restart_celery
1515
service:
1616
name: "{{ item }}"
1717
state: restarted
1818
with_items:
19-
- "{{ celeryd_service_name }}"
20-
- "{{ celerybeat_service_name }}"
19+
- "{{ django_celeryd_service_name }}"
20+
- "{{ django_celerybeat_service_name }}"
2121
when:
22-
- enable_celery == True
23-
- manage_services == True
22+
- django_enable_celery == True
23+
- django_manage_services == True

‎meta/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ dependencies:
1212
- role: ANXS.python
1313
become: true
1414
become_user: "root"
15-
python_source_version: "{{ python_source_version }}"
15+
python_source_version: "{{ django_python_source_version }}"
1616
tags:
1717
- python

‎tasks/celery.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
- name: Copy celeryd default script
33
template:
44
src: templates/etc/default/celeryd.j2
5-
dest: /etc/default/celeryd-{{ system_user }}
5+
dest: /etc/default/celeryd-{{ django_system_user }}
66
mode: 0644
77

88
- name: Copy celerybeat default script
99
template:
1010
src: templates/etc/default/celerybeat.j2
11-
dest: /etc/default/celerybeat-{{ system_user }}
11+
dest: /etc/default/celerybeat-{{ django_system_user }}
1212
mode: 0644
1313

1414
- name: Copy celeryd upstart script
1515
template:
1616
src: "etc/systemd/celeryd.service.j2"
17-
dest: "/etc/systemd/system/{{ celeryd_service_name }}.service"
17+
dest: "/etc/systemd/system/{{ django_celeryd_service_name }}.service"
1818
mode: 0644
1919
notify:
2020
- reload systemctl
@@ -23,7 +23,7 @@
2323
- name: Copy celerybeat upstart script
2424
template:
2525
src: "etc/systemd/celerybeat.service.j2"
26-
dest: "/etc/systemd/system/{{ celerybeat_service_name }}.service"
26+
dest: "/etc/systemd/system/{{ django_celerybeat_service_name }}.service"
2727
mode: 0644
2828
notify:
2929
- reload systemctl

‎tasks/cleanup.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
- name: Get previous app deploy listing
3-
shell: ls -tr1 chdir={{ versioned_path }}
3+
shell: ls -tr1 chdir={{ django_versioned_path }}
44
register: versioned_list
55

66
- name: Remove extra files from app directroy
77
file:
8-
path: "{{ versioned_path }}/{{ versioned_list.stdout_lines[item|int] }}"
8+
path: "{{ django_versioned_path }}/{{ versioned_list.stdout_lines[item|int] }}"
99
state: absent
1010
with_sequence: start=0 end={{ versioned_list.stdout_lines|length - 10 }}
1111
ignore_errors: yes

‎tasks/configure.yml

+20-20
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,49 @@
22
- name: Run Django init commands
33
django_manage:
44
command: "{{ item }}"
5-
app_path: "{{ checkout_path }}"
6-
virtualenv: "{{ venv_path }}"
5+
app_path: "{{ django_checkout_path }}"
6+
virtualenv: "{{ django_venv_path }}"
77
with_items: "{{ django_init_commands }}"
8-
become_user: "{{ system_user }}"
8+
become_user: "{{ django_system_user }}"
99

1010
- name: Changing static folder permission
1111
file:
12-
path: "{{ static_path }}"
13-
owner: "{{ system_user }}"
14-
group: "{{ system_group }}"
12+
path: "{{ django_static_path }}"
13+
owner: "{{ django_system_user }}"
14+
group: "{{ django_system_group }}"
1515
mode: 0755
1616
when:
17-
- static_path is defined
18-
- static_path is not none
17+
- django_static_path is defined
18+
- django_static_path is not none
1919

2020
- name: Changing mediafolder permission
2121
file:
22-
path: "{{ media_path }}"
23-
owner: "{{ system_user }}"
24-
group: "{{ system_group }}"
22+
path: "{{ django_media_path }}"
23+
owner: "{{ django_system_user }}"
24+
group: "{{ django_system_group }}"
2525
mode: 0755
2626
when:
27-
- media_path is defined
28-
- media_path is not none
27+
- django_media_path is defined
28+
- django_media_path is not none
2929

3030
- name: Make the new codebase current
3131
file:
32-
src: "{{ checkout_path }}"
33-
dest: "{{ codebase_path }}"
32+
src: "{{ django_checkout_path }}"
33+
dest: "{{ django_codebase_path }}"
3434
state: link
3535
force: yes
36-
owner: "{{ system_user }}"
37-
group: "{{ system_group }}"
36+
owner: "{{ django_system_user }}"
37+
group: "{{ django_system_group }}"
3838
notify:
3939
- restart_service
4040
- restart_celery
4141

4242
- name: Copy uwsgi.ini
4343
template:
4444
src: uwsgi.ini.j2
45-
dest: "{{ checkout_path }}/uwsgi.ini"
45+
dest: "{{ django_checkout_path }}/uwsgi.ini"
4646
mode: 0644
47-
owner: "{{ system_user }}"
48-
group: "{{ system_group }}"
47+
owner: "{{ django_system_user }}"
48+
group: "{{ django_system_group }}"
4949
notify:
5050
- restart_service

‎tasks/install.yml

+56-56
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
- name: Add system user
22
user:
3-
name: "{{ system_user }}"
3+
name: "{{ django_system_user }}"
44
shell: /bin/bash
5-
group: "{{ system_group }}"
5+
group: "{{ django_system_group }}"
66
append: yes
77
createhome: yes
88

@@ -17,7 +17,7 @@
1717

1818
- name: Install system-wide dependencies
1919
apt:
20-
name: "{{ system_wide_dependencies }}"
20+
name: "{{ django_system_wide_dependencies }}"
2121
state: latest
2222
update_cache: yes
2323
cache_valid_time: 600
@@ -27,75 +27,75 @@
2727
state: absent
2828
path: "{{ item }}"
2929
with_items:
30-
- "{{ venv_path }}"
31-
when: recreate_virtual_env
30+
- "{{ django_venv_path }}"
31+
when: django_recreate_virtual_env
3232

3333
- name: Ensure required directories are present
3434
file:
3535
state: directory
36-
owner: "{{ system_user }}"
36+
owner: "{{ django_system_user }}"
3737
group: www-data
3838
path: "{{ item }}"
3939
when:
4040
- item is defined
4141
- item is not none
4242
with_items:
43-
- "{{ pid_socks_dir }}"
44-
- "{{ versioned_path }}"
45-
- "{{ checkout_path }}"
46-
- "{{ venv_path }}"
47-
- "{{ log_path }}"
48-
- "{{ static_path }}"
49-
- "{{ media_path }}"
50-
- "{{ system_user_home }}/.ssh"
43+
- "{{ django_pid_socks_dir }}"
44+
- "{{ django_versioned_path }}"
45+
- "{{ django_checkout_path }}"
46+
- "{{ django_venv_path }}"
47+
- "{{ django_log_path }}"
48+
- "{{ django_static_path }}"
49+
- "{{ django_media_path }}"
50+
- "{{ django_system_user_home }}/.ssh"
5151

5252
- name: Copy git key
5353
copy:
54-
content: "{{ git_key }}"
55-
dest: "{{ system_user_home }}/.ssh/{{ git_key_filename }}"
56-
owner: "{{ system_user }}"
54+
content: "{{ django_git_key }}"
55+
dest: "{{ django_system_user_home }}/.ssh/{{ django_git_key_filename }}"
56+
owner: "{{ django_system_user }}"
5757
mode: 0600
5858
no_log: False
5959
when:
60-
- git_key is defined
61-
- git_key is not none
60+
- django_git_key is defined
61+
- django_git_key is not none
6262

6363
- name: Git clone with key
6464
git:
6565
accept_hostkey: "yes"
66-
repo: "{{ git_url }}"
67-
dest: "{{ checkout_path }}"
68-
version: "{{ git_version }}"
66+
repo: "{{ django_git_url }}"
67+
dest: "{{ django_checkout_path }}"
68+
version: "{{ django_git_version }}"
6969
depth: 1
70-
key_file: "{{ system_user_home }}/.ssh/{{ git_key_filename }}"
70+
key_file: "{{ django_system_user_home }}/.ssh/{{ django_git_key_filename }}"
7171
become: True
72-
become_user: "{{ system_user }}"
72+
become_user: "{{ django_system_user }}"
7373
when:
74-
- git_key is defined
75-
- git_key is not none
74+
- django_git_key is defined
75+
- django_git_key is not none
7676

7777
- name: Remove Git Key
7878
file:
7979
state: absent
80-
path: "{{ system_user_home }}/.ssh/{{ git_key_filename }}"
80+
path: "{{ django_system_user_home }}/.ssh/{{ django_git_key_filename }}"
8181
become: True
82-
become_user: "{{ system_user }}"
82+
become_user: "{{ django_system_user }}"
8383
when:
84-
- git_key is defined
85-
- git_key is not none
86-
- remove_git_key == True
84+
- django_git_key is defined
85+
- django_git_key is not none
86+
- django_remove_git_key == True
8787

8888
- name: Git clone without key
8989
git:
9090
accept_hostkey: "yes"
91-
repo: "{{ git_url }}"
92-
dest: "{{ checkout_path }}"
93-
version: "{{ git_version }}"
91+
repo: "{{ django_git_url }}"
92+
dest: "{{ django_checkout_path }}"
93+
version: "{{ django_git_version }}"
9494
depth: 1
9595
become: True
96-
become_user: "{{ system_user }}"
96+
become_user: "{{ django_system_user }}"
9797
when:
98-
- git_key is not defined or git_key is none
98+
- django_git_key is not defined or django_git_key is none
9999

100100
- name: Upgrade pip to latest version
101101
pip:
@@ -106,48 +106,48 @@
106106
pip:
107107
state: present
108108
requirements: "{{ item }}"
109-
virtualenv: "{{ venv_path }}"
110-
virtualenv_python: "{{ python_version }}"
111-
become_user: "{{ system_user }}"
112-
with_items: "{{ pip_paths }}"
109+
virtualenv: "{{ django_venv_path }}"
110+
virtualenv_python: "{{ django_python_version }}"
111+
become_user: "{{ django_system_user }}"
112+
with_items: "{{ django_pip_paths }}"
113113
environment:
114114
PATH: "{{ ansible_env.PATH }}:{{ ansible_user_dir }}/.local/bin"
115115
when:
116-
- use_regular_old_pip == True
116+
- django_use_regular_old_pip == True
117117

118118
- name: Install pipenv
119119
pip:
120120
name: pipenv
121121
state: latest
122-
virtualenv: "{{ venv_path }}"
123-
virtualenv_python: "{{ python_version }}"
124-
become_user: "{{ system_user }}"
122+
virtualenv: "{{ django_venv_path }}"
123+
virtualenv_python: "{{ django_python_version }}"
124+
become_user: "{{ django_system_user }}"
125125
environment:
126126
PATH: "{{ ansible_env.PATH }}:{{ ansible_user_dir }}/.local/bin"
127127
when:
128-
- use_pipenv == True
128+
- django_use_pipenv == True
129129

130130
- name: Install Python packages using pipenv
131-
shell: source {{ venv_path }}/bin/activate && pipenv sync --python {{ python_source_version }}
132-
become_user: "{{ system_user }}"
131+
shell: source {{ django_venv_path }}/bin/activate && pipenv sync --python {{ django_python_source_version }}
132+
become_user: "{{ django_system_user }}"
133133
args:
134-
chdir: "{{ checkout_path }}"
134+
chdir: "{{ django_checkout_path }}"
135135
executable: /bin/bash
136136
when:
137-
- use_pipenv == True
137+
- django_use_pipenv == True
138138

139139
- name: Install other python packages using pip
140140
pip:
141-
name: "{{ pip_packages }}"
141+
name: "{{ django_pip_packages }}"
142142
state: latest
143-
virtualenv: "{{ venv_path }}"
144-
virtualenv_python: "{{ python_version }}"
145-
become_user: "{{ system_user }}"
143+
virtualenv: "{{ django_venv_path }}"
144+
virtualenv_python: "{{ django_python_version }}"
145+
become_user: "{{ django_system_user }}"
146146

147147
- name: Copy local settings from template
148148
template:
149149
src: local_settings.py.j2
150-
dest: "{{ local_settings_path }}"
151-
owner: "{{ system_user }}"
152-
group: "{{ system_group }}"
150+
dest: "{{ django_local_settings_path }}"
151+
owner: "{{ django_system_user }}"
152+
group: "{{ django_system_group }}"
153153
mode: 0644

‎tasks/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
- name: Install celery
1818
include_tasks: celery.yml
19-
when: enable_celery == True
19+
when: django_enable_celery == True
2020
tags:
2121
- celery
2222

‎tasks/service.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
- reload systemctl
99
- restart_service
1010
with_items:
11-
- "{{ service_name }}.service"
11+
- "{{ django_service_name }}.service"

‎templates/etc/default/celerybeat.j2

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
# Where to chdir at start.
2-
CELERYBEAT_CHDIR="{{ codebase_path }}"
2+
CELERYBEAT_CHDIR="{{ django_codebase_path }}"
33

44
# Python interpreter from environment, if using virtualenv
5-
ENV_PYTHON="{{ venv_path }}/bin/python"
6-
CELERY_BIN="{{ venv_path }}/bin/celery"
5+
ENV_PYTHON="{{ django_venv_path }}/bin/python"
6+
CELERY_BIN="{{ django_venv_path }}/bin/celery"
77

88
# Name of the celery config module, don't change this.
9-
CELERY_APP="{{ celery_app }}"
9+
CELERY_APP="{{ django_celery_app }}"
1010

1111
# %n will be replaced with the nodename.
1212

1313
# Workers should run as an unprivileged user.
14-
CELERYBEAT_USER="{{ system_user }}"
15-
CELERYBEAT_GROUP="{{ system_group }}"
14+
CELERYBEAT_USER="{{ django_system_user }}"
15+
CELERYBEAT_GROUP="{{ django_system_group }}"
1616

1717
# Set any other env vars here too!
18-
PROJET_ENV="{{ env_name }}"
18+
PROJET_ENV="{{ django_env_name }}"
1919
C_FORCE_ROOT=1
20-
CELERYBEAT_LOG_LEVEL="{{ celerybeat_log_level }}"
21-
CELERYBEAT_LOG_FILE="/var/log/{{ system_user }}/celerybeat.log"
20+
CELERYBEAT_LOG_LEVEL="{{ django_celerybeat_log_level }}"
21+
CELERYBEAT_LOG_FILE="/var/log/{{ django_system_user }}/celerybeat.log"
2222
CELERY_CREATE_DIRS=1
23-
CELERYBEAT_SCHEDULE="/var/run/{{ system_user }}/celerybeat-schedule"
24-
CELERYBEAT_STATE_DIR="/var/run/{{ system_user }}/celerybeat"
25-
{% if celery_beat_pid_file %}
26-
CELERYBEAT_PID_FILE="{{ celery_beat_pid_file }}"
23+
CELERYBEAT_SCHEDULE="/var/run/{{ django_system_user }}/celerybeat-schedule"
24+
CELERYBEAT_STATE_DIR="/var/run/{{ django_system_user }}/celerybeat"
25+
{% if django_celery_beat_pid_file %}
26+
CELERYBEAT_PID_FILE="{{ django_celery_beat_pid_file }}"
2727
{% else %}
28-
CELERYBEAT_PID_FILE="/var/run/{{ system_user }}/celerybeat.pid"
28+
CELERYBEAT_PID_FILE="/var/run/{{ django_system_user }}/celerybeat.pid"
2929
{% endif %}
3030
# Name of the projects settings module.
3131
# in this case is just settings and not the full path because it will change the dir to

‎templates/etc/default/celeryd.j2

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
# Name of nodes to start, here we have a single node
2-
CELERYD_NODES="{{ celeryd_nodes }}"
2+
CELERYD_NODES="{{ django_celeryd_nodes }}"
33

44
# Where to chdir at start.
5-
CELERYD_CHDIR="{{ codebase_path }}"
5+
CELERYD_CHDIR="{{ django_codebase_path }}"
66

77
# Python interpreter from environment, if using virtualenv
8-
ENV_PYTHON="{{ venv_path }}/bin/python"
8+
ENV_PYTHON="{{ django_venv_path }}/bin/python"
99

1010
# How to call "manage.py celeryd_multi"
11-
#CELERYD_MULTI="{{ venv_path }}/bin/celeryd-multi"
11+
#CELERYD_MULTI="{{ django_venv_path }}/bin/celeryd-multi"
1212

1313
# How to call "manage.py celeryctl"
1414
#CELERYCTL="$ENV_PYTHON $CELERYD_CHDIR/manage.py celeryctl"
15-
CELERY_BIN="{{ venv_path }}/bin/celery"
15+
CELERY_BIN="{{ django_venv_path }}/bin/celery"
1616
# Extra arguments to celeryd
17-
CELERYD_OPTS="{{ celeryd_opts }}"
17+
CELERYD_OPTS="{{ django_celeryd_opts }}"
1818

19-
CELERY_APP="{{ celery_app }}"
19+
CELERY_APP="{{ django_celery_app }}"
2020
# Name of the celery config module, don't change this.
2121
#CELERY_CONFIG_MODULE="celeryconfig"
2222

2323
# %n will be replaced with the nodename.
24-
CELERYD_LOG_FILE="/var/log/{{ system_user }}/celery-%n.log"
25-
{% if celeryd_pid_file %}
26-
CELERYD_PID_FILE="{{ celeryd_pid_file }}"
24+
CELERYD_LOG_FILE="/var/log/{{ django_system_user }}/celery-%n.log"
25+
{% if django_celeryd_pid_file %}
26+
CELERYD_PID_FILE="{{ django_celeryd_pid_file }}"
2727
{% else %}
28-
CELERYD_PID_FILE="/run/celery-{{ system_user }}/%n.pid"
28+
CELERYD_PID_FILE="/run/celery-{{ django_system_user }}/%n.pid"
2929
{% endif %}
3030

3131
# Workers should run as an unprivileged user.
32-
CELERYD_USER="{{ system_user }}"
33-
CELERYD_GROUP="{{ system_group }}"
32+
CELERYD_USER="{{ django_system_user }}"
33+
CELERYD_GROUP="{{ django_system_group }}"
3434

3535
CELERY_CREATE_DIRS=1
3636
C_FORCE_ROOT=1
37-
CELERYD_LOG_LEVEL="{{ celeryd_log_level }}"
37+
CELERYD_LOG_LEVEL="{{ django_celeryd_log_level }}"
3838
DJANGO_SETTINGS_MODULE="{{ django_settings_module }}"
+8-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
[Unit]
2-
Description=Celery Beat Schedular {{ system_user }} Service
2+
Description=Celery Beat Schedular {{ django_system_user }} Service
33
After=network.target
44

55
[Service]
66
Type=simple
7-
User={{ system_user }}
8-
Group={{ system_group }}
9-
EnvironmentFile=-/etc/default/celerybeat-{{ system_user }}
10-
WorkingDirectory={{ codebase_path }}
11-
RuntimeDirectory=celery-{{ system_user }}
7+
User={{ django_system_user }}
8+
Group={{ django_system_group }}
9+
EnvironmentFile=-/etc/default/celerybeat-{{ django_system_user }}
10+
WorkingDirectory={{ django_codebase_path }}
11+
RuntimeDirectory=celery-{{ django_system_user }}
1212
ExecStart=/bin/sh -c '${CELERY_BIN} beat \
1313
-A $CELERY_APP \
14-
--workdir={{ codebase_path }} \
14+
--workdir={{ django_codebase_path }} \
1515
--pidfile=${CELERYBEAT_PID_FILE} \
1616
--logfile=${CELERYBEAT_LOG_FILE} \
1717
--loglevel=${CELERYBEAT_LOG_LEVEL} \
1818
--schedule=${CELERYBEAT_SCHEDULE}'
19-
ExecStop=/bin/systemctl kill celerybeat-{{ system_user }}.service
19+
ExecStop=/bin/systemctl kill celerybeat-{{ django_system_user }}.service
2020

2121
[Install]
2222
WantedBy=multi-user.target

‎templates/etc/systemd/celeryd.service.j2

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[Unit]
2-
Description=Celery {{ system_user }} Service
2+
Description=Celery {{ django_system_user }} Service
33
After=network.target
44

55
[Service]
66
Type=forking
7-
User={{ system_user }}
8-
Group={{ system_group }}
9-
EnvironmentFile=-/etc/default/celeryd-{{ system_user }}
10-
WorkingDirectory={{ codebase_path }}
11-
RuntimeDirectory=celery-{{ system_user }}
7+
User={{ django_system_user }}
8+
Group={{ django_system_group }}
9+
EnvironmentFile=-/etc/default/celeryd-{{ django_system_user }}
10+
WorkingDirectory={{ django_codebase_path }}
11+
RuntimeDirectory=celery-{{ django_system_user }}
1212
ExecStart=/bin/sh -c '${CELERY_BIN} multi start $CELERYD_NODES \
1313
-A $CELERY_APP --logfile=${CELERYD_LOG_FILE} \
1414
--loglevel="${CELERYD_LOG_LEVEL}" \
+10-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
[Unit]
2-
Description=uWSGI {{ service_name }} web app
3-
After={{ service_unit_after}}
2+
Description=uWSGI {{ django_service_name }} web app
3+
After={{ django_service_unit_after}}
44

55
[Service]
6-
Type={{ service_type }}
7-
Restart={{ service_restart }}
8-
RuntimeDirectory={{ service_name }}
9-
WorkingDirectory={{ codebase_path }}
10-
User={{ system_user }}
11-
Group={{ service_group }}
12-
ExecStart={{ venv_path }}/bin/uwsgi --ini {{ codebase_path }}/uwsgi.ini --env DJANGO_SETTINGS_MODULE={{ django_settings_module }}
6+
Type={{ django_service_type }}
7+
Restart={{ django_service_restart }}
8+
RuntimeDirectory={{ django_service_name }}
9+
WorkingDirectory={{ django_codebase_path }}
10+
User={{ django_system_user }}
11+
Group={{ django_service_group }}
12+
ExecStart={{ django_venv_path }}/bin/uwsgi --ini {{ django_codebase_path }}/uwsgi.ini --env DJANGO_SETTINGS_MODULE={{ django_settings_module }}
1313

1414

1515
[Install]
16-
WantedBy={{ service_install_wantedby }}
16+
WantedBy={{ django_service_install_wantedby }}

‎templates/local_settings.py.j2

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
{% if top_python_statements %}
2-
{% for stmt in top_python_statements %}
1+
{% if django_top_python_statements %}
2+
{% for stmt in django_top_python_statements %}
33
{{ stmt }}
44
{% endfor %}
55
{% endif %}
@@ -8,8 +8,8 @@
88
{{k}} = {{v}}
99
{% endfor %}
1010

11-
{% if bottom_python_statements %}
12-
{% for stmt in bottom_python_statements %}
11+
{% if django_bottom_python_statements %}
12+
{% for stmt in django_bottom_python_statements %}
1313
{{ stmt }}
1414
{% endfor %}
1515
{% endif %}

‎templates/uwsgi.ini.j2

+25-25
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
[uwsgi]
2-
{% if wsgi_http %}
3-
http={{wsgi_http}}
2+
{% if django_wsgi_http %}
3+
http={{django_wsgi_http}}
44
{% endif %}
5-
socket={{ wsgi_socket }}
6-
chown-socket={{ wsgi_user }}:{{ wsgi_group }}
7-
chmod-socket={{ wsgi_chmod_socket }}
8-
uid={{ wsgi_user }}
9-
gid={{ wsgi_group }}
10-
chdir={{ codebase_path }}
11-
module={{ wsgi_module }}
12-
master={{ wsgi_master }}
13-
processes={{ wsgi_processes }}
14-
pidfile={{ pid_file }}
15-
vacuum={{ wsgi_vacuum }} # clear environment on exit
16-
harakiri={{ wsgi_harakiri }} # respawn processes taking more than 240 seconds
17-
max-requests={{ wsgi_max_requests }} # respawn processes after serving 5000 requests
18-
logto={{ wsgi_logto }}
19-
virtualenv={{ wsgi_virtualenv }}
20-
{% if wsgi_static_map %}
21-
static-map={{ wsgi_static_map }}
5+
socket={{ django_wsgi_socket }}
6+
chown-socket={{ django_wsgi_user }}:{{ django_wsgi_group }}
7+
chmod-socket={{ django_wsgi_chmod_socket }}
8+
uid={{ django_wsgi_user }}
9+
gid={{ django_wsgi_group }}
10+
chdir={{ django_codebase_path }}
11+
module={{ django_wsgi_module }}
12+
master={{ django_wsgi_master }}
13+
processes={{ django_wsgi_processes }}
14+
pidfile={{ django_pid_file }}
15+
vacuum={{ django_wsgi_vacuum }} # clear environment on exit
16+
harakiri={{ django_wsgi_harakiri }} # respawn processes taking more than 240 seconds
17+
max-requests={{ django_wsgi_max_requests }} # respawn processes after serving 5000 requests
18+
logto={{ django_wsgi_logto }}
19+
virtualenv={{ django_wsgi_virtualenv }}
20+
{% if django_wsgi_static_map %}
21+
static-map={{ django_wsgi_static_map }}
2222
{% endif %}
23-
buffer-size={{ wsgi_buffer_size }}
24-
{% if wsgi_env %}
25-
env={{ wsgi_env }}
23+
buffer-size={{ django_wsgi_buffer_size }}
24+
{% if django_wsgi_env %}
25+
env={{ django_wsgi_env }}
2626
{% endif %}
27-
stats={{ wsgi_stats }}
28-
{% if wsgi_enable_threads %}
27+
stats={{ django_wsgi_stats }}
28+
{% if django_wsgi_enable_threads %}
2929
enable-threads
3030
{% endif %}
31-
{% if wsgi_memory_report %}
31+
{% if django_wsgi_memory_report %}
3232
memory-report
3333
{% endif %}

‎tests/test.yml

+17-17
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,31 @@
1919
- name: Test Django role
2020
hosts: all
2121
vars:
22-
system_user: "django_example_app"
23-
system_user_home: "/home/{{ system_user }}"
24-
recreate_virtual_env: False
25-
codebase_path: "{{ system_user_home }}/app"
26-
versioned_path: "{{ codebase_path }}-versioned"
27-
checkout_path: "{{ versioned_path }}/{{ ansible_date_time['epoch'] }}"
28-
git_url: "https://github.com/moshthepitt/picha"
29-
git_version: "master"
30-
celery_app: "picha"
31-
python_source_version: "2.7"
32-
python_version: "python2.7"
33-
enable_celery: True
34-
local_settings_path: "{{ checkout_path }}/picha/local_settings.py"
22+
django_system_user: "django_example_app"
23+
django_system_user_home: "/home/{{ django_system_user }}"
24+
django_recreate_virtual_env: False
25+
django_codebase_path: "{{ django_system_user_home }}/app"
26+
django_versioned_path: "{{ django_codebase_path }}-versioned"
27+
django_checkout_path: "{{ django_versioned_path }}/{{ ansible_date_time['epoch'] }}"
28+
django_git_url: "https://github.com/moshthepitt/picha"
29+
django_git_version: "master"
30+
django_celery_app: "picha"
31+
django_python_source_version: "2.7"
32+
django_python_version: "python2.7"
33+
django_enable_celery: True
34+
django_local_settings_path: "{{ django_checkout_path }}/picha/local_settings.py"
3535
django_settings_module: "picha.settings"
36-
wsgi_module: "picha.wsgi:application"
36+
django_wsgi_module: "picha.wsgi:application"
3737
django_init_commands:
3838
- migrate --noinput
39-
pip_packages:
39+
django_pip_packages:
4040
- celery
4141
- uwsgi
4242
- 'redis==2.10.6'
43-
top_python_statements:
43+
django_top_python_statements:
4444
- import os
4545
- from decimal import Decimal
46-
bottom_python_statements:
46+
django_bottom_python_statements:
4747
- test_var = Decimal(16)
4848
gather_facts: True
4949
become: True

0 commit comments

Comments
 (0)
Please sign in to comment.