ansible-infra/playbooks/roles/bluetooth_audio_sink/tasks/main.yaml
2023-07-30 01:04:25 +02:00

182 lines
4.7 KiB
YAML

---
- name: Ensure acl is installed
become: true
ansible.builtin.apt:
name: acl
- name: Ensure machine-info file is deployed
become: true
ansible.builtin.template:
src: machine-info.j2
dest: /etc/machine-info
mode: "644"
owner: root
group: root
notify: Restart bluetooth service
- name: Ensure bluetooth config is deployed
become: true
ansible.builtin.template:
src: main.conf.j2
dest: /etc/bluetooth/main.conf
mode: "644"
owner: root
group: root
notify: Restart bluetooth service
- name: Ensure bluetooth service is enabled and started
become: true
ansible.builtin.systemd:
service: bluetooth.service
state: started
enabled: true
- name: Ensure audiosink user exists
become: true
ansible.builtin.user:
name: audiosink
groups:
- audio
- name: Ensure user services are started without needing to login
become: true
ansible.builtin.command:
cmd: loginctl enable-linger audiosink
changed_when: false
- name: Detect if on Raspberry Pi # noqa ignore-errors
ansible.builtin.include_role:
name: raspberry_pi_check
ignore_errors: true
- name: Ensure debian archive keyring is installed # noqa no-handler
become: true
when: raspberry_pi_check__cpuinfo.found
ansible.builtin.apt:
deb: https://ftp.debian.org/debian/pool/main/d/debian-archive-keyring/debian-archive-keyring_2021.1.1+deb11u1_all.deb
- name: Ensure debian backports repository is enabled
ansible.builtin.include_role:
name: add_apt_repository
vars:
add_apt_repository__https_repo: false
add_apt_repository__repo: "deb http://deb.debian.org/debian {{ ansible_facts.lsb.codename }}-backports main contrib non-free"
add_apt_repository__filename: "{{ ansible_facts.lsb.codename }}-backports.list"
- name: Ensure pipewire, wireplumber and libspa-0.2-bluetooth are installed
become: true
ansible.builtin.apt:
name:
- pipewire
- wireplumber
- libspa-0.2-bluetooth
default_release: "{{ ansible_facts.lsb.codename }}-backports"
- name: Ensure pipewire user service is enabled and started
become: true
become_user: audiosink
ansible.builtin.systemd:
name: pipewire.service
state: started
enabled: true
scope: user
- name: Ensure pipewire-pulse user service is enabled and started
become: true
become_user: audiosink
ansible.builtin.systemd:
name: pipewire-pulse.service
state: started
enabled: true
scope: user
- name: Ensure wireplumber user service is enabled
become: true
become_user: audiosink
ansible.builtin.systemd:
name: wireplumber.service
enabled: true
scope: user
- name: Ensure speaker-agent dependencies are installed
become: true
ansible.builtin.apt:
name:
- git
- python3-dbus
- name: Ensure speaker-agent repository is cloned
become: true
ansible.builtin.git:
repo: https://github.com/fdanis-oss/pw_wp_bluetooth_rpi_speaker.git
dest: /opt/speaker-agent
version: 9a939a23865ea020816017e06fd2290f301c35f9
- name: Ensure .config directory exists
become: true
become_user: audiosink
ansible.builtin.file:
path: /home/audiosink/.config
state: directory
mode: "700"
owner: audiosink
group: audiosink
- name: Ensure .config/systemd directory exists
become: true
become_user: audiosink
ansible.builtin.file:
path: /home/audiosink/.config/systemd
state: directory
mode: "755"
owner: audiosink
group: audiosink
- name: Ensure .config/systemd/user directory exists
become: true
become_user: audiosink
ansible.builtin.file:
path: /home/audiosink/.config/systemd/user
state: directory
mode: "755"
owner: audiosink
group: audiosink
- name: Ensure speaker-agent service file is deployed
become: true
become_user: audiosink
ansible.builtin.copy:
src: speaker-agent.service
dest: /home/audiosink/.config/systemd/user/speaker-agent.service
mode: "644"
owner: audiosink
group: audiosink
notify: Restart speaker-agent service
- name: Ensure speaker-agent service is enabled and started
become: true
become_user: audiosink
ansible.builtin.systemd:
name: speaker-agent.service
state: started
enabled: true
scope: user
# This part is janky, but I don't know how to make the bluetooth service, wireplumber and pipewire
# work with each other without being logged in.
- name: Ensure getty@tty1 override file is deployed
become: true
ansible.builtin.copy:
src: override.conf
dest: /etc/systemd/system/getty@tty1.service.d/override.conf
mode: "644"
owner: root
group: root
notify: Reboot host
- name: Ensure autologin for audiosink user is enabled
become: true
ansible.builtin.systemd:
service: getty@tty1.service
enabled: true
notify: Reboot host