summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorheqnx <root@heqnx.com>2025-07-06 14:57:39 +0300
committerheqnx <root@heqnx.com>2025-07-06 14:57:39 +0300
commita064cbda2086b79b6cc04111cb308a6b2d770aa6 (patch)
tree9b2c6aa08775aaae76420f9ad8d6baaf728bbe24
parent3559ca8a720086f080286e887a29b6fa68810fa9 (diff)
downloadansible-icecast2-a064cbda2086b79b6cc04111cb308a6b2d770aa6.tar.gz
ansible-icecast2-a064cbda2086b79b6cc04111cb308a6b2d770aa6.zip
replaced ices2 which only supports vorbis, with liquidsoap + creation of title metadata; reorganized templates
-rw-r--r--inventory.yaml.example1
-rw-r--r--tasks/icecast2_setup.yaml69
-rw-r--r--tasks/nginx_setup.yaml54
-rw-r--r--templates/etc/icecast2/icecast.xml.j2 (renamed from templates/icecast2/icecast.xml.j2)0
-rw-r--r--templates/etc/icecast2/ices-playlist.xml.j2 (renamed from templates/icecast2/ices-playlist.xml.j2)0
-rw-r--r--templates/etc/icecast2/mp3-to-ogg.sh.j2 (renamed from templates/icecast2/mp3-to-ogg.sh.j2)0
-rw-r--r--templates/etc/nginx/nginx.conf.j2 (renamed from templates/nginx/nginx.conf.j2)0
-rw-r--r--templates/etc/systemd/system/ices2.service (renamed from templates/systemd/system/ices2.service)0
-rw-r--r--templates/etc/systemd/system/liquidsoap-radio.service17
-rw-r--r--templates/srv/radio/create-playlist.sh.j222
-rw-r--r--templates/srv/radio/radio.liq.j223
-rw-r--r--templates/var/www/html/audio-controls.js5
-rw-r--r--vars/main.yaml3
13 files changed, 162 insertions, 32 deletions
diff --git a/inventory.yaml.example b/inventory.yaml.example
index 5872643..58a6eb8 100644
--- a/inventory.yaml.example
+++ b/inventory.yaml.example
@@ -9,6 +9,7 @@ all:
radio_genre: "my genre"
radio_description: "my description"
radio_url: "https://test123.com"
+ radio_music_dir: "/srv/radio"
children:
servers:
hosts:
diff --git a/tasks/icecast2_setup.yaml b/tasks/icecast2_setup.yaml
index ee8342d..506c537 100644
--- a/tasks/icecast2_setup.yaml
+++ b/tasks/icecast2_setup.yaml
@@ -6,33 +6,76 @@
group: icecast
mode: '0700'
+- name: ensure {{ radio_music_dir }}/tracks directory exists
+ file:
+ path: "{{ radio_music_dir }}/tracks"
+ state: directory
+ owner: icecast2
+ group: icecast
+ mode: '0700'
+
+- name: ensure {{ radio_music_dir }}/logs directory exists
+ file:
+ path: "{{ radio_music_dir }}/logs"
+ state: directory
+ owner: icecast2
+ group: icecast
+ mode: '0700'
+
- name: deploy icecast.xml from template
template:
- src: icecast2/icecast.xml.j2
+ src: etc/icecast2/icecast.xml.j2
dest: /etc/icecast2/icecast.xml
owner: root
group: root
mode: '0644'
-- name: deploy ices-playlist.xml.j2 from template
+- name: deploy radio.liq from template
template:
- src: icecast2/ices-playlist.xml.j2
- dest: /etc/icecast2/ices-playlist.xml
- owner: root
- group: root
- mode: '0644'
+ src: srv/radio/radio.liq.j2
+ dest: "{{ radio_music_dir }}/radio.liq"
+ owner: icecast2
+ group: icecast
+ mode: '0744'
-- name: deploy mp3-to-ogg.sh from template
+- name: deploy liquidsoap-radio.service from template
template:
- src: icecast2/mp3-to-ogg.sh.j2
- dest: /etc/icecast2/mp3-to-ogg.sh
- owner: root
- group: root
+ src: etc/systemd/system/liquidsoap-radio.service
+ dest: /etc/systemd/system/liquidsoap-radio.service
+ owner: icecast2
+ group: icecast
mode: '0744'
-- name: restart icecast2
+- name: reload systemd daemon
+ systemd:
+ daemon_reload: yes
+
+- name: restart and enable icecast2
systemd:
name: icecast2
state: restarted
enabled: true
when: ansible_service_mgr == 'systemd'
+
+- name: restart and enable liquidsoap-radio
+ systemd:
+ name: liquidsoap-radio
+ state: restarted
+ enabled: true
+ when: ansible_service_mgr == 'systemd'
+
+#- name: deploy ices-playlist.xml.j2 from template
+# template:
+# src: icecast2/ices-playlist.xml.j2
+# dest: /etc/icecast2/ices-playlist.xml
+# owner: root
+# group: root
+# mode: '0644'
+
+#- name: deploy mp3-to-ogg.sh from template
+# template:
+# src: icecast2/mp3-to-ogg.sh.j2
+# dest: /etc/icecast2/mp3-to-ogg.sh
+# owner: root
+# group: root
+# mode: '0744'
diff --git a/tasks/nginx_setup.yaml b/tasks/nginx_setup.yaml
index 604db6d..1b6688f 100644
--- a/tasks/nginx_setup.yaml
+++ b/tasks/nginx_setup.yaml
@@ -1,3 +1,9 @@
+- name: remove /var/www/html directory
+ file:
+ path: /var/www/html
+ state: absent
+ ignore_errors: true
+
- name: remove /etc/nginx/sites-enabled directory
file:
path: /etc/nginx/sites-enabled
@@ -8,7 +14,7 @@
path: /etc/nginx/sites-available
state: absent
-- name: ensure /var/www/html directory exists and is empty
+- name: ensure /var/www/html directory exists
file:
path: /var/www/html
state: directory
@@ -16,28 +22,46 @@
owner: www-data
group: www-data
-- name: clean /var/www/html contents
+- name: ensure /var/www/html/videos directory exists
file:
- path: /var/www/html
- state: absent
- become: true
- ignore_errors: true
+ path: /var/www/html/videos
+ state: directory
+ mode: '0755'
+ owner: www-data
+ group: www-data
-- name: recreate /var/www/html directory
- file:
- path: /var/www/html
+- name: copy web templates to /var/www/html
+ ansible.builtin.template:
+ src: "{{ item.src }}"
+ dest: "/var/www/html/{{ item.path }}"
+ owner: www-data
+ group: www-data
+ mode: '0644'
+ with_community.general.filetree: templates/var/www/html
+ when: item.state == "file"
+
+- name: set directory permissions to 755
+ ansible.builtin.file:
+ path: /var/www/html/
+ recurse: yes
state: directory
mode: '0755'
owner: www-data
group: www-data
-- name: deploy nginx.conf from template
- template:
- src: nginx/nginx.conf.j2
- dest: /etc/nginx/nginx.conf
- owner: root
- group: root
+- name: set file permissions to 644
+ ansible.builtin.find:
+ paths: /var/www/html/
+ file_type: file
+ register: found_files
+
+- name: apply 644 permission on files
+ ansible.builtin.file:
+ path: "{{ item.path }}"
mode: '0644'
+ owner: www-data
+ group: www-data
+ loop: "{{ found_files.files }}"
- name: restart nginx
systemd:
diff --git a/templates/icecast2/icecast.xml.j2 b/templates/etc/icecast2/icecast.xml.j2
index ef6e539..ef6e539 100644
--- a/templates/icecast2/icecast.xml.j2
+++ b/templates/etc/icecast2/icecast.xml.j2
diff --git a/templates/icecast2/ices-playlist.xml.j2 b/templates/etc/icecast2/ices-playlist.xml.j2
index 89fc4c9..89fc4c9 100644
--- a/templates/icecast2/ices-playlist.xml.j2
+++ b/templates/etc/icecast2/ices-playlist.xml.j2
diff --git a/templates/icecast2/mp3-to-ogg.sh.j2 b/templates/etc/icecast2/mp3-to-ogg.sh.j2
index f475d36..f475d36 100644
--- a/templates/icecast2/mp3-to-ogg.sh.j2
+++ b/templates/etc/icecast2/mp3-to-ogg.sh.j2
diff --git a/templates/nginx/nginx.conf.j2 b/templates/etc/nginx/nginx.conf.j2
index bb0930e..bb0930e 100644
--- a/templates/nginx/nginx.conf.j2
+++ b/templates/etc/nginx/nginx.conf.j2
diff --git a/templates/systemd/system/ices2.service b/templates/etc/systemd/system/ices2.service
index d3a4c2f..d3a4c2f 100644
--- a/templates/systemd/system/ices2.service
+++ b/templates/etc/systemd/system/ices2.service
diff --git a/templates/etc/systemd/system/liquidsoap-radio.service b/templates/etc/systemd/system/liquidsoap-radio.service
new file mode 100644
index 0000000..c10983d
--- /dev/null
+++ b/templates/etc/systemd/system/liquidsoap-radio.service
@@ -0,0 +1,17 @@
+[Unit]
+Description=Liquidsoap Radio Streaming Service
+After=network.target
+
+[Service]
+Type=simple
+User=icecast2
+#Group=icecast
+ExecStart=/usr/bin/liquidsoap /srv/radio/radio.liq
+Restart=on-failure
+RestartSec=5
+StandardOutput=syslog
+StandardError=syslog
+SyslogIdentifier=liquidsoap-radio
+
+[Install]
+WantedBy=multi-user.target
diff --git a/templates/srv/radio/create-playlist.sh.j2 b/templates/srv/radio/create-playlist.sh.j2
new file mode 100644
index 0000000..d596e8a
--- /dev/null
+++ b/templates/srv/radio/create-playlist.sh.j2
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+DIR="{{ radio_music_dir }}"
+
+> "${DIR}/playlist.txt"
+for i in "${DIR}"/tracks/*.mp3; do
+ title="$(basename "${i}" .mp3)"
+ printf "%s\n" "annotate:title=\"${title}\":${i}" >> "${DIR}/playlist.txt"
+done
+
+if id -u icecast2 >/dev/null 2>&1 && getent group icecast >/dev/null 2>&1; then
+ chown -R icecast2:icecast "${DIR}"
+ printf "%s\n" "[inf] chowned ${DIR} with icecast2:icecast"
+else
+ printf "%s\n" "[err] user or group icecast2:icecast does not exist, skipping chown"
+fi
+
+if systemctl is-active liquidsoap-radio.service; then
+ systemctl restart liquidsoap-radio.service
+else
+ printf "%s\n" "[err] liquidsoap-radio.service is not active, skipping restart"
+fi
diff --git a/templates/srv/radio/radio.liq.j2 b/templates/srv/radio/radio.liq.j2
new file mode 100644
index 0000000..0a070fe
--- /dev/null
+++ b/templates/srv/radio/radio.liq.j2
@@ -0,0 +1,23 @@
+#!/usr/bin/liquidsoap
+
+#settings.init.allow_root := true
+set("log.file.path", "{{ radio_music_dir }}/logs/radio.log")
+
+music = playlist("{{ radio_music_dir }}/playlist.txt")
+music = mksafe(music)
+
+def append_branding(m) =
+ title = m["title"]
+ [("title", "#{title}")]
+end
+
+music = map_metadata(append_branding, music)
+
+output.icecast(
+ %mp3(bitrate=128),
+ music,
+ host="localhost",
+ port=8000,
+ password="{{ random_password }}",
+ mount="/stream",
+)
diff --git a/templates/var/www/html/audio-controls.js b/templates/var/www/html/audio-controls.js
index 3b0a0c1..7f488f8 100644
--- a/templates/var/www/html/audio-controls.js
+++ b/templates/var/www/html/audio-controls.js
@@ -42,13 +42,12 @@ async function fetchCurrentTrack() {
const data = await response.json();
const source = data.icestats.source;
- const title = source.title || 'Unknown';
- const bitrate = source['ice-bitrate'] || 0;
+ const title = source.title || 'unknown';
const listeners = source.listeners || 0;
const listenerLabel = listeners === 1 ? 'listener' : 'listeners';
stopSpinner();
- infoEl.textContent = `${title} | ${bitrate} kbps | ${listeners} ${listenerLabel}`;
+ infoEl.textContent = `${title} | ${listeners} ${listenerLabel}`;
spinnerHasRun = true;
diff --git a/vars/main.yaml b/vars/main.yaml
index 56da4e3..784a675 100644
--- a/vars/main.yaml
+++ b/vars/main.yaml
@@ -6,6 +6,7 @@ apt_packages:
- iptables
- icecast2
- ices2
+ - liquidsoap
- nginx
- ufw
- unattended-upgrades
@@ -13,4 +14,4 @@ apt_packages:
- vim
fail2ban_jail_dir: /etc/fail2ban/jail.d
-random_password: "{{ ((ansible_date_time.epoch | string) ~ inventory_hostname) | hash('sha1sum') | truncate(32, end='') }}"
+random_password: "{{ ((ansible_date_time.epoch | string) ~ inventory_hostname) | hash('sha1') | truncate(32, end='') }}"