- name: Create logging dir
  file:
    path: "{{ django_log_file | dirname }}"
    state: directory
    owner: "{{ gunicorn_user }}"
    group: "{{ gunicorn_user_group }}"
    recurse: yes
  when: django_log_file is defined and django_log_file

- name: Upload local settings file
  template:
    src: local_settings.py.j2
    dest: "{{ django_local_settings }}"
  notify:
    - reload celery
    - restart gunicorn

- name: Run Django migrations
  django_manage:
    command: migrate
    app_path: "{{ django_app_path }}"
    virtualenv: "{{ virtualenv }}"
  notify:
    - reload celery
    - restart gunicorn

- name: Compile SCSS
  django_manage:
    command: compilescss
    app_path: "{{ django_app_path }}"
    virtualenv: "{{ virtualenv }}"

- name: Collect static files
  django_manage:
    command: collectstatic -i *.scss --noinput
    app_path: "{{ django_app_path }}"
    virtualenv: "{{ virtualenv }}"

- name: Create logging dir
  file:
    path: "{{ django_log_file | dirname }}"
    state: directory
    owner: "{{ gunicorn_user }}"
    group: "{{ gunicorn_user_group }}"
    recurse: yes
  when: django_log_file is defined and django_log_file

- name: Create log file with correct permissions
  file:
    path: "{{ django_log_file }}"
    state: touch
    owner: "{{ gunicorn_user }}"
    group: "{{ gunicorn_user_group | default(omit) }}"
  when: django_log_file is defined and django_log_file

- name: Upload local settings file
  template:
    src: local_settings.py.j2
    dest: "{{ django_local_settings }}"
  notify:
    - reload celery
    - restart gunicorn

- name: Run Django migrations
  django_manage:
    command: migrate
    app_path: "{{ django_app_path }}"
    virtualenv: "{{ virtualenv }}"
  notify:
    - reload celery
    - restart gunicorn

- name: Compile SCSS
  django_manage:
    command: compilescss
    app_path: "{{ django_app_path }}"
    virtualenv: "{{ virtualenv }}"

- name: Collect static files
  django_manage:
    command: collectstatic -i *.scss --noinput
    app_path: "{{ django_app_path }}"
    virtualenv: "{{ virtualenv }}"

Fix issue with log permissions.
Fix issue with log permissions.

Somehow the log file for django was being created with root permissions.
This was preventing gunicorn from writing to it later which caused the
gunicorn worker to crash. The fix is to 'touch' the file and set the
correct permissions on it before running the worker.
