ansible/roles/printer/tasks/main.yml

167 lines
4.1 KiB
YAML

---
- name: Pin Django from Debian bullseye-backports
template:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
loop:
- src: "apt/sources.list.d/bullseye-backports.list.j2"
dest: "/etc/apt/sources.list.d/bullseye-backports.list"
- src: "apt/preferences.d/django-backports.j2"
dest: "/etc/apt/preferences.d/django-backports"
- name: Install printer dependencies
apt:
update_cache: true
install_recommends: false
name:
- cups
- gettext
- python3-authlib
- python3-cups
- python3-django
- python3-django-auth-ldap
- python3-django-crispy-forms
- python3-django-extensions
- python3-docutils
- python3-ipython
- python3-pip
- 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: Install non-packaged dependencies
pip:
name: crispy-bootstrap5==0.4
- 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
git:
repo: 'https://gitlab.adm.crans.org/nounous/django-printer.git'
dest: "/var/local/django-printer"
umask: '002'
version: "{{ printer.version }}"
recursive: true
- name: Set owner of cloned project
file:
path: "/var/local/django-printer"
owner: "{{ printer.owner }}"
group: "{{ printer.group }}"
recurse: true
- name: Set manage.py executable
file:
path: "/var/local/django-printer/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: "/var/local/django-printer/printer/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: "/var/local/django-printer"
notify: Restart uWSGI
- name: Migrate database
django_manage:
command: migrate
project_path: "/var/local/django-printer"
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: "/var/local/django-printer"
notify: Restart uWSGI
- name: Compile messages
django_manage:
command: compilemessages
project_path: "/var/local/django-printer"
- 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: Build HTML documentation
command: "sphinx-build -b dirhtml /var/local/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