ansible/roles/chat/tasks/main.yaml
Mark Janssen -- Sig-I/O Automatisering 050205e95c
Some checks failed
Test / build (push) Failing after 57s
Cleanup thelounge playbook
2025-04-27 21:11:17 +02:00

112 lines
3.4 KiB
YAML

---
- name: Install dependencies
ansible.builtin.apt:
state: present
pkg:
- gpg
- apt-transport-https
- build-essential
- name: Import nodesource signing key
ansible.builtin.shell:
cmd: curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor
-o /usr/share/keyrings/nodesource.gpg
args:
creates: /usr/share/keyrings/nodesource.gpg
notify: Apt update
- name: Ensure directories are present
ansible.builtin.file:
path: "{{ item.path }}"
owner: "thelounge"
group: "thelounge"
state: "{{ item.state | default('directory') }}"
mode: "{{ item.mode | default('0770') }}"
with_items:
- { path: "/etc/thelounge" }
- { path: "/var/local/thelounge/users" }
- { path: "/var/local/thelounge/storage" }
notify:
- Restart thelounge
- name: Configure templates
ansible.builtin.template:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: "{{ item.owner | default( 'thelounge' ) }}"
group: "{{ item.group | default( 'thelounge' ) }}"
mode: "{{ item.mode | default('0640') }}"
with_items:
- { src: "nodesource.list", dest: "/etc/apt/sources.list.d/nodesource.list", owner: root, group: root }
- { src: "nodejs-apt-pref", dest: "/etc/apt/preferences.d/nodejs", owner: root, group: root }
- name: Install nodejs
ansible.builtin.apt:
name: nodejs
- name: Install yarn
ansible.builtin.shell:
cmd: npm install --global yarn
- stat: path=/opt/thelounge
register: src_path
- name: Retreive thelounge source
block:
- name: Checkout source
ansible.builtin.git:
repo: 'https://github.com/revspace/thelounge.git'
dest: /opt/thelounge
version: 9d6dc83
force: true
- name: Copy patch
ansible.builtin.template:
src: thelounge-bitlair.patch
dest: /tmp/thelounge-bitlair.patch
- name: Apply patch
ansible.builtin.shell:
chdir: /opt/thelounge
cmd: git apply /tmp/thelounge-bitlair.patch
when: not src_path.stat.exists
- name: Build and install thelounge
ansible.builtin.shell:
chdir: /opt/thelounge
cmd: yarn add sharp --ignore-engines && yarn install --include-optional sharp && NODE_ENV=production yarn build && ln -sf $(pwd)/index.js /usr/local/bin/thelounge
notify:
- Restart thelounge
- name: Ensure user thelounge is present
ansible.builtin.user:
name: thelounge
createhome: no
comment: The Lounge (IRC client)
system: yes
state: present
- name: Ensure JS and JSON syntax checking packages are installed
yarn:
name: "{{ item }}"
global: yes
state: latest # FIXME: Remove when https://github.com/ansible/ansible/pull/39557 makes it in
with_items:
- esprima
- jsonlint
changed_when: no # FIXME: Remove when https://github.com/ansible/ansible/pull/39557 makes it in
- name: Configure templates
ansible.builtin.template:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: "{{ item.owner | default( 'thelounge' ) }}"
group: "{{ item.group | default( 'thelounge' ) }}"
mode: "{{ item.mode | default('0640') }}"
validate: "{{ item.validate | default([]) }}"
with_items:
- { src: "config.js.j2", dest: "/etc/thelounge/config.js", validate: 'esvalidate %s' }
- { src: "thelounge.service", dest: "/etc/systemd/system/thelounge.service", owner: root, group: root, notify: "Reload systemd" }
notify: "{{ item.notify | default('Restart thelounge') }}"