blender-id/playbooks/tasks/deploy.yaml

88 lines
2.5 KiB
YAML

---
- name: Pulling latest branch "{{ branch }}"
ansible.builtin.git:
repo: "{{ source_url }}"
dest: "{{ dir.source }}"
accept_hostkey: true
version: "{{ branch }}"
tags:
- git
- name: Copying error pages
ansible.builtin.template:
src: templates/nginx/errors/503-service-unavailable.html
dest: "{{ dir.errors }}/503-service-unavailable.html"
mode: 0644
- name: Deleting {{ dir.source }}/.venv if it exists
ansible.builtin.file:
path: "{{ dir.source }}/.venv"
state: absent
when: delete_venv
- name: Installing remaining Python dependencies in {{ dir.source }}/.venv
ansible.builtin.pip:
requirements: "{{ dir.source }}/requirements.txt"
virtualenv: "{{ dir.source }}/.venv"
virtualenv_command: python{{ python_version }} -m venv
chdir: "{{ dir.source }}"
tags:
- pip
- name: Preparing to run database migrations
tags:
- migrate
block:
- name: Displaying database migrations
import_tasks: managepy.yaml
vars:
command: migrate --plan
- name: Displaying database migrations
ansible.builtin.debug:
var: management_command_output.stdout
- name: Confirming database migrations
when:
- management_command_output.stdout | length > 0
- ('No planned migration operations' not in management_command_output.stdout)
ansible.builtin.pause:
prompt: Press return to continue. Press Ctrl+c and then "a" to abort.
- name: Running database migrations
when:
- management_command_output.stdout | length > 0
- ('No planned migration operations' not in management_command_output.stdout)
import_tasks: managepy.yaml
vars:
command: migrate
changed_when:
- management_command_output.stdout | length > 0
- ('No planned migration operations' not in management_command_output.stdout)
- name: Collecting static files
ansible.builtin.command: "{{ dir.source }}/.venv/bin/python {{ dir.source }}/manage.py collectstatic --noinput"
args:
chdir: "{{ dir.source }}"
changed_when: true
tags:
- collectstatic
notify:
- restart service
- test nginx
- reload nginx
- name: Creating a directory for docs
ansible.builtin.file: path={{ item }} state=directory owner={{ user }} group={{ group }} recurse=yes
with_items:
- "{{ dir.docs }}"
tags:
- docs
- name: Building docs
changed_when: true
ansible.builtin.command: "{{ dir.source }}/.venv/bin/mkdocs build --site-dir={{ dir.docs }}"
args:
chdir: "{{ dir.source }}/docs"
tags:
- docs