From 1d8505786c09aec7475e91a1d9c178cac896a0b9 Mon Sep 17 00:00:00 2001 From: Kelvin Jayanoris Date: Thu, 28 Mar 2019 18:43:36 +0300 Subject: [PATCH] Add django prefix to all variables --- README.md | 12 +- defaults/main.yml | 138 ++++++++++---------- handlers/main.yml | 14 +- meta/main.yml | 2 +- tasks/celery.yml | 8 +- tasks/cleanup.yml | 4 +- tasks/configure.yml | 40 +++--- tasks/install.yml | 112 ++++++++-------- tasks/main.yml | 2 +- tasks/service.yml | 2 +- templates/etc/default/celerybeat.j2 | 28 ++-- templates/etc/default/celeryd.j2 | 28 ++-- templates/etc/systemd/celerybeat.service.j2 | 16 +-- templates/etc/systemd/celeryd.service.j2 | 12 +- templates/etc/systemd/django.service.j2 | 20 +-- templates/local_settings.py.j2 | 8 +- templates/uwsgi.ini.j2 | 50 +++---- tests/test.yml | 34 ++--- 18 files changed, 265 insertions(+), 265 deletions(-) diff --git a/README.md b/README.md index ccf5b27..520e748 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/defaults/main.yml b/defaults/main.yml index 543a3a6..38926d2 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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 @@ -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'" @@ -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: diff --git a/handlers/main.yml b/handlers/main.yml index 3ef42eb..9080166 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -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 \ No newline at end of file + - django_enable_celery == True + - django_manage_services == True \ No newline at end of file diff --git a/meta/main.yml b/meta/main.yml index 5ebc57a..106cf02 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -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 \ No newline at end of file diff --git a/tasks/celery.yml b/tasks/celery.yml index 172d236..b1eb160 100644 --- a/tasks/celery.yml +++ b/tasks/celery.yml @@ -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 @@ -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 diff --git a/tasks/cleanup.yml b/tasks/cleanup.yml index 2b78ab3..9f79a86 100644 --- a/tasks/cleanup.yml +++ b/tasks/cleanup.yml @@ -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 \ No newline at end of file diff --git a/tasks/configure.yml b/tasks/configure.yml index f47517c..1bd9624 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -2,39 +2,39 @@ - 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 @@ -42,9 +42,9 @@ - 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 \ No newline at end of file diff --git a/tasks/install.yml b/tasks/install.yml index 35ce9e9..3df7135 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -1,8 +1,8 @@ - name: Add system user user: - name: "{{ system_user }}" + name: "{{ django_system_user }}" shell: /bin/bash - group: "{{ system_group }}" + group: "{{ django_system_group }}" append: yes createhome: yes @@ -17,7 +17,7 @@ - name: Install system-wide dependencies apt: - name: "{{ system_wide_dependencies }}" + name: "{{ django_system_wide_dependencies }}" state: latest update_cache: yes cache_valid_time: 600 @@ -27,75 +27,75 @@ state: absent path: "{{ item }}" with_items: - - "{{ venv_path }}" - when: recreate_virtual_env + - "{{ django_venv_path }}" + when: django_recreate_virtual_env - name: Ensure required directories are present file: state: directory - owner: "{{ system_user }}" + owner: "{{ django_system_user }}" group: www-data path: "{{ item }}" when: - item is defined - item is not none with_items: - - "{{ pid_socks_dir }}" - - "{{ versioned_path }}" - - "{{ checkout_path }}" - - "{{ venv_path }}" - - "{{ log_path }}" - - "{{ static_path }}" - - "{{ media_path }}" - - "{{ system_user_home }}/.ssh" + - "{{ django_pid_socks_dir }}" + - "{{ django_versioned_path }}" + - "{{ django_checkout_path }}" + - "{{ django_venv_path }}" + - "{{ django_log_path }}" + - "{{ django_static_path }}" + - "{{ django_media_path }}" + - "{{ django_system_user_home }}/.ssh" - name: Copy git key copy: - content: "{{ git_key }}" - dest: "{{ system_user_home }}/.ssh/{{ git_key_filename }}" - owner: "{{ system_user }}" + content: "{{ django_git_key }}" + dest: "{{ django_system_user_home }}/.ssh/{{ django_git_key_filename }}" + owner: "{{ django_system_user }}" mode: 0600 no_log: False when: - - git_key is defined - - git_key is not none + - django_git_key is defined + - django_git_key is not none - name: Git clone with key git: accept_hostkey: "yes" - repo: "{{ git_url }}" - dest: "{{ checkout_path }}" - version: "{{ git_version }}" + repo: "{{ django_git_url }}" + dest: "{{ django_checkout_path }}" + version: "{{ django_git_version }}" depth: 1 - key_file: "{{ system_user_home }}/.ssh/{{ git_key_filename }}" + key_file: "{{ django_system_user_home }}/.ssh/{{ django_git_key_filename }}" become: True - become_user: "{{ system_user }}" + become_user: "{{ django_system_user }}" when: - - git_key is defined - - git_key is not none + - django_git_key is defined + - django_git_key is not none - name: Remove Git Key file: state: absent - path: "{{ system_user_home }}/.ssh/{{ git_key_filename }}" + path: "{{ django_system_user_home }}/.ssh/{{ django_git_key_filename }}" become: True - become_user: "{{ system_user }}" + become_user: "{{ django_system_user }}" when: - - git_key is defined - - git_key is not none - - remove_git_key == True + - django_git_key is defined + - django_git_key is not none + - django_remove_git_key == True - name: Git clone without key git: accept_hostkey: "yes" - repo: "{{ git_url }}" - dest: "{{ checkout_path }}" - version: "{{ git_version }}" + repo: "{{ django_git_url }}" + dest: "{{ django_checkout_path }}" + version: "{{ django_git_version }}" depth: 1 become: True - become_user: "{{ system_user }}" + become_user: "{{ django_system_user }}" when: - - git_key is not defined or git_key is none + - django_git_key is not defined or django_git_key is none - name: Upgrade pip to latest version pip: @@ -106,48 +106,48 @@ pip: state: present requirements: "{{ item }}" - virtualenv: "{{ venv_path }}" - virtualenv_python: "{{ python_version }}" - become_user: "{{ system_user }}" - with_items: "{{ pip_paths }}" + virtualenv: "{{ django_venv_path }}" + virtualenv_python: "{{ django_python_version }}" + become_user: "{{ django_system_user }}" + with_items: "{{ django_pip_paths }}" environment: PATH: "{{ ansible_env.PATH }}:{{ ansible_user_dir }}/.local/bin" when: - - use_regular_old_pip == True + - django_use_regular_old_pip == True - name: Install pipenv pip: name: pipenv state: latest - virtualenv: "{{ venv_path }}" - virtualenv_python: "{{ python_version }}" - become_user: "{{ system_user }}" + virtualenv: "{{ django_venv_path }}" + virtualenv_python: "{{ django_python_version }}" + become_user: "{{ django_system_user }}" environment: PATH: "{{ ansible_env.PATH }}:{{ ansible_user_dir }}/.local/bin" when: - - use_pipenv == True + - django_use_pipenv == True - name: Install Python packages using pipenv - shell: source {{ venv_path }}/bin/activate && pipenv sync --python {{ python_source_version }} - become_user: "{{ system_user }}" + shell: source {{ django_venv_path }}/bin/activate && pipenv sync --python {{ django_python_source_version }} + become_user: "{{ django_system_user }}" args: - chdir: "{{ checkout_path }}" + chdir: "{{ django_checkout_path }}" executable: /bin/bash when: - - use_pipenv == True + - django_use_pipenv == True - name: Install other python packages using pip pip: - name: "{{ pip_packages }}" + name: "{{ django_pip_packages }}" state: latest - virtualenv: "{{ venv_path }}" - virtualenv_python: "{{ python_version }}" - become_user: "{{ system_user }}" + virtualenv: "{{ django_venv_path }}" + virtualenv_python: "{{ django_python_version }}" + become_user: "{{ django_system_user }}" - name: Copy local settings from template template: src: local_settings.py.j2 - dest: "{{ local_settings_path }}" - owner: "{{ system_user }}" - group: "{{ system_group }}" + dest: "{{ django_local_settings_path }}" + owner: "{{ django_system_user }}" + group: "{{ django_system_group }}" mode: 0644 diff --git a/tasks/main.yml b/tasks/main.yml index f380e17..6f5ebe8 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -16,7 +16,7 @@ - name: Install celery include_tasks: celery.yml - when: enable_celery == True + when: django_enable_celery == True tags: - celery diff --git a/tasks/service.yml b/tasks/service.yml index 3dd68a9..21a72ad 100644 --- a/tasks/service.yml +++ b/tasks/service.yml @@ -8,4 +8,4 @@ - reload systemctl - restart_service with_items: - - "{{ service_name }}.service" \ No newline at end of file + - "{{ django_service_name }}.service" \ No newline at end of file diff --git a/templates/etc/default/celerybeat.j2 b/templates/etc/default/celerybeat.j2 index 590135f..ca4d8db 100644 --- a/templates/etc/default/celerybeat.j2 +++ b/templates/etc/default/celerybeat.j2 @@ -1,31 +1,31 @@ # Where to chdir at start. -CELERYBEAT_CHDIR="{{ codebase_path }}" +CELERYBEAT_CHDIR="{{ django_codebase_path }}" # Python interpreter from environment, if using virtualenv -ENV_PYTHON="{{ venv_path }}/bin/python" -CELERY_BIN="{{ venv_path }}/bin/celery" +ENV_PYTHON="{{ django_venv_path }}/bin/python" +CELERY_BIN="{{ django_venv_path }}/bin/celery" # Name of the celery config module, don't change this. -CELERY_APP="{{ celery_app }}" +CELERY_APP="{{ django_celery_app }}" # %n will be replaced with the nodename. # Workers should run as an unprivileged user. -CELERYBEAT_USER="{{ system_user }}" -CELERYBEAT_GROUP="{{ system_group }}" +CELERYBEAT_USER="{{ django_system_user }}" +CELERYBEAT_GROUP="{{ django_system_group }}" # Set any other env vars here too! -PROJET_ENV="{{ env_name }}" +PROJET_ENV="{{ django_env_name }}" C_FORCE_ROOT=1 -CELERYBEAT_LOG_LEVEL="{{ celerybeat_log_level }}" -CELERYBEAT_LOG_FILE="/var/log/{{ system_user }}/celerybeat.log" +CELERYBEAT_LOG_LEVEL="{{ django_celerybeat_log_level }}" +CELERYBEAT_LOG_FILE="/var/log/{{ django_system_user }}/celerybeat.log" CELERY_CREATE_DIRS=1 -CELERYBEAT_SCHEDULE="/var/run/{{ system_user }}/celerybeat-schedule" -CELERYBEAT_STATE_DIR="/var/run/{{ system_user }}/celerybeat" -{% if celery_beat_pid_file %} -CELERYBEAT_PID_FILE="{{ celery_beat_pid_file }}" +CELERYBEAT_SCHEDULE="/var/run/{{ django_system_user }}/celerybeat-schedule" +CELERYBEAT_STATE_DIR="/var/run/{{ django_system_user }}/celerybeat" +{% if django_celery_beat_pid_file %} +CELERYBEAT_PID_FILE="{{ django_celery_beat_pid_file }}" {% else %} -CELERYBEAT_PID_FILE="/var/run/{{ system_user }}/celerybeat.pid" +CELERYBEAT_PID_FILE="/var/run/{{ django_system_user }}/celerybeat.pid" {% endif %} # Name of the projects settings module. # in this case is just settings and not the full path because it will change the dir to diff --git a/templates/etc/default/celeryd.j2 b/templates/etc/default/celeryd.j2 index 5dc0403..98300db 100644 --- a/templates/etc/default/celeryd.j2 +++ b/templates/etc/default/celeryd.j2 @@ -1,38 +1,38 @@ # Name of nodes to start, here we have a single node -CELERYD_NODES="{{ celeryd_nodes }}" +CELERYD_NODES="{{ django_celeryd_nodes }}" # Where to chdir at start. -CELERYD_CHDIR="{{ codebase_path }}" +CELERYD_CHDIR="{{ django_codebase_path }}" # Python interpreter from environment, if using virtualenv -ENV_PYTHON="{{ venv_path }}/bin/python" +ENV_PYTHON="{{ django_venv_path }}/bin/python" # How to call "manage.py celeryd_multi" -#CELERYD_MULTI="{{ venv_path }}/bin/celeryd-multi" +#CELERYD_MULTI="{{ django_venv_path }}/bin/celeryd-multi" # How to call "manage.py celeryctl" #CELERYCTL="$ENV_PYTHON $CELERYD_CHDIR/manage.py celeryctl" -CELERY_BIN="{{ venv_path }}/bin/celery" +CELERY_BIN="{{ django_venv_path }}/bin/celery" # Extra arguments to celeryd -CELERYD_OPTS="{{ celeryd_opts }}" +CELERYD_OPTS="{{ django_celeryd_opts }}" -CELERY_APP="{{ celery_app }}" +CELERY_APP="{{ django_celery_app }}" # Name of the celery config module, don't change this. #CELERY_CONFIG_MODULE="celeryconfig" # %n will be replaced with the nodename. -CELERYD_LOG_FILE="/var/log/{{ system_user }}/celery-%n.log" -{% if celeryd_pid_file %} -CELERYD_PID_FILE="{{ celeryd_pid_file }}" +CELERYD_LOG_FILE="/var/log/{{ django_system_user }}/celery-%n.log" +{% if django_celeryd_pid_file %} +CELERYD_PID_FILE="{{ django_celeryd_pid_file }}" {% else %} -CELERYD_PID_FILE="/run/celery-{{ system_user }}/%n.pid" +CELERYD_PID_FILE="/run/celery-{{ django_system_user }}/%n.pid" {% endif %} # Workers should run as an unprivileged user. -CELERYD_USER="{{ system_user }}" -CELERYD_GROUP="{{ system_group }}" +CELERYD_USER="{{ django_system_user }}" +CELERYD_GROUP="{{ django_system_group }}" CELERY_CREATE_DIRS=1 C_FORCE_ROOT=1 -CELERYD_LOG_LEVEL="{{ celeryd_log_level }}" +CELERYD_LOG_LEVEL="{{ django_celeryd_log_level }}" DJANGO_SETTINGS_MODULE="{{ django_settings_module }}" diff --git a/templates/etc/systemd/celerybeat.service.j2 b/templates/etc/systemd/celerybeat.service.j2 index eb2e8ae..018e88c 100644 --- a/templates/etc/systemd/celerybeat.service.j2 +++ b/templates/etc/systemd/celerybeat.service.j2 @@ -1,22 +1,22 @@ [Unit] -Description=Celery Beat Schedular {{ system_user }} Service +Description=Celery Beat Schedular {{ django_system_user }} Service After=network.target [Service] Type=simple -User={{ system_user }} -Group={{ system_group }} -EnvironmentFile=-/etc/default/celerybeat-{{ system_user }} -WorkingDirectory={{ codebase_path }} -RuntimeDirectory=celery-{{ system_user }} +User={{ django_system_user }} +Group={{ django_system_group }} +EnvironmentFile=-/etc/default/celerybeat-{{ django_system_user }} +WorkingDirectory={{ django_codebase_path }} +RuntimeDirectory=celery-{{ django_system_user }} ExecStart=/bin/sh -c '${CELERY_BIN} beat \ -A $CELERY_APP \ - --workdir={{ codebase_path }} \ + --workdir={{ django_codebase_path }} \ --pidfile=${CELERYBEAT_PID_FILE} \ --logfile=${CELERYBEAT_LOG_FILE} \ --loglevel=${CELERYBEAT_LOG_LEVEL} \ --schedule=${CELERYBEAT_SCHEDULE}' -ExecStop=/bin/systemctl kill celerybeat-{{ system_user }}.service +ExecStop=/bin/systemctl kill celerybeat-{{ django_system_user }}.service [Install] WantedBy=multi-user.target diff --git a/templates/etc/systemd/celeryd.service.j2 b/templates/etc/systemd/celeryd.service.j2 index 072db85..0eee234 100644 --- a/templates/etc/systemd/celeryd.service.j2 +++ b/templates/etc/systemd/celeryd.service.j2 @@ -1,14 +1,14 @@ [Unit] -Description=Celery {{ system_user }} Service +Description=Celery {{ django_system_user }} Service After=network.target [Service] Type=forking -User={{ system_user }} -Group={{ system_group }} -EnvironmentFile=-/etc/default/celeryd-{{ system_user }} -WorkingDirectory={{ codebase_path }} -RuntimeDirectory=celery-{{ system_user }} +User={{ django_system_user }} +Group={{ django_system_group }} +EnvironmentFile=-/etc/default/celeryd-{{ django_system_user }} +WorkingDirectory={{ django_codebase_path }} +RuntimeDirectory=celery-{{ django_system_user }} ExecStart=/bin/sh -c '${CELERY_BIN} multi start $CELERYD_NODES \ -A $CELERY_APP --logfile=${CELERYD_LOG_FILE} \ --loglevel="${CELERYD_LOG_LEVEL}" \ diff --git a/templates/etc/systemd/django.service.j2 b/templates/etc/systemd/django.service.j2 index 66da1b8..d58d114 100644 --- a/templates/etc/systemd/django.service.j2 +++ b/templates/etc/systemd/django.service.j2 @@ -1,16 +1,16 @@ [Unit] -Description=uWSGI {{ service_name }} web app -After={{ service_unit_after}} +Description=uWSGI {{ django_service_name }} web app +After={{ django_service_unit_after}} [Service] -Type={{ service_type }} -Restart={{ service_restart }} -RuntimeDirectory={{ service_name }} -WorkingDirectory={{ codebase_path }} -User={{ system_user }} -Group={{ service_group }} -ExecStart={{ venv_path }}/bin/uwsgi --ini {{ codebase_path }}/uwsgi.ini --env DJANGO_SETTINGS_MODULE={{ django_settings_module }} +Type={{ django_service_type }} +Restart={{ django_service_restart }} +RuntimeDirectory={{ django_service_name }} +WorkingDirectory={{ django_codebase_path }} +User={{ django_system_user }} +Group={{ django_service_group }} +ExecStart={{ django_venv_path }}/bin/uwsgi --ini {{ django_codebase_path }}/uwsgi.ini --env DJANGO_SETTINGS_MODULE={{ django_settings_module }} [Install] -WantedBy={{ service_install_wantedby }} +WantedBy={{ django_service_install_wantedby }} diff --git a/templates/local_settings.py.j2 b/templates/local_settings.py.j2 index ed1bf6d..cf57da6 100644 --- a/templates/local_settings.py.j2 +++ b/templates/local_settings.py.j2 @@ -1,5 +1,5 @@ -{% if top_python_statements %} -{% for stmt in top_python_statements %} +{% if django_top_python_statements %} +{% for stmt in django_top_python_statements %} {{ stmt }} {% endfor %} {% endif %} @@ -8,8 +8,8 @@ {{k}} = {{v}} {% endfor %} -{% if bottom_python_statements %} -{% for stmt in bottom_python_statements %} +{% if django_bottom_python_statements %} +{% for stmt in django_bottom_python_statements %} {{ stmt }} {% endfor %} {% endif %} \ No newline at end of file diff --git a/templates/uwsgi.ini.j2 b/templates/uwsgi.ini.j2 index f7cf5e2..a3bccf3 100644 --- a/templates/uwsgi.ini.j2 +++ b/templates/uwsgi.ini.j2 @@ -1,33 +1,33 @@ [uwsgi] -{% if wsgi_http %} -http={{wsgi_http}} +{% if django_wsgi_http %} +http={{django_wsgi_http}} {% endif %} -socket={{ wsgi_socket }} -chown-socket={{ wsgi_user }}:{{ wsgi_group }} -chmod-socket={{ wsgi_chmod_socket }} -uid={{ wsgi_user }} -gid={{ wsgi_group }} -chdir={{ codebase_path }} -module={{ wsgi_module }} -master={{ wsgi_master }} -processes={{ wsgi_processes }} -pidfile={{ pid_file }} -vacuum={{ wsgi_vacuum }} # clear environment on exit -harakiri={{ wsgi_harakiri }} # respawn processes taking more than 240 seconds -max-requests={{ wsgi_max_requests }} # respawn processes after serving 5000 requests -logto={{ wsgi_logto }} -virtualenv={{ wsgi_virtualenv }} -{% if wsgi_static_map %} -static-map={{ wsgi_static_map }} +socket={{ django_wsgi_socket }} +chown-socket={{ django_wsgi_user }}:{{ django_wsgi_group }} +chmod-socket={{ django_wsgi_chmod_socket }} +uid={{ django_wsgi_user }} +gid={{ django_wsgi_group }} +chdir={{ django_codebase_path }} +module={{ django_wsgi_module }} +master={{ django_wsgi_master }} +processes={{ django_wsgi_processes }} +pidfile={{ django_pid_file }} +vacuum={{ django_wsgi_vacuum }} # clear environment on exit +harakiri={{ django_wsgi_harakiri }} # respawn processes taking more than 240 seconds +max-requests={{ django_wsgi_max_requests }} # respawn processes after serving 5000 requests +logto={{ django_wsgi_logto }} +virtualenv={{ django_wsgi_virtualenv }} +{% if django_wsgi_static_map %} +static-map={{ django_wsgi_static_map }} {% endif %} -buffer-size={{ wsgi_buffer_size }} -{% if wsgi_env %} -env={{ wsgi_env }} +buffer-size={{ django_wsgi_buffer_size }} +{% if django_wsgi_env %} +env={{ django_wsgi_env }} {% endif %} -stats={{ wsgi_stats }} -{% if wsgi_enable_threads %} +stats={{ django_wsgi_stats }} +{% if django_wsgi_enable_threads %} enable-threads {% endif %} -{% if wsgi_memory_report %} +{% if django_wsgi_memory_report %} memory-report {% endif %} \ No newline at end of file diff --git a/tests/test.yml b/tests/test.yml index ffe175a..884f4bd 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -19,31 +19,31 @@ - name: Test Django role hosts: all vars: - system_user: "django_example_app" - system_user_home: "/home/{{ system_user }}" - recreate_virtual_env: False - codebase_path: "{{ system_user_home }}/app" - versioned_path: "{{ codebase_path }}-versioned" - checkout_path: "{{ versioned_path }}/{{ ansible_date_time['epoch'] }}" - git_url: "https://github.com/moshthepitt/picha" - git_version: "master" - celery_app: "picha" - python_source_version: "2.7" - python_version: "python2.7" - enable_celery: True - local_settings_path: "{{ checkout_path }}/picha/local_settings.py" + django_system_user: "django_example_app" + django_system_user_home: "/home/{{ django_system_user }}" + django_recreate_virtual_env: False + 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_git_url: "https://github.com/moshthepitt/picha" + django_git_version: "master" + django_celery_app: "picha" + django_python_source_version: "2.7" + django_python_version: "python2.7" + django_enable_celery: True + django_local_settings_path: "{{ django_checkout_path }}/picha/local_settings.py" django_settings_module: "picha.settings" - wsgi_module: "picha.wsgi:application" + django_wsgi_module: "picha.wsgi:application" django_init_commands: - migrate --noinput - pip_packages: + django_pip_packages: - celery - uwsgi - 'redis==2.10.6' - top_python_statements: + django_top_python_statements: - import os - from decimal import Decimal - bottom_python_statements: + django_bottom_python_statements: - test_var = Decimal(16) gather_facts: True become: True