-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmirror.yml
198 lines (168 loc) · 6.21 KB
/
mirror.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
# Copyright 2015-2016 Harri Kapanen <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
- hosts: all
remote_user: pi
gather_facts: yes
sudo: yes
# Public variables
vars:
- hostname: mirror
- timezone: Europe/Helsinki
- nodejs_armv7_version: 10.x
- mm2_user: pi
- mm2_group: pi
- mm2_path: /home/{{ mm2_user }}/MagicMirror # some modules expect users home tree
- mm2_display_rotation: 3 # 0=normal, 1=90, 2=180, 3=270 degrees
vars_files:
- mirror-secrets.yml
roles:
- common
- wificlient
- node
handlers:
- include: ../../handlers/handlers.yml
tasks:
# MAGICMIRROR
- name: Make app dir
file: path={{ mm2_path }} state=directory mode=0755 owner={{ mm2_user }} group={{ mm2_group }}
- name: Pull sources from the repository
git: repo=https://github.com/MichMich/MagicMirror.git dest={{ mm2_path }} force=yes version=master
become_user: "{{ mm2_user }}"
register: mm2_git_pull
- name: Install npm packages
shell: chdir={{ mm2_path }} npm install
become_user: "{{ mm2_user }}"
when: mm2_git_pull.changed
# MODULES
# mmm-weathercharts
- name: create directory for mmm-weatherchart
file: path={{ mm2_path }}/modules/mmm-weatherchart state=directory mode=0755 owner={{ mm2_user }} group={{ mm2_group }}
- name: Download mmm-weatherchart
git: repo=https://github.com/paphko/mmm-weatherchart.git dest={{ mm2_path }}/modules/mmm-weatherchart force=yes version=master
become_user: "{{ mm2_user }}"
- name: create directory for MMM-Hsl-stops
file: path={{ mm2_path }}/modules/MMM-Hsl-stops state=directory mode=0755 owner={{ mm2_user }} group={{ mm2_group }}
- name: Download MMM-Hsl-stops # NOTE: jannekalliola is not the origin, PRs pending
git: repo=https://github.com/jannekalliola/MMM-Hsl-stops.git dest={{ mm2_path }}/modules/MMM-Hsl-stops force=yes version=master
become_user: "{{ mm2_user }}"
register: MMM_Hsl_stops_pull
- name: Install MMM-Hsl-stops
shell: chdir={{ mm2_path }}/modules/MMM-Hsl-stops npm install
become_user: "{{ mm2_user }}"
when: MMM_Hsl_stops_pull.changed
# MMM-PIR-Sensor
- name: create directory for MMM-PIR-Sensor
file: path={{ mm2_path }}/modules/MMM-PIR-Sensor state=directory mode=0755 owner={{ mm2_user }} group={{ mm2_group }}
- name: Download MMM-PIR-Sensor
git: repo=https://github.com/paviro/MMM-PIR-Sensor.git dest={{ mm2_path }}/modules/MMM-PIR-Sensor force=yes version=master
become_user: "{{ mm2_user }}"
register: MMM_PIR_Sensor_pull
- name: Install MMM-PIR-Sensor
shell: chdir={{ mm2_path }}/modules/MMM-PIR-Sensor npm install
become_user: "{{ mm2_user }}"
when: MMM_PIR_Sensor_pull.changed
- name: Add user to GPIO group
user: name={{ mm2_user }} groups=gpio append=yes
- name: Set some file perms
file:
path: "{{ item }}"
mode: "u+s"
with_items:
- "/opt/vc/bin/tvservice"
- "/bin/chvt"
notify: reboot
# MAGICMIRROR CONFIG FILE
- name: Copy custom magicmirror settings
template:
src: ./conf/mirror-conf.js.j2
dest: '{{ mm2_path }}/config/config.js'
mode: 0644
owner: "{{ mm2_user }}"
register: mm2_config_change
# SERVICE UNIT FILE
- name: Create MagicMirror unit file
copy:
dest: /etc/systemd/system/MagicMirror.service
content: |
[Unit]
Description=MagicMirror
[Service]
ExecStart=/usr/bin/npm start
WorkingDirectory={{ mm2_path }}
User={{ mm2_user }}
Group={{ mm2_user }}
StandardOutput=syslog
StandardError=syslog
Environment=NODE_ENV=production
Environment=DISPLAY=:0
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
register: mm2_unit_file
# DISPLAY THINGIES
- name: Set display rotation and remove boot gfx
lineinfile:
dest: /boot/config.txt
line: '{{ item }}'
with_items:
- 'dtoverlay=vc4-fkms-v3d'
- 'display_rotate= {{ mm2_display_rotation }}'
- 'avoid_warnings=1'
become: true
notify: reboot
# Hide mouse cursor
- name: Install unclutter
apt: pkg=unclutter state=latest
become: true
notify: reboot
- name: Configure unclutter
lineinfile:
dest: '/home/{{ mm2_user }}/.config/lxsession/LXDE-pi/autostart'
line: '@unclutter -display :0 -idle 3 -root -noevents'
create: yes
notify: reboot
# Disable screensaver
- name: Disable screensaver - configure lxsession
lineinfile:
dest: '/home/{{ mm2_user }}/.config/lxsession/LXDE-pi/autostart'
line: '{{ item }}'
create: yes
with_items:
- '@xset s noblank'
- '@xset s off'
- '@xset -dpms'
notify: reboot
- name: Disable screensaver - configure lightdm.conf
ini_file:
path: /etc/lightdm/lightdm.conf
section: SeatDefaults
option: 'xserver-command'
value: 'X -s 0 -dpms'
become: true
notify: reboot
# WIFI POWER SAVE OFF (Raspbian Stretch)
- name: wlan power saving disable script
copy:
dest: /etc/network/if-up.d/off-power-manager mode=755
content: |
#!/bin/sh
iw dev wlan0 set power_save off
become: true
notify: restart-networking
# ENABLE AND START THE SERVICE
- name: Enable MagicMirror and start it
service: name=MagicMirror daemon_reload=yes state=restarted enabled=yes
when: (mm2_unit_file is defined and mm2_unit_file.changed) or (mm2_config_change is defined)