Skip to content

Instantly share code, notes, and snippets.

@tobiasmcnulty
Created December 7, 2021 16:38
Show Gist options
  • Save tobiasmcnulty/666a302e1cd8a3021d88b221c90ae02b to your computer and use it in GitHub Desktop.
Save tobiasmcnulty/666a302e1cd8a3021d88b221c90ae02b to your computer and use it in GitHub Desktop.

Revisions

  1. tobiasmcnulty created this gist Dec 7, 2021.
    32 changes: 32 additions & 0 deletions hifiberry-tasks-main.yaml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    - name: Disable onboard audio
    replace:
    path: /boot/config.txt
    regexp: '^dtparam=audio=on$'
    replace: '#dtparam=audio=on'
    register: disable_onboard
    when: dac_type is defined

    - name: Enable DAC ({{ dac_type }})
    lineinfile:
    path: /boot/config.txt
    line: 'dtoverlay={{ dac_type }}'
    register: enable_dac
    when: dac_type is defined

    - name: Add asound.conf
    blockinfile:
    path: /etc/asound.conf
    block: |
    pcm.!default {
    type hw card 0
    }
    ctl.!default {
    type hw card 0
    }
    create: yes
    register: asound_conf
    when: dac_type is defined

    - name: Rebooting machine
    reboot:
    when: dac_type is defined and (disable_onboard.changed or enable_dac.changed or asound_conf.changed)
    8 changes: 8 additions & 0 deletions raspotify-defaults-main.yaml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    # see https://support.hifiberry.com/hc/en-us/articles/205377651-Configuring-Linux-4-x-or-higher
    dac_type: hifiberry-dac

    # raspotify bit rate
    raspotify_bitrate: 320

    raspotify_volume: 100
    raspotify_volume_args: --enable-volume-normalisation --linear-volume --initial-volume={{ raspotify_volume }}
    49 changes: 49 additions & 0 deletions raspotify-tasks-main.yaml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    - name: Make sure apt can use https sources
    apt:
    name: apt-transport-https
    state: present

    - name: Add signing key
    apt_key:
    url: https://dtcooper.github.io/raspotify/key.asc
    state: present

    - name: Add repo
    apt_repository:
    repo: deb https://dtcooper.github.io/raspotify raspotify main
    state: present

    - name: Install package
    apt:
    name: raspotify
    state: present

    - name: Set DEVICE_NAME for each device
    replace:
    path: /etc/default/raspotify
    regexp: '#?DEVICE_NAME=.+$'
    replace: 'DEVICE_NAME="{{ raspotify_device_name }}"'
    backup: yes
    register: raspotify_devname

    - name: Set BITRATE for each device
    replace:
    path: /etc/default/raspotify
    regexp: '#?BITRATE=.+$'
    replace: 'BITRATE={{ raspotify_bitrate }}'
    backup: yes
    register: raspotify_bitrate

    - name: Set VOLUME_ARGS for each device
    replace:
    path: /etc/default/raspotify
    regexp: '#?VOLUME_ARGS=.+$'
    replace: 'VOLUME_ARGS="{{ raspotify_volume_args }}"'
    backup: yes
    register: raspotify_bitrate

    - name: Restart raspotify
    systemd:
    name: raspotify
    state: restarted
    when: raspotify_bitrate.changed or raspotify_devname.changed