ansible/roles/printer/tasks/main.yml

192 lines
4.7 KiB
YAML

---
- name: Pin Django from Debian bullseye-backports
template:
src: "apt/sources.list.d/bullseye-backports.list.j2"
dest: "/etc/apt/sources.list.d/bullseye-backports.list"
- name: Install printer dependencies
apt:
update_cache: true
install_recommends: false
name:
- cups
- gettext
- python3-authlib
- python3-django
- python3-django-extensions
- python3-docutils
- python3-ipython
- python3-pip
- python3-cups
- python3-psycopg2
- python3-pypdf2
- python3-requests
- python3-sphinx
- python3-sphinx-rtd-theme
- uwsgi
- uwsgi-plugin-python3
register: apt_result
retries: 3
until: apt_result is succeeded
- name: Set configuration directories in development mode
when: printer.version != "main"
set_fact:
module_path: "/var/local/django-printer/printer"
project_path: "/var/local/django-printer"
- name: Set configuration directories in production mode
when: printer.version == "main"
set_fact:
module_path: "/usr/local/lib/python3.9/dist-packages/printer"
project_path: "/usr/local/lib/python3.9/dist-packages/printer"
- name: Create django-printer configuration directory
file:
path: "/etc/django-printer"
state: directory
mode: '2775'
owner: "{{ printer.owner }}"
group: "{{ printer.group }}"
- name: Set ACL for printer directory
acl:
path: "/etc/django-printer"
default: true
entity: _nounou
etype: group
permissions: rwx
state: query
ignore_errors: "{{ ansible_check_mode }}"
- name: Clone printer repository (development)
when: printer.version != "main"
git:
repo: 'https://gitlab.adm.crans.org/nounous/django-printer.git'
dest: "{{ project_path }}"
umask: '002'
version: "{{ printer.version }}"
recursive: true
- name: Install pip module with editable flag (development)
when: printer.version != "main"
pip:
name:
- "{{ project_path }}"
editable: true
state: latest
- name: Install and upgrade django-printer (production)
when: printer.version == "main"
pip:
name:
- git+https://gitlab.adm.crans.org/nounous/django-printer.git
state: latest
- name: Set owner of cloned project
when: printer.version != "main"
file:
path: "{{ project_path }}"
owner: "{{ printer.owner }}"
group: "{{ printer.group }}"
recurse: true
- name: Set manage.py executable
file:
path: "{{ module_path }}/manage.py"
mode: 0755
- name: Deploy local settings
template:
src: django-printer/settings_local.py.j2
dest: "/etc/django-printer/settings_local.py"
mode: 0660
- name: Symlink configuration file
file:
src: "/etc/django-printer/settings_local.py"
dest: "{{ module_path }}/settings_local.py"
state: link
ignore_errors: "{{ ansible_check_mode }}"
# In the future, migrations will be included in the repository.
- name: Make Django migrations
django_manage:
command: makemigrations
project_path: "{{ project_path }}"
notify: Restart uWSGI
- name: Migrate database
django_manage:
command: migrate
project_path: "{{ project_path }}"
notify: Restart uWSGI
- name: Create static files directory
file:
path: "/var/lib/django-printer/{{ item }}"
state: directory
mode: '2775'
owner: "www-data"
group: "{{ printer.group }}"
recurse: true
loop:
- static
- files
- name: Collect static files
django_manage:
command: collectstatic
project_path: "{{ project_path }}"
notify: Restart uWSGI
- name: Compile messages
django_manage:
command: compilemessages
project_path: "{{ project_path }}"
- name: Copy uWSGI app
template:
src: "uwsgi/apps-available/django-printer.ini.j2"
dest: "/etc/uwsgi/apps-available/django-printer.ini"
owner: root
group: root
mode: 0644
notify: Restart uWSGI
- name: Activate uWSGI app
file:
src: "../apps-available/django-printer.ini"
dest: "/etc/uwsgi/apps-enabled/django-printer.ini"
owner: root
group: root
state: link
ignore_errors: "{{ ansible_check_mode }}"
notify: Restart uWSGI
- name: Create documentation directory with good permissions
file:
path: /var/www/django-printer-doc
state: directory
owner: www-data
group: www-data
mode: u=rwx,g=rwxs,o=rx
- name: Clone projet to get documentation sources
git:
repo: 'https://gitlab.adm.crans.org/nounous/django-printer.git'
dest: '/tmp/django-printer'
umask: '002'
version: "{{ printer.version }}"
- name: Build HTML documentation
command: "sphinx-build -b dirhtml /tmp/django-printer/docs/ /var/www/django-printer-doc/"
become_user: www-data
- name: Indicate module in motd
template:
src: update-motd.d/05-service.j2
dest: /etc/update-motd.d/05-django-printer
mode: 0755