This repository has been archived by the owner on Jun 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
main.yml
227 lines (195 loc) · 6.92 KB
/
main.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
---
- name: include distribution-specific vars
include_vars: "{{ ansible_distribution }}.yml"
- name: check that the H264 variables are in a consistent state
fail:
msg: >-
The H264 variables are in an inconsistent state. You must set the
ustreamer_h264_sink variable in order to set other H264 variables.
when: >-
ustreamer_h264_sink == None
and (ustreamer_h264_sink_mode != None
or ustreamer_h264_sink_rm != None
or ustreamer_h264_bitrate != None)
# If the `build uStreamer` step should be run with the `WITH_JANUS` option, we
# need to install the Janus Debian package beforehand, because it provides
# C-headers.
- name: determine whether to install Janus
set_fact:
ustreamer_install_janus: "{{ ustreamer_h264_sink != None }}"
- name: detect OS
set_fact:
ustreamer_is_os_raspbian: "{{ ansible_lsb.id is defined and ansible_lsb.id == 'Raspbian' }}"
ustreamer_is_os_debian: "{{ ansible_lsb.id is defined and ansible_lsb.id == 'Debian' }}"
- name: decide whether to support audio streaming
set_fact:
# Audio streaming requires Janus because MJPEG can't carry audio.
ustreamer_enable_audio_streaming: "{{ ustreamer_install_janus }}"
- name: install Janus
include_tasks: install_janus.yml
when: ustreamer_install_janus
- name: create ustreamer group
group:
name: "{{ ustreamer_group }}"
state: present
- name: create ustreamer user
user:
name: "{{ ustreamer_user }}"
group: "{{ ustreamer_group }}"
groups:
- video
system: yes
create_home: yes
- name: check for a boot config file
stat:
path: /boot/config.txt
register: boot_config_result
- name: save whether boot config file exists
set_fact:
boot_config_exists: "{{ boot_config_result.stat.exists }}"
- name: check whether this machine has a uStreamer settings file
stat:
path: "{{ ustreamer_settings_file }}"
register: ustreamer_settings_file_result
- name: read saved settings
import_tasks: check_saved_settings.yml
when: ustreamer_settings_file_result.stat.exists | bool
- name: configure TC358743 HDMI capture chip
import_tasks: provision_tc358743.yml
when: ustreamer_capture_device == 'tc358743'
- name: uninstall TC358743 settings if they're not in use
import_tasks: remove_tc358743.yml
when: ustreamer_capture_device != 'tc358743'
- name: collect universal required apt packages
set_fact:
ustreamer_packages:
- build-essential
- git
- libevent-dev
- libbsd-dev
- uuid-dev
- name: collect Raspberry Pi OS specific required apt packages
set_fact:
ustreamer_packages: "{{ ustreamer_packages }} + ['libjpeg9-dev']"
when: ustreamer_is_os_raspbian
- name: collect Raspberry Pi OS and Debian specific required apt packages for audio
set_fact:
ustreamer_packages: "{{ ustreamer_packages }} + ['libasound2-dev', 'libspeex-dev', 'libspeexdsp-dev', 'libopus-dev']"
when: ustreamer_install_janus and ustreamer_enable_audio_streaming
- name: collect Debian-specific required apt packages
set_fact:
ustreamer_packages: "{{ ustreamer_packages }} + ['libjpeg62-turbo-dev']"
when: ustreamer_is_os_debian
- name: collect Ubuntu-specific required apt packages
set_fact:
ustreamer_packages: "{{ ustreamer_packages }} + ['gcc', 'libjpeg8', 'libjpeg-dev', 'libjpeg-turbo8', 'libuuid1', 'libbsd0', 'make']"
when: ansible_distribution == 'Ubuntu'
- name: collect Janus WebRTC plugin specific required apt packages
set_fact:
ustreamer_packages: "{{ ustreamer_packages }} + ['libglib2.0-dev', 'libjansson-dev']"
when: ustreamer_install_janus
- name: install uStreamer pre-requisite packages
apt:
name: "{{ ustreamer_packages }}"
state: present
- name: install uStreamer Debian package
apt:
deb: "{{ ustreamer_debian_package_path }}"
when: ustreamer_debian_package_path != None
- name: create uStreamer folder
file:
path: "{{ ustreamer_dir }}"
state: directory
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
recurse: yes
tags:
# This fails the idempotency test because it must run on every provision
# to set the correct directory ownership that allows git to sync.
# Issue: https://github.com/tiny-pilot/tinypilot/issues/963
- molecule-idempotence-notest
when: ustreamer_debian_package_path == None
- name: get uStreamer repo
# Don't escalate privileges because only the directory owner can use git.
# Issue: https://github.com/tiny-pilot/tinypilot/issues/963
become: no
git:
repo: "{{ ustreamer_repo }}"
dest: "{{ ustreamer_dir }}"
version: "{{ ustreamer_repo_version }}"
tags:
# This fails the idempotency test because we're also skipping the
# idempotency test on the previous task that allows git to sync.
# Issue: https://github.com/tiny-pilot/tinypilot/issues/963
- molecule-idempotence-notest
when: ustreamer_debian_package_path == None
# We always need to clean and build uStreamer to ensure that the uStreamer
# service is in sync with its dependencies installed on the device.
# Issue: https://github.com/tiny-pilot/ansible-role-tinypilot/issues/174
- name: clean uStreamer repository
make:
chdir: "{{ ustreamer_dir }}"
target: clean
tags:
- molecule-idempotence-notest
when: ustreamer_debian_package_path == None
- name: build uStreamer
make:
chdir: "{{ ustreamer_dir }}"
params:
WITH_JANUS: "{{ ustreamer_install_janus | int }}"
notify:
- restart uStreamer
tags:
- molecule-idempotence-notest
when: ustreamer_debian_package_path == None
- name: fix uStreamer folder permissions
file:
path: "{{ ustreamer_dir }}"
state: directory
owner: "{{ ustreamer_user }}"
group: "{{ ustreamer_group }}"
recurse: yes
tags:
- molecule-idempotence-notest
- name: install uStreamer as a service
template:
src: ustreamer.systemd.j2
dest: /lib/systemd/system/ustreamer.service
owner: root
group: root
mode: '0644'
notify:
- reload systemd config
- restart uStreamer
- restart Janus
- name: enable systemd uStreamer service file
systemd:
name: ustreamer
enabled: yes
- name: save uStreamer settings file
template:
src: config.yml.j2
dest: "{{ ustreamer_settings_file }}"
owner: "{{ ustreamer_user }}"
group: "{{ ustreamer_group }}"
mode: '0644'
- name: create uStreamer Janus plugin config
template:
src: janus.plugin.ustreamer.jcfg.j2
dest: "{{ ustreamer_janus_configs_dir }}/janus.plugin.ustreamer.jcfg"
notify:
- restart Janus
when: ustreamer_install_janus
- name: install uStreamer Janus plugin
copy:
remote_src: yes
# The `build uStreamer` step created and placed the `.so` file in case it
# had been run with the `WITH_JANUS` option.
src: "{{ ustreamer_dir }}/janus/libjanus_ustreamer.so"
dest: "{{ ustreamer_janus_plugins_dir }}"
notify:
- restart Janus
when: ustreamer_debian_package_path == None and ustreamer_install_janus
- name: install uStreamer launcher
import_tasks: install_launcher.yml