ansible/pis/03-install-pulseaudio-bluet...

103 lines
3.3 KiB
YAML
Raw Normal View History

# Run with
# ansible-playbook -i raspberrypi, 03-install-pulseaudio-bluetooth.yml
# where "raspberrypi" is the hostname of the pi
---
- hosts: all
gather_facts: false
remote_user: root
vars:
bluetooth_mac_address: B8:27:EB:AA:23:4E
vars_prompt:
- name: bluetooth_name
prompt: Name of Bluetooth device
private: no
tasks:
# --- Initial Checks ---
- 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