2020-01-08 20:18:23 +01:00
|
|
|
# Run with
|
|
|
|
# ansible-playbook -i raspberrypi, 03-install-pulseaudio-bluetooth.yml
|
|
|
|
# where "raspberrypi" is the hostname of the pi
|
|
|
|
---
|
|
|
|
|
2020-01-16 21:09:14 +01:00
|
|
|
- hosts: raspberrypi
|
2020-01-08 20:18:23 +01:00
|
|
|
gather_facts: false
|
|
|
|
remote_user: root
|
|
|
|
tasks:
|
|
|
|
# --- Initial Checks ---
|
2020-01-16 21:09:14 +01:00
|
|
|
- fail: msg="Make sure to set the MAC address of the BT device to variable 'bluetooth_mac_address_audio'"
|
|
|
|
when: bluetooth_mac_address_audio is undefined
|
2020-01-08 20:18:23 +01:00
|
|
|
- name: Detect Raspi Model
|
|
|
|
slurp:
|
|
|
|
src: /sys/firmware/devicetree/base/model
|
|
|
|
register: raspberry_model
|
|
|
|
- name: Decode Raspi Model
|
|
|
|
set_fact:
|
|
|
|
raspi_model: "{{ raspberry_model.content | b64decode }}"
|
|
|
|
- name: Check if its a Raspberry 3 (where I've tested this)
|
|
|
|
fail:
|
|
|
|
msg: I've only tested this on Raspberry 3 Model Pi, this is something else
|
|
|
|
when: 'not raspi_model.startswith("Raspberry Pi 3 Model B Plus")'
|
|
|
|
#- name: Determine MAC Address of first Bluetooth device
|
|
|
|
# command: 'hciconfig hci0'
|
|
|
|
# register: hci_output
|
|
|
|
#- name: Extract MAC address
|
|
|
|
# set_fact:
|
|
|
|
# hci0_addr: "{{ hci_output.stdout | regex_search('BD Address: ([^\\s]+)', '\\1') | first }}"
|
|
|
|
# --- The actual work ---
|
|
|
|
- name: Install pulseaudio packages
|
|
|
|
apt:
|
|
|
|
name:
|
|
|
|
- pulseaudio
|
|
|
|
- pulseaudio-utils
|
|
|
|
- pulseaudio-module-bluetooth
|
|
|
|
- alsa-utils
|
|
|
|
- bluez-tools
|
|
|
|
cache_valid_time: 7200
|
|
|
|
state: present
|
|
|
|
install_recommends: no
|
|
|
|
- name: Add root to pulse-access group
|
|
|
|
user:
|
|
|
|
name: root
|
|
|
|
groups:
|
|
|
|
- pulse-access
|
|
|
|
- pulse
|
|
|
|
- audio
|
|
|
|
append: yes
|
|
|
|
- name: Copy DBus permission file
|
|
|
|
copy: src=dbus-pulseaudio-bluetooth.conf dest=/etc/dbus-1/system.d/pulseaudio-bluetooth.conf
|
|
|
|
- name: Copy Pulseaudio system-mode config file
|
|
|
|
copy: src=pulseaudio.cfg dest=/etc/pulse/system.pa
|
|
|
|
- name: Copy bluetoothd main.conf
|
|
|
|
copy: src=bluetooth_main.conf dest=/etc/bluetooth/main.conf
|
|
|
|
- name: Copy bluetoothd audio.conf
|
|
|
|
copy: src=bluetooth_audio.conf dest=/etc/bluetooth/audio.conf
|
|
|
|
- name: Copy bt-agent service file
|
|
|
|
template: src=bt-agent.service dest=/lib/systemd/system/bt-agent.service
|
|
|
|
- name: Copy pulseaudio service file
|
|
|
|
copy: src=pulseaudio.service dest=/lib/systemd/system/
|
|
|
|
- name: Copy Python script for discoverable and name setting
|
|
|
|
copy:
|
|
|
|
src: start_bt_discoverable.py
|
|
|
|
dest: /bin/start_bt_discoverable
|
|
|
|
mode: u=rwx,g=rx
|
|
|
|
#- name: Stop Bluetooth
|
|
|
|
# service:
|
|
|
|
# name: bluetooth
|
|
|
|
# state: stopped
|
|
|
|
#- name: Set bluetooth device name
|
|
|
|
# ini_file:
|
|
|
|
# path: "/var/lib/bluetooth/{{hci0_addr}}/settings"
|
|
|
|
# section: General
|
|
|
|
# option: Alias
|
|
|
|
# value: "{{bluetooth_name}}"
|
|
|
|
#- name: Mark as discoverable
|
|
|
|
# ini_file:
|
|
|
|
# path: "/var/lib/bluetooth/{{hci0_addr}}/settings"
|
|
|
|
# section: General
|
|
|
|
# option: Discoverable
|
|
|
|
# value: true
|
|
|
|
- name: Enable and restart bluetooth
|
|
|
|
service:
|
|
|
|
name: bluetooth
|
|
|
|
enabled: yes
|
|
|
|
state: restarted
|
|
|
|
- name: Enable and restart pulseaudio
|
|
|
|
service:
|
|
|
|
name: pulseaudio
|
|
|
|
enabled: yes
|
|
|
|
state: restarted
|
|
|
|
- name: Enable and restart bt-agent
|
|
|
|
service:
|
|
|
|
name: bt-agent
|
|
|
|
enabled: yes
|
|
|
|
state: restarted
|
|
|
|
daemon_reload: yes
|