-
Notifications
You must be signed in to change notification settings - Fork 0
/
castpi2go.yml
245 lines (213 loc) · 6.77 KB
/
castpi2go.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
---
- hosts: all
become: true
pre_tasks:
- name: install updates
tags: always
ansible.builtin.apt:
update_cache: yes
upgrade: dist
- hosts : all
become: true
tasks:
- name: Include ansible user and ssh key from ssh_config.yaml
ansible.builtin.include_vars:
file: ssh_config.yaml
- name: add ssh key for ansible user
tags: always
ansible.builtin.authorized_key:
user: "{{ ansible_user }}"
key: "{{ ansible_user_ssh_key }}"
- hosts: all
become: true
vars:
arch_map:
armv6l: "armhf"
armv7l: "armhf"
aarch64: "arm64"
target_arch: "{{ arch_map[ansible_architecture] | default(ansible_architecture) }}"
snapclient_url: >
{{
(lookup('url', 'https://api.github.com/repos/badaix/snapcast/releases/latest', split_lines=false)
| from_json).assets
| selectattr('browser_download_url', 'search', 'snapclient.*' ~ target_arch ~ '.*' ~ ansible_distribution_release ~ '\.deb')
| map(attribute='browser_download_url')
| first
}}
snapclient_file: "/var/cache/apt/archives/{{ snapclient_url | regex_search('.*/(snapclient.*?\\.deb)', '\\1') | first }}"
tasks:
- name: disable dtparam
tags: hifiberry
ansible.builtin.replace:
path: /boot/firmware/config.txt
regexp: '^dtparam=audio=on$'
replace: '# dtparam=audio=on'
when: hifiberry_overlay is defined
notify: restart_pi
- name: disable vc4-kms-v3d
tags: hifiberry
ansible.builtin.lineinfile:
path: /boot/firmware/config.txt
regexp: '^dtoverlay=vc4-kms-v3d$'
line: dtoverlay=vc4-kms-v3d,noaudio
when: hifiberry_overlay is defined
notify: restart_pi
- name: add hifiberry device tree
tags: hifiberry
ansible.builtin.lineinfile:
path: /boot/firmware/config.txt
insertafter: '^#dtparam=audio=on$'
line: "{{ hifiberry_overlay }}"
when: hifiberry_overlay is defined
notify: restart_pi
- name: add alsa config for hifiberry
tags: hifiberry
ansible.builtin.copy:
dest: /etc/asound.conf
content: |
pcm.!default {
type hw card 0
}
ctl.!default {
type hw card 0
}
when: hifiberry_overlay is defined
notify: restart_pi
- name: download upmpdcli gpg key
tags: upmpdcli
ansible.builtin.get_url:
url: https://www.lesbonscomptes.com/pages/lesbonscomptes.gpg
dest: /usr/share/keyrings/lesbonscomptes.gpg
- name: download upmpdcli list file
tags: upmpdcli
ansible.builtin.get_url:
url: https://www.lesbonscomptes.com/upmpdcli/pages/upmpdcli-r{{ ansible_distribution_release }}.list
dest: /etc/apt/sources.list.d/upmpdcli-r{{ ansible_distribution_release }}.list
- name: install upmpdcli and mpd
tags: upmpdcli
ansible.builtin.apt:
name:
- upmpdcli
- mpd
state: latest
update_cache: yes
- name: start and enable mpd service
tags: upmpdcli
ansible.builtin.service:
name: mpd
state: started
enabled: yes
- name: set friendlyname for UPnP
tags: upmpdcli
ansible.builtin.replace:
path: /etc/upmpdcli.conf
regexp: '^#?friendlyname = .*$'
replace: friendlyname = {{ friendly_name }}
notify: restart_upmpdcli
- name: configure audio device for mpd to use
tags: upmpdcli
ansible.builtin.blockinfile:
path: /etc/mpd.conf
insertafter: '^# An example of an ALSA output:$'
block: |
audio_output {
type "alsa"
name "Hifiberry DAC"
device "hw:CARD=sndrpihifiberry,DEV=0" # optional
mixer_type "software" # optional
}
when: hifiberry_overlay is defined
notify: restart_mpd
- name: download snapcast client binary
tags: snapclient,snapcast
ansible.builtin.get_url:
url: "{{ snapclient_url }}"
dest: "{{ snapclient_file }}"
when:
- target_arch is defined
- hifiberry_overlay is defined
- name: install snapcast client
tags: snapclient,snapcast
ansible.builtin.apt:
deb: "{{ snapclient_file }}"
when:
- target_arch is defined
- hifiberry_overlay is defined
- name: set snapcast server IP in client config
tags: snapclient,snapcast
ansible.builtin.replace:
path: /etc/default/snapclient
regexp: '^SNAPCLIENT_OPTS="(?:-h \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})?'
replace: SNAPCLIENT_OPTS="-h {{ snapcast_server_ip }}
when: hifiberry_overlay is defined
notify: restart_snapclient
handlers:
- name: restart_pi
ansible.builtin.reboot:
- name: restart_upmpdcli
ansible.builtin.service:
name: upmpdcli
state: restarted
- name: restart_mpd
ansible.builtin.service:
name: mpd
state: restarted
- name: restart_snapclient
ansible.builtin.service:
name: snapclient
state: restarted
- hosts: snapservers
become: true
vars:
arch_map:
armv6l: "armhf"
armv7l: "armhf"
aarch64: "arm64"
target_arch: "{{ arch_map[ansible_architecture] | default(ansible_architecture) }}"
snapserver_url: >
{{
(lookup('url', 'https://api.github.com/repos/badaix/snapcast/releases/latest', split_lines=false)
| from_json).assets
| selectattr('browser_download_url', 'search', 'snapserver.*' ~ target_arch ~ '.*' ~ ansible_distribution_release ~ '\.deb')
| map(attribute='browser_download_url')
| first
}}
snapserver_file: "/var/cache/apt/archives/{{ snapserver_url | regex_search('.*/(snapserver.*?\\.deb)', '\\1') | first }}"
tasks:
- name: download snapcast server binary
tags: snapserver,snapcast
ansible.builtin.get_url:
url: "{{ snapserver_url }}"
dest: "{{ snapserver_file }}"
when: target_arch is defined
- name: install snapcast server
tags: snapserver,snapcast
ansible.builtin.apt:
deb: "{{ snapserver_file }}"
when: target_arch is defined
- name: add pipe to mpd.conf
tags: snapserver,snapcast
ansible.builtin.blockinfile:
path: /etc/mpd.conf
insertafter: '^# An example of an ALSA output:$'
block: |
audio_output {
type "fifo"
name "snapserver pipe"
path "/tmp/snapfifo"
format "48000:16:2"
mixer_type "software"
}
notify: restart_snapserver
- name: set friendlyname for snapserver source
tags: snapserver,snapcast
ansible.builtin.replace:
path: /etc/snapserver.conf
regexp: 'tmp\/snapfifo\?name=.*$'
replace: tmp/snapfifo?name={{ friendly_name }}
notify: restart_snapserver
handlers:
- name: restart_snapserver
ansible.builtin.service:
name: snapserver
state: restarted